From 39b16a0cb6c17e9594abdcb897890c5b1b7c0cae Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:59:31 +0200 Subject: [PATCH 1/7] Remove PAT secret from update-sdk workflow --- .github/workflows/update-sdk.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/update-sdk.yaml b/.github/workflows/update-sdk.yaml index 9152e826b..bb7eb45fb 100644 --- a/.github/workflows/update-sdk.yaml +++ b/.github/workflows/update-sdk.yaml @@ -31,7 +31,6 @@ jobs: repository: ${{ github.event.inputs.sdk-repo }} ref: ${{ github.event.inputs.sdk-version }} path: ./sdk - token: ${{ secrets.PAT }} - name: Setup Go uses: actions/setup-go@v5 @@ -59,7 +58,6 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: - token: ${{ secrets.PAT }} path: ./sdk branch: update-sdk-${{ github.run_number }} title: Update SDK ${{ github.event.inputs.sdk-version }} From 8adb875e9bbc3ee1888bf9272b5d5961665cc9cd Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:42:42 +0200 Subject: [PATCH 2/7] Fixes to removal of old files, add PAT usage in PR step --- .github/workflows/update-sdk.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-sdk.yaml b/.github/workflows/update-sdk.yaml index bb7eb45fb..966f2b44d 100644 --- a/.github/workflows/update-sdk.yaml +++ b/.github/workflows/update-sdk.yaml @@ -45,7 +45,8 @@ jobs: SDK_VERSION: ${{ github.event.inputs.sdk-version }} run: | # Remove all in case some files are removed - rm -rf .[!.]* * + shopt -s nullglob + rm -rf .[!.git]* * cp -r $PROJECT/pkg/.[^.]* $PROJECT/pkg/* $PROJECT/go.mod . # Replace module references @@ -58,6 +59,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: + token: ${{ secrets.PAT }} path: ./sdk branch: update-sdk-${{ github.run_number }} title: Update SDK ${{ github.event.inputs.sdk-version }} From b5f7ba0ded3ba09b77f75eed088fc2bda2e04815 Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:53:23 +0200 Subject: [PATCH 3/7] Remove dependency on `internal` from `pkg/names` --- pkg/names/service_account.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/names/service_account.go b/pkg/names/service_account.go index ec94e7819..8e66ce4be 100644 --- a/pkg/names/service_account.go +++ b/pkg/names/service_account.go @@ -6,7 +6,6 @@ import ( "fmt" "strings" - "github.com/canonical/jimm/v3/internal/errors" "github.com/juju/names/v5" ) @@ -81,7 +80,7 @@ func EnsureValidServiceAccountId(id string) (string, error) { } if !IsValidServiceAccountId(id) { - return "", errors.E(errors.CodeBadRequest, "invalid client ID") + return "", fmt.Errorf("invalid client id %q", id) } return id, nil } From f406c024f71f9dcdfdc27d5a60fda8bfa429001d Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:08:40 +0200 Subject: [PATCH 4/7] Add `v3` in module name in `update-sdk.yaml` --- .github/workflows/update-sdk.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-sdk.yaml b/.github/workflows/update-sdk.yaml index 966f2b44d..a5a126a06 100644 --- a/.github/workflows/update-sdk.yaml +++ b/.github/workflows/update-sdk.yaml @@ -50,7 +50,7 @@ jobs: cp -r $PROJECT/pkg/.[^.]* $PROJECT/pkg/* $PROJECT/go.mod . # Replace module references - find . -type f -exec sed -i "s|github.com/canonical/jimm/pkg|github.com/$SDK_REPO/$SDK_VERSION|" {} + + find . -type f -exec sed -i "s|github.com/canonical/jimm/v3/pkg|github.com/$SDK_REPO/$SDK_VERSION|" {} + sed -i "s|module .*|module github.com/$SDK_REPO/$SDK_VERSION|" go.mod # Needed to remove unused dependencies From 5ffa86ac09261824ca7d2857f6e0a60b2b114314 Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:24:40 +0000 Subject: [PATCH 5/7] Make error msg in pkg/names match the expected one --- pkg/names/service_account.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/names/service_account.go b/pkg/names/service_account.go index 8e66ce4be..f7cfe1a9a 100644 --- a/pkg/names/service_account.go +++ b/pkg/names/service_account.go @@ -5,6 +5,7 @@ package names import ( "fmt" "strings" + "errors" "github.com/juju/names/v5" ) @@ -80,7 +81,7 @@ func EnsureValidServiceAccountId(id string) (string, error) { } if !IsValidServiceAccountId(id) { - return "", fmt.Errorf("invalid client id %q", id) + return "", errors.New("invalid client ID") } return id, nil } From 6ab5626eed1e18c115fdf39c10471f83874b19aa Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:06:44 +0000 Subject: [PATCH 6/7] Create `ErrInvalidClientID` global var --- pkg/names/service_account.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/names/service_account.go b/pkg/names/service_account.go index f7cfe1a9a..009728f4a 100644 --- a/pkg/names/service_account.go +++ b/pkg/names/service_account.go @@ -3,9 +3,9 @@ package names import ( + "errors" "fmt" "strings" - "errors" "github.com/juju/names/v5" ) @@ -20,6 +20,11 @@ const ( ServiceAccountDomain = "serviceaccount" ) +var ( + // ErrInvalidClientID indicates an invalid client ID error. + ErrInvalidClientID = errors.New("invalid client ID") +) + // Service accounts are an OIDC/OAuth concept which allows for machine<->machine communication. // Service accounts are identified by their client ID. @@ -81,7 +86,7 @@ func EnsureValidServiceAccountId(id string) (string, error) { } if !IsValidServiceAccountId(id) { - return "", errors.New("invalid client ID") + return "", ErrInvalidClientID } return id, nil } From f9435f22db1738dfb3dea3f1c8792d3821be2534 Mon Sep 17 00:00:00 2001 From: pkulik0 <70904851+pkulik0@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:27:24 +0000 Subject: [PATCH 7/7] Change secret name to `JIMM_GO_SDK_PAT` --- .github/workflows/update-sdk.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-sdk.yaml b/.github/workflows/update-sdk.yaml index a5a126a06..9c55dd050 100644 --- a/.github/workflows/update-sdk.yaml +++ b/.github/workflows/update-sdk.yaml @@ -59,7 +59,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: - token: ${{ secrets.PAT }} + token: ${{ secrets.JIMM_GO_SDK_PAT }} path: ./sdk branch: update-sdk-${{ github.run_number }} title: Update SDK ${{ github.event.inputs.sdk-version }}