@@ -22,11 +22,15 @@ package integration
2222import (
2323 "context"
2424 "fmt"
25+ "net/url"
2526
2627 tfjson "github.com/hashicorp/terraform-json"
2728
2829 "github.com/fluxcd/pkg/apis/meta"
30+ "github.com/fluxcd/pkg/auth"
2931 "github.com/fluxcd/pkg/auth/aws"
32+ authutils "github.com/fluxcd/pkg/auth/utils"
33+ "github.com/fluxcd/pkg/git"
3034 "github.com/fluxcd/test-infra/tftestenv"
3135)
3236
@@ -94,7 +98,7 @@ func registryLoginECR(ctx context.Context, output map[string]*tfjson.StateOutput
9498// logged in and is capable of pushing the test images.
9599func pushAppTestImagesECR (ctx context.Context , localImgs map [string ]string , output map [string ]* tfjson.StateOutput ) (map [string ]string , error ) {
96100 // Get the registry name and construct the image names accordingly.
97- repo := output ["ecr_test_app_repo_url " ].Value .(string )
101+ repo := output ["ecr_repository_url " ].Value .(string )
98102 remoteImage := repo + ":test"
99103 return tftestenv .PushTestAppImagesECR (ctx , localImgs , remoteImage )
100104}
@@ -138,17 +142,52 @@ func getClusterUsersAWS(output map[string]*tfjson.StateOutput) ([]string, error)
138142 return []string {clusterUser }, nil
139143}
140144
141- // When implemented, getGitTestConfigAws would return the git-specific test config for AWS
142145func getGitTestConfigAWS (outputs map [string ]* tfjson.StateOutput ) (* gitTestConfig , error ) {
143- return nil , fmt .Errorf ("NotImplemented for AWS" )
146+ repoURL := outputs ["git_repo_http_url" ].Value .(string )
147+ if repoURL == "" {
148+ return nil , fmt .Errorf ("no AWS CodeCommit repository URL in terraform output" )
149+ }
150+
151+ region := outputs ["region" ].Value .(string )
152+ if region == "" {
153+ return nil , fmt .Errorf ("no AWS region in terraform output" )
154+ }
155+
156+ parsedRepoURL , err := url .Parse (repoURL )
157+ if err != nil {
158+ return nil , fmt .Errorf ("failed to parse AWS CodeCommit repository URL: %w" , err )
159+ }
160+
161+ creds , err := authutils .GetGitCredentials (context .Background (), aws .ProviderName ,
162+ auth .WithSTSRegion (region ),
163+ auth .WithGitURL (* parsedRepoURL ),
164+ )
165+ if err != nil {
166+ return nil , fmt .Errorf ("failed to get AWS CodeCommit credentials: %w" , err )
167+ }
168+
169+ authOpts , err := getAuthOpts (repoURL , map [string ][]byte {
170+ "username" : []byte (creds .Username ),
171+ "password" : []byte (creds .Password ),
172+ })
173+ if err != nil {
174+ return nil , err
175+ }
176+
177+ return & gitTestConfig {
178+ defaultGitTransport : git .HTTPS ,
179+ defaultAuthOpts : authOpts ,
180+ applicationRepository : repoURL ,
181+ applicationRepositoryWithoutUser : repoURL ,
182+ }, nil
144183}
145184
146- // When implemented, grantPermissionsToGitRepositoryAWS would grant the required permissions to AWS CodeCommit repository
147185func grantPermissionsToGitRepositoryAWS (ctx context.Context , cfg * gitTestConfig , output map [string ]* tfjson.StateOutput ) error {
148- return fmt .Errorf ("NotImplemented for AWS" )
186+ // Noop, CodeCommit permissions are granted via Terraform
187+ return nil
149188}
150189
151- // When implemented, revokePermissionsToGitRepositoryAWS would revoke the permissions granted to AWS CodeCommit repository
152190func revokePermissionsToGitRepositoryAWS (ctx context.Context , cfg * gitTestConfig , outputs map [string ]* tfjson.StateOutput ) error {
153- return fmt .Errorf ("NotImplemented for AWS" )
191+ // Noop, CodeCommit permissions are granted via Terraform
192+ return nil
154193}
0 commit comments