@@ -33,9 +33,7 @@ import (
3333 "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/installer"
3434 "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/localpackages"
3535 "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/packageservice"
36- "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/ssms3"
3736 "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/trace"
38- "github.com/aws/amazon-ssm-agent/agent/s3util"
3937 "github.com/aws/amazon-ssm-agent/agent/task"
4038 "github.com/aws/aws-sdk-go/service/ssm"
4139)
@@ -456,72 +454,59 @@ func checkAlreadyInstalled(
456454
457455// selectService chooses the implementation of PackageService to use for a given execution of the plugin
458456func selectService (context context.T , tracer trace.Tracer , input * ConfigurePackagePluginInput , localrepo localpackages.Repository , appCfg * appconfig.SsmagentConfig , birdwatcherFacade facade.BirdwatcherFacade , isDocumentArchive * bool ) (packageservice.PackageService , error ) {
459- region , _ := context .Identity ().Region ()
460- serviceEndpoint := input .Repository
461457 response := & ssm.GetManifestOutput {}
462458 var err error
463- var s3Endpoint string
464- if s3Endpoint , err = s3util .GetS3Endpoint (context , region ); err != nil {
465- tracer .CurrentTrace ().AppendErrorf ("Failed to generate s3 endpoint - %v." , err .Error ())
466- return nil , err
467- }
468459
469- if (appCfg != nil && appCfg .Birdwatcher .ForceEnable ) || ! ssms3 .UseSSMS3Service (context , tracer , s3Endpoint , serviceEndpoint , region ) {
470- // This indicates that it would be the birdwatcher service.
471- // Before creating an object of type birdwatcher here, check if the name is of document arn. If it is, return with a Document type service
472- if regexp .MustCompile (documentArnPattern ).MatchString (input .Name ) {
460+ // Before creating an object of type birdwatcher here, check if the name is of document arn. If it is, return with a Document type service
461+ if regexp .MustCompile (documentArnPattern ).MatchString (input .Name ) {
462+ * isDocumentArchive = true
463+ // return a new object of type document
464+ return birdwatcherservice .NewDocumentArchive (context , birdwatcherFacade , localrepo ), nil
465+ }
466+ if input .Version != "" {
467+ // Birdwatcher version pattern and document version name pattern is different. If the pattern doesn't match Birdwatcher,
468+ // we assume document and continue, since birdwatcher will error out with ValidationException.
469+ // This could also happen if there is a typo in the birdwatcher version, but we assume Document and continue.
470+ if ! regexp .MustCompile (birdwatcherVersionPattern ).MatchString (input .Version ) {
473471 * isDocumentArchive = true
474472 // return a new object of type document
475473 return birdwatcherservice .NewDocumentArchive (context , birdwatcherFacade , localrepo ), nil
476474 }
477- if input .Version != "" {
478- // Birdwatcher version pattern and document version name pattern is different. If the pattern doesn't match Birdwatcher,
479- // we assume document and continue, since birdwatcher will error out with ValidationException.
480- // This could also happen if there is a typo in the birdwatcher version, but we assume Document and continue.
481- if ! regexp .MustCompile (birdwatcherVersionPattern ).MatchString (input .Version ) {
482- * isDocumentArchive = true
483- // return a new object of type document
484- return birdwatcherservice .NewDocumentArchive (context , birdwatcherFacade , localrepo ), nil
485- }
486- }
475+ }
487476
488- // If not, make a call to GetManifest and try to figure out if it is birdwatcher or document archive.
489- version := input .Version
490- if packageservice .IsLatest (version ) {
491- version = packageservice .Latest
492- }
493- response , err = birdwatcherFacade .GetManifest (
494- & ssm.GetManifestInput {
495- PackageName : & input .Name ,
496- PackageVersion : & version ,
497- },
498- )
499-
500- // If the error returned is the "ResourceNotFoundException", create a service with document archive
501- // if any other response, create a service of birdwatcher type
502- if err != nil {
503- if strings .Contains (err .Error (), resourceNotFoundException ) {
504- * isDocumentArchive = true
505- // return a new object of type document
506- return birdwatcherservice .NewDocumentArchive (context , birdwatcherFacade , localrepo ), nil
507- } else {
508- tracer .CurrentTrace ().AppendErrorf ("Error returned for GetManifest - %v." , err .Error ())
509- return nil , err
510- }
477+ // If not, make a call to GetManifest and try to figure out if it is birdwatcher or document archive.
478+ version := input .Version
479+ if packageservice .IsLatest (version ) {
480+ version = packageservice .Latest
481+ }
482+ response , err = birdwatcherFacade .GetManifest (
483+ & ssm.GetManifestInput {
484+ PackageName : & input .Name ,
485+ PackageVersion : & version ,
486+ },
487+ )
488+
489+ // If the error returned is the "ResourceNotFoundException", create a service with document archive
490+ // if any other response, create a service of birdwatcher type
491+ if err != nil {
492+ if strings .Contains (err .Error (), resourceNotFoundException ) {
493+ * isDocumentArchive = true
494+ // return a new object of type document
495+ return birdwatcherservice .NewDocumentArchive (context , birdwatcherFacade , localrepo ), nil
496+ } else {
497+ tracer .CurrentTrace ().AppendErrorf ("Error returned for GetManifest - %v." , err .Error ())
498+ return nil , err
511499 }
512-
513- * isDocumentArchive = false
514-
515- // return a new object of type birdwatcher
516- birdWatcherArchiveContext := make (map [string ]string )
517- birdWatcherArchiveContext ["packageName" ] = input .Name
518- birdWatcherArchiveContext ["packageVersion" ] = input .Version
519- birdWatcherArchiveContext ["manifest" ] = * response .Manifest
520- return birdwatcherservice .NewBirdwatcherArchive (context , birdwatcherFacade , localrepo , birdWatcherArchiveContext ), nil
521500 }
522501
523- tracer .CurrentTrace ().AppendInfof ("S3 repository is marked active" )
524- return ssms3 .New (context , s3Endpoint , serviceEndpoint , region ), nil
502+ * isDocumentArchive = false
503+
504+ // return a new object of type birdwatcher
505+ birdWatcherArchiveContext := make (map [string ]string )
506+ birdWatcherArchiveContext ["packageName" ] = input .Name
507+ birdWatcherArchiveContext ["packageVersion" ] = input .Version
508+ birdWatcherArchiveContext ["manifest" ] = * response .Manifest
509+ return birdwatcherservice .NewBirdwatcherArchive (context , birdwatcherFacade , localrepo , birdWatcherArchiveContext ), nil
525510}
526511
527512// Execute runs the plugin operation and returns output
0 commit comments