|
1 | 1 | // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -use clap::{App, AppSettings, Arg}; |
| 4 | +use clap::{Arg, ArgAction, Command}; |
5 | 5 | use std::fs::OpenOptions; |
6 | 6 |
|
7 | 7 | use aws_nitro_enclaves_image_format::generate_build_info; |
8 | 8 | use enclave_build::Docker2Eif; |
9 | 9 |
|
10 | 10 | fn main() { |
11 | | - let matches = App::new("Docker2Eif builder") |
| 11 | + let matches = Command::new("Docker2Eif builder") |
12 | 12 | .about("Generate consistent EIF image from a Docker image") |
13 | | - .setting(AppSettings::DisableVersion) |
14 | 13 | .arg( |
15 | | - Arg::with_name("docker_image") |
| 14 | + Arg::new("docker_image") |
16 | 15 | .short('t') |
17 | 16 | .long("tag") |
18 | 17 | .help("Docker image tag") |
19 | | - .takes_value(true) |
20 | 18 | .required(true), |
21 | 19 | ) |
22 | 20 | .arg( |
23 | | - Arg::with_name("init_path") |
| 21 | + Arg::new("init_path") |
24 | 22 | .short('i') |
25 | 23 | .long("init") |
26 | 24 | .help("Path to a binary representing the init process for the enclave") |
27 | | - .takes_value(true) |
28 | 25 | .required(true), |
29 | 26 | ) |
30 | 27 | .arg( |
31 | | - Arg::with_name("nsm_path") |
| 28 | + Arg::new("nsm_path") |
32 | 29 | .short('n') |
33 | 30 | .long("nsm") |
34 | 31 | .help("Path to the NitroSecureModule Kernel Driver") |
35 | | - .takes_value(true) |
36 | 32 | .required(true), |
37 | 33 | ) |
38 | 34 | .arg( |
39 | | - Arg::with_name("kernel_img_path") |
| 35 | + Arg::new("kernel_img_path") |
40 | 36 | .short('k') |
41 | 37 | .long("kernel") |
42 | 38 | .help("Path to a bzImage/Image file for x86_64/aarch64 linux kernel") |
43 | | - .takes_value(true) |
44 | 39 | .required(true), |
45 | 40 | ) |
46 | 41 | .arg( |
47 | | - Arg::with_name("kernel_cfg_path") |
| 42 | + Arg::new("kernel_cfg_path") |
48 | 43 | .long("kernel_config") |
49 | 44 | .help("Path to a bzImage.config/Image.config file for x86_64/aarch64 linux kernel config") |
50 | | - .takes_value(true) |
51 | 45 | .required(true), |
52 | 46 | ) |
53 | 47 | .arg( |
54 | | - Arg::with_name("cmdline") |
| 48 | + Arg::new("cmdline") |
55 | 49 | .short('c') |
56 | 50 | .long("cmdline") |
57 | 51 | .help("Cmdline for kernel") |
58 | | - .takes_value(true) |
59 | 52 | .required(true), |
60 | 53 | ) |
61 | 54 | .arg( |
62 | | - Arg::with_name("linuxkit_path") |
| 55 | + Arg::new("linuxkit_path") |
63 | 56 | .short('l') |
64 | 57 | .long("linuxkit") |
65 | 58 | .help("Linuxkit executable path") |
66 | | - .takes_value(true) |
67 | 59 | .required(true), |
68 | 60 | ) |
69 | 61 | .arg( |
70 | | - Arg::with_name("output") |
| 62 | + Arg::new("output") |
71 | 63 | .short('o') |
72 | 64 | .long("output") |
73 | 65 | .help("Output file for EIF image") |
74 | | - .takes_value(true) |
75 | 66 | .required(true), |
76 | 67 | ) |
77 | 68 | .arg( |
78 | | - Arg::with_name("signing-certificate") |
| 69 | + Arg::new("signing-certificate") |
79 | 70 | .long("signing-certificate") |
80 | | - .help("Specify the path to the signing certificate") |
81 | | - .takes_value(true), |
| 71 | + .help("Specify the path to the signing certificate"), |
82 | 72 | ) |
83 | 73 | .arg( |
84 | | - Arg::with_name("private-key") |
| 74 | + Arg::new("private-key") |
85 | 75 | .long("private-key") |
86 | | - .help("Specify the path to the private-key") |
87 | | - .takes_value(true), |
| 76 | + .help("Specify the path to the private-key"), |
88 | 77 | ) |
89 | 78 | .arg( |
90 | | - Arg::with_name("build") |
| 79 | + Arg::new("build") |
91 | 80 | .short('b') |
92 | 81 | .long("build") |
93 | 82 | .help("Build image from Dockerfile") |
94 | | - .takes_value(true) |
95 | | - .required(false), |
| 83 | + .conflicts_with("pull"), |
96 | 84 | ) |
97 | 85 | .arg( |
98 | | - Arg::with_name("pull") |
| 86 | + Arg::new("pull") |
99 | 87 | .short('p') |
100 | 88 | .long("pull") |
101 | 89 | .help("Pull the Docker image before generating EIF") |
102 | | - .required(false) |
| 90 | + .action(ArgAction::SetTrue) |
103 | 91 | .conflicts_with("build"), |
104 | 92 | ) |
105 | 93 | .arg( |
106 | | - Arg::with_name("image_name") |
| 94 | + Arg::new("image_name") |
107 | 95 | .long("name") |
108 | | - .help("Name for enclave image") |
109 | | - .takes_value(true), |
| 96 | + .help("Name for enclave image"), |
110 | 97 | ) |
111 | 98 | .arg( |
112 | | - Arg::with_name("image_version") |
| 99 | + Arg::new("image_version") |
113 | 100 | .long("version") |
114 | | - .help("Version of the enclave image") |
115 | | - .takes_value(true), |
| 101 | + .help("Version of the enclave image"), |
116 | 102 | ) |
117 | 103 | .arg( |
118 | | - Arg::with_name("metadata") |
| 104 | + Arg::new("metadata") |
119 | 105 | .long("metadata") |
120 | | - .help("Path to JSON containing the custom metadata provided by the user.") |
121 | | - .takes_value(true), |
| 106 | + .help("Path to JSON containing the custom metadata provided by the user"), |
122 | 107 | ) |
123 | 108 | .get_matches(); |
124 | 109 |
|
125 | | - let docker_image = matches.value_of("docker_image").unwrap(); |
126 | | - let init_path = matches.value_of("init_path").unwrap(); |
127 | | - let nsm_path = matches.value_of("nsm_path").unwrap(); |
128 | | - let kernel_img_path = matches.value_of("kernel_img_path").unwrap(); |
129 | | - let kernel_cfg_path = matches.value_of("kernel_cfg_path").unwrap(); |
130 | | - let cmdline = matches.value_of("cmdline").unwrap(); |
131 | | - let linuxkit_path = matches.value_of("linuxkit_path").unwrap(); |
132 | | - let output = matches.value_of("output").unwrap(); |
| 110 | + let docker_image = matches.get_one::<String>("docker_image").unwrap(); |
| 111 | + let init_path = matches.get_one::<String>("init_path").unwrap(); |
| 112 | + let nsm_path = matches.get_one::<String>("nsm_path").unwrap(); |
| 113 | + let kernel_img_path = matches.get_one::<String>("kernel_img_path").unwrap(); |
| 114 | + let kernel_cfg_path = matches.get_one::<String>("kernel_cfg_path").unwrap(); |
| 115 | + let cmdline = matches.get_one::<String>("cmdline").unwrap(); |
| 116 | + let linuxkit_path = matches.get_one::<String>("linuxkit_path").unwrap(); |
| 117 | + let output = matches.get_one::<String>("output").unwrap(); |
133 | 118 | let signing_certificate = matches |
134 | | - .value_of("signing_certificate") |
135 | | - .map(|val| val.to_string()); |
136 | | - let private_key = matches |
137 | | - .value_of("private_certificate") |
138 | | - .map(|val| val.to_string()); |
139 | | - let img_name = matches.value_of("image_name").map(|val| val.to_string()); |
140 | | - let img_version = matches.value_of("image_version").map(|val| val.to_string()); |
141 | | - let metadata = matches.value_of("metadata").map(|val| val.to_string()); |
| 119 | + .get_one::<String>("signing-certificate") |
| 120 | + .map(String::from); |
| 121 | + let private_key = matches.get_one::<String>("private-key").map(String::from); |
| 122 | + let img_name = matches.get_one::<String>("image_name").map(String::from); |
| 123 | + let img_version = matches.get_one::<String>("image_version").map(String::from); |
| 124 | + let metadata = matches.get_one::<String>("metadata").map(String::from); |
142 | 125 |
|
143 | 126 | let mut output = OpenOptions::new() |
144 | 127 | .read(true) |
@@ -166,10 +149,9 @@ fn main() { |
166 | 149 | ) |
167 | 150 | .unwrap(); |
168 | 151 |
|
169 | | - if matches.is_present("build") { |
170 | | - let dockerfile_dir = matches.value_of("build").unwrap(); |
| 152 | + if let Some(dockerfile_dir) = matches.get_one::<String>("build") { |
171 | 153 | img.build_docker_image(dockerfile_dir.to_string()).unwrap(); |
172 | | - } else if matches.is_present("pull") { |
| 154 | + } else if matches.get_flag("pull") { |
173 | 155 | img.pull_docker_image().unwrap(); |
174 | 156 | } |
175 | 157 |
|
|
0 commit comments