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:: { ContainerCreateOpts , PullOpts , RegistryAuth , RmContainerOpts } ;
4
4
use futures_util:: { StreamExt , TryStreamExt } ;
5
5
use podman_api:: opts:: ContainerCreateOpts as PodmanContainerCreateOpts ;
6
6
use podman_api:: opts:: PullOpts as PodmanPullOpts ;
7
+ use podman_api:: opts:: RegistryAuth as PodmanRegistryAuth ;
7
8
use std:: path:: PathBuf ;
8
9
use tar:: Archive ;
9
10
@@ -28,6 +29,10 @@ pub struct Config {
28
29
write_to_stdout : bool ,
29
30
// What level of logs to output
30
31
log_level : String ,
32
+ // Username for singing into a private registry
33
+ username : String ,
34
+ // Password for signing into a private registry
35
+ password : String ,
31
36
}
32
37
33
38
pub fn get_args ( ) -> Result < Config > {
@@ -65,6 +70,24 @@ pub fn get_args() -> Result<Config> {
65
70
. short ( "w" )
66
71
. long ( "write-to-stdout" ) ,
67
72
)
73
+ . arg (
74
+ Arg :: with_name ( "username" )
75
+ . value_name ( "USERNAME" )
76
+ . help ( "Username used for singing into a private registry." )
77
+ . short ( "u" )
78
+ . long ( "username" )
79
+ . default_value ( "" ) ,
80
+
81
+ )
82
+ . arg (
83
+ Arg :: with_name ( "password" )
84
+ . value_name ( "PASSWORD" )
85
+ . 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" )
86
+ . short ( "p" )
87
+ . long ( "password" )
88
+ . default_value ( "" ) ,
89
+
90
+ )
68
91
. arg (
69
92
Arg :: with_name ( "log-level" )
70
93
. value_name ( "LOG-LEVEL" )
@@ -80,6 +103,9 @@ pub fn get_args() -> Result<Config> {
80
103
let content_path = matches. value_of ( "content-path" ) . unwrap ( ) . to_string ( ) ;
81
104
let write_to_stdout = matches. is_present ( "write-to-stdout" ) ;
82
105
let log_level = matches. value_of ( "log-level" ) . unwrap ( ) . to_string ( ) ;
106
+ // TODO (tyslaton): Need to come up with a way for this to be extracted from the docker config to be more secure locally.
107
+ let username = matches. value_of ( "username" ) . unwrap ( ) . to_string ( ) ;
108
+ let password = matches. value_of ( "password" ) . unwrap ( ) . to_string ( ) ;
83
109
84
110
if write_to_stdout {
85
111
return Err ( anyhow ! (
@@ -93,6 +119,8 @@ pub fn get_args() -> Result<Config> {
93
119
content_path,
94
120
write_to_stdout,
95
121
log_level,
122
+ username,
123
+ password,
96
124
} )
97
125
}
98
126
@@ -132,7 +160,12 @@ pub async fn run(config: Config) -> Result<()> {
132
160
} ;
133
161
134
162
if let Some ( docker) = & rt. docker {
135
- let pull_opts = PullOpts :: builder ( ) . image ( repo) . tag ( tag) . build ( ) ;
163
+ let auth = RegistryAuth :: builder ( )
164
+ . username ( config. username )
165
+ . password ( config. password )
166
+ . build ( ) ;
167
+ let pull_opts = PullOpts :: builder ( ) . image ( repo) . tag ( tag) . auth ( auth) . build ( ) ;
168
+
136
169
let images = docker. images ( ) ;
137
170
let mut stream = images. pull ( & pull_opts) ;
138
171
@@ -147,8 +180,13 @@ pub async fn run(config: Config) -> Result<()> {
147
180
}
148
181
}
149
182
} else {
183
+ let auth = PodmanRegistryAuth :: builder ( )
184
+ . username ( config. username )
185
+ . password ( config. password )
186
+ . build ( ) ;
150
187
let pull_opts = PodmanPullOpts :: builder ( )
151
188
. reference ( config. image . clone ( ) . trim ( ) )
189
+ . auth ( auth)
152
190
. build ( ) ;
153
191
let images = rt. podman . as_ref ( ) . unwrap ( ) . images ( ) ;
154
192
let mut stream = images. pull ( & pull_opts) ;
0 commit comments