@@ -72,18 +72,28 @@ pub struct S3Config {
72
72
long,
73
73
env = "P_S3_ACCESS_KEY" ,
74
74
value_name = "access-key" ,
75
- required = true
75
+ required_unless_present = "profile_name"
76
76
) ]
77
- pub access_key_id : String ,
77
+ pub access_key_id : Option < String > ,
78
78
79
79
/// The secret key for AWS S3 or compatible object storage platform
80
80
#[ arg(
81
81
long,
82
82
env = "P_S3_SECRET_KEY" ,
83
83
value_name = "secret-key" ,
84
- required = true
84
+ required_unless_present = "profile_name"
85
85
) ]
86
- pub secret_key : String ,
86
+ pub secret_key : Option < String > ,
87
+
88
+ // Use aws profile name to fetch credentials
89
+ #[ arg(
90
+ long,
91
+ env = "P_AWS_PROFILE_NAME" ,
92
+ value_name = "profile" ,
93
+ conflicts_with_all = [ "access_key_id" , "secret_key" ] ,
94
+ required = false
95
+ ) ]
96
+ pub profile_name : Option < String > ,
87
97
88
98
/// The region for AWS S3 or compatible object storage platform
89
99
#[ arg( long, env = "P_S3_REGION" , value_name = "region" , required = true ) ]
@@ -119,6 +129,24 @@ pub struct S3Config {
119
129
default_value = "false"
120
130
) ]
121
131
pub skip_tls : bool ,
132
+
133
+ /// Set client to fallback to imdsv1
134
+ #[ arg(
135
+ long,
136
+ env = "P_AWS_IMDSV1_FALLBACK" ,
137
+ value_name = "bool" ,
138
+ default_value = "false"
139
+ ) ]
140
+ pub imdsv1_fallback : bool ,
141
+
142
+ /// Set instance metadata endpoint to use.
143
+ #[ arg(
144
+ long,
145
+ env = "P_AWS_METADATA_ENDPOINT" ,
146
+ value_name = "url" ,
147
+ required = false
148
+ ) ]
149
+ pub metadata_endpoint : Option < String > ,
122
150
}
123
151
124
152
impl S3Config {
@@ -135,15 +163,33 @@ impl S3Config {
135
163
. with_region ( & self . region )
136
164
. with_endpoint ( & self . endpoint_url )
137
165
. with_bucket_name ( & self . bucket_name )
138
- . with_access_key_id ( & self . access_key_id )
139
- . with_secret_access_key ( & self . secret_key )
140
166
. with_virtual_hosted_style_request ( !self . use_path_style )
141
167
. with_allow_http ( true ) ;
142
168
143
169
if self . set_checksum {
144
170
builder = builder. with_checksum_algorithm ( Checksum :: SHA256 )
145
171
}
146
172
173
+ if let Some ( ( access_key, secret_key) ) =
174
+ self . access_key_id . as_ref ( ) . zip ( self . secret_key . as_ref ( ) )
175
+ {
176
+ builder = builder
177
+ . with_access_key_id ( access_key)
178
+ . with_secret_access_key ( secret_key) ;
179
+ }
180
+
181
+ if let Some ( profile) = & self . profile_name {
182
+ builder = builder. with_profile ( profile) ;
183
+ }
184
+
185
+ if self . imdsv1_fallback {
186
+ builder = builder. with_imdsv1_fallback ( )
187
+ }
188
+
189
+ if let Some ( metadata_endpoint) = & self . metadata_endpoint {
190
+ builder = builder. with_metadata_endpoint ( metadata_endpoint)
191
+ }
192
+
147
193
builder. with_client_options ( client_options)
148
194
}
149
195
}
0 commit comments