diff options
author | Anton Ageev <antage@gmail.com> | 2019-03-31 03:20:21 +0300 |
---|---|---|
committer | Doug Tangren <d.tangren@gmail.com> | 2019-03-30 20:20:21 -0400 |
commit | ac8789e257f5e4a477192bbbd8ecc2676bb485e5 (patch) | |
tree | 792377890e4d0293be366233acf510e2610bd4fd /examples | |
parent | eb98b1916c0220e44e2d0f3c869c01a2dd037f60 (diff) |
Add a registry authentication. (#157)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/imagepull_auth.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/imagepull_auth.rs b/examples/imagepull_auth.rs new file mode 100644 index 0000000..1c559c7 --- /dev/null +++ b/examples/imagepull_auth.rs @@ -0,0 +1,28 @@ +// cargo run --example imagepull_auth busybox username password + +use shiplift::{Docker, PullOptions, RegistryAuth}; +use std::env; +use tokio::prelude::{Future, Stream}; + +fn main() { + env_logger::init(); + let docker = Docker::new(); + let img = env::args() + .nth(1) + .expect("You need to specify an image name"); + let username = env::args().nth(2).expect("You need to specify an username"); + let password = env::args().nth(3).expect("You need to specify a password"); + let auth = RegistryAuth::builder() + .username(username) + .password(password) + .build(); + let fut = docker + .images() + .pull(&PullOptions::builder().image(img).auth(auth).build()) + .for_each(|output| { + println!("{:?}", output); + Ok(()) + }) + .map_err(|e| eprintln!("Error: {}", e)); + tokio::run(fut); +} |