1
1
use anyhow:: { anyhow, Result } ;
2
2
use clap:: { App , Arg } ;
3
- use docker_api:: api:: { ContainerCreateOpts , PullOpts , RmContainerOpts } ;
3
+ use docker_api:: api:: {
4
+ ContainerCreateOpts ,
5
+ PullOpts ,
6
+ RmContainerOpts ,
7
+ RegistryAuth
8
+ } ;
4
9
use futures_util:: { StreamExt , TryStreamExt } ;
5
10
use podman_api:: opts:: ContainerCreateOpts as PodmanContainerCreateOpts ;
6
11
use podman_api:: opts:: PullOpts as PodmanPullOpts ;
12
+ use podman_api:: opts:: RegistryAuth as PodmanRegistryAuth ;
7
13
use std:: path:: PathBuf ;
8
14
use tar:: Archive ;
9
15
@@ -28,6 +34,10 @@ pub struct Config {
28
34
write_to_stdout : bool ,
29
35
// What level of logs to output
30
36
log_level : String ,
37
+ // Username for singing into a private registry
38
+ username : String ,
39
+ // Password for signing into a private registry
40
+ password : String ,
31
41
}
32
42
33
43
pub fn get_args ( ) -> Result < Config > {
@@ -65,6 +75,24 @@ pub fn get_args() -> Result<Config> {
65
75
. short ( "w" )
66
76
. long ( "write-to-stdout" ) ,
67
77
)
78
+ . arg (
79
+ Arg :: with_name ( "username" )
80
+ . value_name ( "USERNAME" )
81
+ . help ( "Username used for singing into a private registry." )
82
+ . short ( "u" )
83
+ . long ( "username" )
84
+ . default_value ( "" ) ,
85
+
86
+ )
87
+ . arg (
88
+ Arg :: with_name ( "password" )
89
+ . value_name ( "PASSWORD" )
90
+ . help ( "Password used for signing into a private registry. * WARNING *: Writing credentials to your terminal is risky. Be sure you are okay with them showing up in your history" )
91
+ . short ( "p" )
92
+ . long ( "password" )
93
+ . default_value ( "" ) ,
94
+
95
+ )
68
96
. arg (
69
97
Arg :: with_name ( "log-level" )
70
98
. value_name ( "LOG-LEVEL" )
@@ -80,6 +108,9 @@ pub fn get_args() -> Result<Config> {
80
108
let content_path = matches. value_of ( "content-path" ) . unwrap ( ) . to_string ( ) ;
81
109
let write_to_stdout = matches. is_present ( "write-to-stdout" ) ;
82
110
let log_level = matches. value_of ( "log-level" ) . unwrap ( ) . to_string ( ) ;
111
+ // TODO (tyslaton): Need to come up with a way for this to be extracted from the docker config to be more secure locally.
112
+ let username = matches. value_of ( "username" ) . unwrap ( ) . to_string ( ) ;
113
+ let password = matches. value_of ( "password" ) . unwrap ( ) . to_string ( ) ;
83
114
84
115
if write_to_stdout {
85
116
return Err ( anyhow ! (
@@ -93,6 +124,8 @@ pub fn get_args() -> Result<Config> {
93
124
content_path,
94
125
write_to_stdout,
95
126
log_level,
127
+ username,
128
+ password
96
129
} )
97
130
}
98
131
@@ -132,7 +165,12 @@ pub async fn run(config: Config) -> Result<()> {
132
165
} ;
133
166
134
167
if let Some ( docker) = & rt. docker {
135
- let pull_opts = PullOpts :: builder ( ) . image ( repo) . tag ( tag) . build ( ) ;
168
+ let auth = RegistryAuth :: builder ( )
169
+ . username ( config. username )
170
+ . password ( config. password )
171
+ . build ( ) ;
172
+ let pull_opts = PullOpts :: builder ( ) . image ( repo) . tag ( tag) . auth ( auth) . build ( ) ;
173
+
136
174
let images = docker. images ( ) ;
137
175
let mut stream = images. pull ( & pull_opts) ;
138
176
@@ -147,8 +185,13 @@ pub async fn run(config: Config) -> Result<()> {
147
185
}
148
186
}
149
187
} else {
188
+ let auth = PodmanRegistryAuth :: builder ( )
189
+ . username ( config. username )
190
+ . password ( config. password )
191
+ . build ( ) ;
150
192
let pull_opts = PodmanPullOpts :: builder ( )
151
193
. reference ( config. image . clone ( ) . trim ( ) )
194
+ . auth ( auth)
152
195
. build ( ) ;
153
196
let images = rt. podman . as_ref ( ) . unwrap ( ) . images ( ) ;
154
197
let mut stream = images. pull ( & pull_opts) ;
0 commit comments