create a CachedCodeBuildListProjects function that accepts a codebuild client, account id, and region. Make sure it handles the region option and pagination
(CodeBuildClient CodeBuildClientInterface, accountID string, region string)
| 27 | |
| 28 | // create a CachedCodeBuildListProjects function that accepts a codebuild client, account id, and region. Make sure it handles the region option and pagination |
| 29 | func CachedCodeBuildListProjects(CodeBuildClient CodeBuildClientInterface, accountID string, region string) ([]string, error) { |
| 30 | var PaginationControl *string |
| 31 | var projects []string |
| 32 | cacheKey := fmt.Sprintf("%s-codebuild-ListProjects", accountID) |
| 33 | cached, found := internal.Cache.Get(cacheKey) |
| 34 | if found { |
| 35 | sharedLogger.WithFields(logrus.Fields{ |
| 36 | "api": "codebuild:ListProjects", |
| 37 | "account": accountID, |
| 38 | "region": region, |
| 39 | "cache": "hit", |
| 40 | }).Info("AWS API call") |
| 41 | return cached.([]string), nil |
| 42 | } |
| 43 | sharedLogger.WithFields(logrus.Fields{ |
| 44 | "api": "codebuild:ListProjects", |
| 45 | "account": accountID, |
| 46 | "region": region, |
| 47 | "cache": "miss", |
| 48 | }).Info("AWS API call") |
| 49 | |
| 50 | for { |
| 51 | ListProjects, err := CodeBuildClient.ListProjects( |
| 52 | context.TODO(), |
| 53 | &codebuild.ListProjectsInput{ |
| 54 | NextToken: PaginationControl, |
| 55 | }, |
| 56 | func(o *codebuild.Options) { |
| 57 | o.Region = region |
| 58 | }, |
| 59 | ) |
| 60 | if err != nil { |
| 61 | sharedLogger.Error(err.Error()) |
| 62 | break |
| 63 | } |
| 64 | |
| 65 | projects = append(projects, ListProjects.Projects...) |
| 66 | |
| 67 | // Pagination control. |
| 68 | if ListProjects.NextToken != nil { |
| 69 | PaginationControl = ListProjects.NextToken |
| 70 | } else { |
| 71 | PaginationControl = nil |
| 72 | break |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | internal.Cache.Set(cacheKey, projects, cache.DefaultExpiration) |
| 77 | return projects, nil |
| 78 | |
| 79 | } |
| 80 | |
| 81 | // create a CachedCodeBuildBatchGetProjects function that accepts a codebuild client, account id, region, and a single projectId. Make sure it handles the region option and pagination |
| 82 | func CachedCodeBuildBatchGetProjects(CodeBuildClient CodeBuildClientInterface, accountID string, region string, projectID string) (codeBuildTypes.Project, error) { |
no test coverage detected