File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ R""(
2+
3+ # Examples
4+
5+ * Get the credentials for a host:
6+
7+ ``` console
8+ # printf 'protocol=https\nhost=cache.example.org\n' | nix auth fill
9+ protocol=https
10+ host=cache.example.org
11+ username=alice
12+ password=foobar
13+ ```
14+
15+ # Description
16+
17+ Read a [ ` git-credential ` ] ( https://git-scm.com/docs/git-credential )
18+ request from standard input, resolve it against
19+ [ ` auth-sources ` ] ( @docroot@/command-ref/conf-file.md#conf-auth-sources ) ,
20+ and write the resulting fields to standard output.
21+
22+ With ` --require ` , prompt via ` $SSH_ASKPASS ` for any field no source
23+ provides.
24+
25+ )""
Original file line number Diff line number Diff line change 1+ #include " nix/util/auth.hh"
2+ #include " nix/cmd/command.hh"
3+
4+ namespace nix {
5+
6+ struct CmdAuthFill : Command
7+ {
8+ bool require = false ;
9+
10+ CmdAuthFill ()
11+ {
12+ addFlag ({
13+ .longName = " require" ,
14+ .description = " Prompt for credentials if no authentication source provides them." ,
15+ .handler = {&require, true },
16+ });
17+ }
18+
19+ std::string description () override
20+ {
21+ return " obtain a user name and password from the configured authentication sources" ;
22+ }
23+
24+ std::string doc () override
25+ {
26+ return
27+ #include " auth-fill.md"
28+ ;
29+ }
30+
31+ Category category () override
32+ {
33+ return catUtility;
34+ }
35+
36+ void run () override
37+ {
38+ logger->pause ();
39+ auto request = auth::AuthData::parseGitAuthData (drainFD (STDIN_FILENO ));
40+ if (auto authData = auth::getAuthenticator ()->fill (request, require))
41+ writeFull (STDOUT_FILENO , authData->toGitAuthData ());
42+ }
43+ };
44+
45+ struct CmdAuth : NixMultiCommand
46+ {
47+ CmdAuth ()
48+ : NixMultiCommand(" auth" , RegisterCommand::getCommandsFor({" auth" }))
49+ {
50+ }
51+
52+ std::string description () override
53+ {
54+ return " authentication-related commands" ;
55+ }
56+
57+ Category category () override
58+ {
59+ return catUtility;
60+ }
61+ };
62+
63+ static auto rCmdAuth = registerCommand<CmdAuth>(" auth" );
64+ static auto rCmdAuthFill = registerCommand2<CmdAuthFill>({" auth" , " fill" });
65+
66+ } // namespace nix
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ subdir('nix-meson-build-support/generate-header')
7777nix_sources = [ config_priv_h ] + files (
7878 ' add-to-store.cc' ,
7979 ' app.cc' ,
80+ ' auth.cc' ,
8081 ' build-trace.cc' ,
8182 ' build.cc' ,
8283 ' bundle.cc' ,
You can’t perform that action at this time.
0 commit comments