1313See the License for the specific language governing permissions and
1414limitations under the License.
1515"""
16- from typing import List
16+ from typing import List , Tuple
17+
1718from charon .config import CharonConfig , get_config
1819from charon .utils .logs import set_logging
1920from charon .utils .archive import detect_npm_archive , download_archive , NpmArchiveType
6263 help = """
6364 The target to do the uploading, which will decide which s3 bucket
6465 and what root path where all files will be uploaded to.
66+ Can accept more than one target.
6567 """ ,
6668 required = True ,
67- multiple = False ,
69+ multiple = True ,
6870)
6971@option (
7072 "--root_path" ,
@@ -112,7 +114,7 @@ def upload(
112114 repo : str ,
113115 product : str ,
114116 version : str ,
115- target : str ,
117+ target : List [ str ] ,
116118 root_path = "maven-repository" ,
117119 ignore_patterns : List [str ] = None ,
118120 work_dir : str = None ,
@@ -140,25 +142,20 @@ def upload(
140142 if not aws_profile :
141143 logger .warning ("No AWS profile specified!" )
142144
143- aws_bucket = conf .get_aws_bucket (target )
144- if not aws_bucket :
145- sys .exit (1 )
146-
147145 archive_path = __get_local_repo (repo )
148146 npm_archive_type = detect_npm_archive (archive_path )
149147 product_key = f"{ product } -{ version } "
150- prefix_ = conf .get_bucket_prefix (target )
151148 manifest_bucket_name = conf .get_manifest_bucket ()
149+ targets_ = __get_targets (target , conf )
152150 if npm_archive_type != NpmArchiveType .NOT_NPM :
153151 logger .info ("This is a npm archive" )
154152 tmp_dir , succeeded = handle_npm_uploading (
155153 archive_path ,
156154 product_key ,
157- target = ( aws_bucket , prefix_ ) ,
155+ targets = targets_ ,
158156 aws_profile = aws_profile ,
159157 dir_ = work_dir ,
160158 dry_run = dryrun ,
161- manifest_folder = target ,
162159 manifest_bucket_name = manifest_bucket_name
163160 )
164161 if not succeeded :
@@ -175,7 +172,7 @@ def upload(
175172 product_key ,
176173 ignore_patterns_list ,
177174 root = root_path ,
178- targets = [( target , aws_bucket , prefix_ )] ,
175+ targets = targets_ ,
179176 aws_profile = aws_profile ,
180177 dir_ = work_dir ,
181178 dry_run = dryrun ,
@@ -222,9 +219,10 @@ def upload(
222219 help = """
223220 The target to do the deletion, which will decide which s3 bucket
224221 and what root path where all files will be deleted from.
222+ Can accept more than one target.
225223 """ ,
226224 required = True ,
227- multiple = False ,
225+ multiple = True ,
228226)
229227@option (
230228 "--root_path" ,
@@ -271,7 +269,7 @@ def delete(
271269 repo : str ,
272270 product : str ,
273271 version : str ,
274- target : str ,
272+ target : List [ str ] ,
275273 root_path = "maven-repository" ,
276274 ignore_patterns : List [str ] = None ,
277275 work_dir : str = None ,
@@ -299,25 +297,20 @@ def delete(
299297 if not aws_profile :
300298 logger .warning ("No AWS profile specified!" )
301299
302- aws_bucket = conf .get_aws_bucket (target )
303- if not aws_bucket :
304- sys .exit (1 )
305-
306300 archive_path = __get_local_repo (repo )
307301 npm_archive_type = detect_npm_archive (archive_path )
308302 product_key = f"{ product } -{ version } "
309- prefix_ = conf .get_bucket_prefix (target )
310303 manifest_bucket_name = conf .get_manifest_bucket ()
304+ targets_ = __get_targets (target , conf )
311305 if npm_archive_type != NpmArchiveType .NOT_NPM :
312306 logger .info ("This is a npm archive" )
313307 tmp_dir , succeeded = handle_npm_del (
314308 archive_path ,
315309 product_key ,
316- target = ( aws_bucket , prefix_ ) ,
310+ targets = targets_ ,
317311 aws_profile = aws_profile ,
318312 dir_ = work_dir ,
319313 dry_run = dryrun ,
320- manifest_folder = target ,
321314 manifest_bucket_name = manifest_bucket_name
322315 )
323316 if not succeeded :
@@ -334,7 +327,7 @@ def delete(
334327 product_key ,
335328 ignore_patterns_list ,
336329 root = root_path ,
337- targets = [( target , aws_bucket , prefix_ )] ,
330+ targets = targets_ ,
338331 aws_profile = aws_profile ,
339332 dir_ = work_dir ,
340333 dry_run = dryrun ,
@@ -350,6 +343,23 @@ def delete(
350343 __safe_delete (tmp_dir )
351344
352345
346+ def __get_targets (target : List [str ], conf : CharonConfig ) -> List [Tuple [str , str , str ]]:
347+ targets_ = []
348+ for tgt in target :
349+ aws_bucket = conf .get_aws_bucket (tgt )
350+ if not aws_bucket :
351+ continue
352+ prefix = conf .get_bucket_prefix (tgt )
353+ targets_ .append ([tgt , aws_bucket , prefix ])
354+ if len (targets_ ) == 0 :
355+ logger .error (
356+ "All targets are not valid or configured, "
357+ "please check your charon configurations."
358+ )
359+ sys .exit (1 )
360+ return targets_
361+
362+
353363def __safe_delete (tmp_dir : str ):
354364 if tmp_dir and os .path .exists (tmp_dir ):
355365 logger .info ("Cleaning up work directory: %s" , tmp_dir )
0 commit comments