From 73c43da04901570df91ee2c4f55c480059475eee Mon Sep 17 00:00:00 2001 From: zan-mateusz Date: Fri, 3 Nov 2023 16:32:38 +0000 Subject: [PATCH 1/3] fix for being unable to rename github repo --- GitHub-Repositories-Repository/docs/README.md | 4 ++++ .../github-repositories-repository.json | 9 ++++++-- .../src/handlers.ts | 22 ++++++++++++++----- GitHub-Repositories-Repository/src/models.ts | 21 +++++++++++++----- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/GitHub-Repositories-Repository/docs/README.md b/GitHub-Repositories-Repository/docs/README.md index e7153bb..01dc63e 100644 --- a/GitHub-Repositories-Repository/docs/README.md +++ b/GitHub-Repositories-Repository/docs/README.md @@ -301,6 +301,10 @@ The `Fn::GetAtt` intrinsic function returns a value for a specified attribute of For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html). +#### Id + +The ID of the repository. + #### Owner ID of the repository owner. diff --git a/GitHub-Repositories-Repository/github-repositories-repository.json b/GitHub-Repositories-Repository/github-repositories-repository.json index f563715..2e5f5f1 100644 --- a/GitHub-Repositories-Repository/github-repositories-repository.json +++ b/GitHub-Repositories-Repository/github-repositories-repository.json @@ -100,6 +100,10 @@ ] }, "properties": { + "Id": { + "description": "The ID of the repository.", + "type": "number" + }, "Organization": { "description": "The organization name. The name is not case sensitive. If not specified, then the managed repository will be within the currently logged-in user account.", "type": "string" @@ -245,6 +249,7 @@ "Name" ], "readOnlyProperties": [ + "/properties/Id", "/properties/Owner", "/properties/HtmlUrl", "/properties/GitUrl", @@ -273,8 +278,8 @@ "/properties/SecurityAndAnalysis" ], "primaryIdentifier": [ - "/properties/Owner", - "/properties/Name" + "/properties/Id", + "/properties/Owner" ], "handlers": { "create": { diff --git a/GitHub-Repositories-Repository/src/handlers.ts b/GitHub-Repositories-Repository/src/handlers.ts index c6bed98..8887bb7 100644 --- a/GitHub-Repositories-Repository/src/handlers.ts +++ b/GitHub-Repositories-Repository/src/handlers.ts @@ -67,9 +67,13 @@ class Resource extends AbstractGitHubResource('GET /repos/{owner}/{repo}', { - owner: model.owner, - repo: model.name + // Note - in order to allow renaming the github repo, we need to use the id instead of owner and name for the path. + // See here for more information about this api (since it's undocumented): https://github.com/piotrmurach/github/issues/282 + // ts ignore below necessary as this path is not part of octokit endpoints + + // @ts-ignore + const response = await octokit.request('GET /repositories/{id}', { + id: model.id }); return response.data; @@ -168,9 +172,14 @@ class Resource extends AbstractGitHubResource( - 'PATCH /repos/{owner}/{repo}', - payload); + const pathWithId = `PATCH /repositories/${model.id}`; + + // Note - in order to allow renaming the github repo, we need to use the id instead of owner and name for the path. + // See here for more information about this api (since it's undocumented): https://github.com/piotrmurach/github/issues/282 + // ts ignore below necessary as this path is not part of octokit endpoints + + // @ts-ignore + const response = await octokit.request(pathWithId, payload); return response.data; } @@ -199,6 +208,7 @@ class Resource extends AbstractGitHubResource + transformValue(Number, 'id', value, obj, []), + { + toClassOnly: true, + } + ) + id?: Optional; @Expose({ name: 'Organization' }) @Transform( (value: any, obj: any) => @@ -290,12 +299,12 @@ export class ResourceModel extends BaseModel { @Exclude() public getPrimaryIdentifier(): Dict { const identifier: Dict = {}; - if (this.owner != null) { - identifier[this.IDENTIFIER_KEY_OWNER] = this.owner; + if (this.id != null) { + identifier[this.IDENTIFIER_KEY_ID] = this.id; } - if (this.name != null) { - identifier[this.IDENTIFIER_KEY_NAME] = this.name; + if (this.owner != null) { + identifier[this.IDENTIFIER_KEY_OWNER] = this.owner; } // only return the identifier if it can be used, i.e. if all components are present From 56f659ed79de9d593b2d0d509299d36b0a3f4e6c Mon Sep 17 00:00:00 2001 From: zan-mateusz Date: Fri, 3 Nov 2023 16:40:47 +0000 Subject: [PATCH 2/3] remove name from createOnlyProperties --- .../github-repositories-repository.json | 1 - 1 file changed, 1 deletion(-) diff --git a/GitHub-Repositories-Repository/github-repositories-repository.json b/GitHub-Repositories-Repository/github-repositories-repository.json index 2e5f5f1..fc01964 100644 --- a/GitHub-Repositories-Repository/github-repositories-repository.json +++ b/GitHub-Repositories-Repository/github-repositories-repository.json @@ -262,7 +262,6 @@ ], "createOnlyProperties": [ "/properties/Organization", - "/properties/Name", "/properties/TeamId", "/properties/AutoInit", "/properties/GitIgnoreTemplate", From b0ded7d0874a261562d644495c28e179a92186f7 Mon Sep 17 00:00:00 2001 From: Duncan Grant Date: Tue, 14 Nov 2023 11:14:48 +0000 Subject: [PATCH 3/3] Update delete handler to use repo id --- GitHub-Repositories-Repository/docs/README.md | 2 +- .../github-repositories-repository.json | 20 ++++++++++++++----- .../package-lock.json | 1 - .../resource-role.yaml | 4 ++-- .../src/handlers.ts | 5 ++--- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/GitHub-Repositories-Repository/docs/README.md b/GitHub-Repositories-Repository/docs/README.md index 01dc63e..dcf4add 100644 --- a/GitHub-Repositories-Repository/docs/README.md +++ b/GitHub-Repositories-Repository/docs/README.md @@ -87,7 +87,7 @@ _Required_: Yes _Type_: String -_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement) +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) #### Description diff --git a/GitHub-Repositories-Repository/github-repositories-repository.json b/GitHub-Repositories-Repository/github-repositories-repository.json index fc01964..f1c7950 100644 --- a/GitHub-Repositories-Repository/github-repositories-repository.json +++ b/GitHub-Repositories-Repository/github-repositories-repository.json @@ -282,19 +282,29 @@ ], "handlers": { "create": { - "permissions": [] + "permissions": [ + "appsync:CreateApiKey" + ] }, "read": { - "permissions": [] + "permissions": [ + "appsync:CreateApiKey" + ] }, "update": { - "permissions": [] + "permissions": [ + "appsync:CreateApiKey" + ] }, "delete": { - "permissions": [] + "permissions": [ + "appsync:CreateApiKey" + ] }, "list": { - "permissions": [] + "permissions": [ + "appsync:CreateApiKey" + ] } } } diff --git a/GitHub-Repositories-Repository/package-lock.json b/GitHub-Repositories-Repository/package-lock.json index d157329..518ba4a 100644 --- a/GitHub-Repositories-Repository/package-lock.json +++ b/GitHub-Repositories-Repository/package-lock.json @@ -11,7 +11,6 @@ "@amazon-web-services-cloudformation/cloudformation-cli-typescript-lib": "^1.0.3", "@octokit/core": "^4.1.0", "@octokit/rest": "^19.0.5", - "aws-sdk": "^2.1354.0", "class-transformer": "0.3.1" }, "devDependencies": { diff --git a/GitHub-Repositories-Repository/resource-role.yaml b/GitHub-Repositories-Repository/resource-role.yaml index 18b33ff..b82cbfb 100644 --- a/GitHub-Repositories-Repository/resource-role.yaml +++ b/GitHub-Repositories-Repository/resource-role.yaml @@ -28,9 +28,9 @@ Resources: PolicyDocument: Version: '2012-10-17' Statement: - - Effect: Deny + - Effect: Allow Action: - - "*" + - "appsync:CreateApiKey" Resource: "*" Outputs: ExecutionRoleArn: diff --git a/GitHub-Repositories-Repository/src/handlers.ts b/GitHub-Repositories-Repository/src/handlers.ts index 8887bb7..0f60ca6 100644 --- a/GitHub-Repositories-Repository/src/handlers.ts +++ b/GitHub-Repositories-Repository/src/handlers.ts @@ -190,9 +190,8 @@ class Resource extends AbstractGitHubResource