From 5931a2f66295fe1c791e3090fd010e597dc97674 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 17 Dec 2024 17:04:09 +0000 Subject: [PATCH] depth 2 --- .github/workflows/autoupdate-prod.yaml | 9 +- admin/api_alerts.go | 13 +- admin/api_atlas_search.go | 11 +- auth/code/device_flow.go | 4 +- auth/code/device_flow_test.go | 218 ++++++++++----------- internal/core/client.go | 1 + mockadmin/teams_api.go | 11 +- tools/releaser/scripts/breaking-changes.sh | 50 +++-- 8 files changed, 168 insertions(+), 149 deletions(-) diff --git a/.github/workflows/autoupdate-prod.yaml b/.github/workflows/autoupdate-prod.yaml index 46177aa7e..2e7ebcc8c 100644 --- a/.github/workflows/autoupdate-prod.yaml +++ b/.github/workflows/autoupdate-prod.yaml @@ -10,6 +10,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: '2' + - name: Temp check Git SHA after checkout depth 3 + run: | + git rev-parse HEAD - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' @@ -23,8 +28,8 @@ jobs: git config --global user.name "github-actions[bot]" git add . git commit --allow-empty -m "fix: update OpenAPI spec" - - name: Set old commit for SDK API diff - run: echo "API_DIFF_OLD_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV + # - name: Set old commit for SDK API diff + # run: echo "API_DIFF_OLD_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV - name: Run generation working-directory: ./tools run: | diff --git a/admin/api_alerts.go b/admin/api_alerts.go index 3a93f7f32..d3e61a683 100644 --- a/admin/api_alerts.go +++ b/admin/api_alerts.go @@ -129,17 +129,18 @@ type AcknowledgeAlertApiRequest struct { } type AcknowledgeAlertApiParams struct { - GroupId string - AlertId string + GroupId string + // AlertId string + AlertIdTemp string AcknowledgeAlert *AcknowledgeAlert } func (a *AlertsApiService) AcknowledgeAlertWithParams(ctx context.Context, args *AcknowledgeAlertApiParams) AcknowledgeAlertApiRequest { return AcknowledgeAlertApiRequest{ - ApiService: a, - ctx: ctx, - groupId: args.GroupId, - alertId: args.AlertId, + ApiService: a, + ctx: ctx, + groupId: args.GroupId, + // alertId: args.AlertId, acknowledgeAlert: args.AcknowledgeAlert, } } diff --git a/admin/api_atlas_search.go b/admin/api_atlas_search.go index 36ff5aaae..8e06a7203 100644 --- a/admin/api_atlas_search.go +++ b/admin/api_atlas_search.go @@ -495,8 +495,8 @@ type AtlasSearchApi interface { type AtlasSearchApiService service type CreateAtlasSearchDeploymentApiRequest struct { - ctx context.Context - ApiService AtlasSearchApi + ctx context.Context + // ApiService AtlasSearchApi groupId string clusterName string apiSearchDeploymentRequest *ApiSearchDeploymentRequest @@ -510,7 +510,7 @@ type CreateAtlasSearchDeploymentApiParams struct { func (a *AtlasSearchApiService) CreateAtlasSearchDeploymentWithParams(ctx context.Context, args *CreateAtlasSearchDeploymentApiParams) CreateAtlasSearchDeploymentApiRequest { return CreateAtlasSearchDeploymentApiRequest{ - ApiService: a, + // ApiService: a, ctx: ctx, groupId: args.GroupId, clusterName: args.ClusterName, @@ -519,7 +519,8 @@ func (a *AtlasSearchApiService) CreateAtlasSearchDeploymentWithParams(ctx contex } func (r CreateAtlasSearchDeploymentApiRequest) Execute() (*ApiSearchDeploymentResponse, *http.Response, error) { - return r.ApiService.CreateAtlasSearchDeploymentExecute(r) + // return r.ApiService.CreateAtlasSearchDeploymentExecute(r) + return nil, nil, nil } /* @@ -534,7 +535,7 @@ Creates Search Nodes for the specified cluster. */ func (a *AtlasSearchApiService) CreateAtlasSearchDeployment(ctx context.Context, groupId string, clusterName string, apiSearchDeploymentRequest *ApiSearchDeploymentRequest) CreateAtlasSearchDeploymentApiRequest { return CreateAtlasSearchDeploymentApiRequest{ - ApiService: a, + // ApiService: a, ctx: ctx, groupId: groupId, clusterName: clusterName, diff --git a/auth/code/device_flow.go b/auth/code/device_flow.go index 50b485bec..81e339fb3 100644 --- a/auth/code/device_flow.go +++ b/auth/code/device_flow.go @@ -33,7 +33,7 @@ type DeviceCode struct { VerificationURI string `json:"verification_uri"` // VerificationURI is the URI where users will need to confirm the code DeviceCode string `json:"device_code"` // DeviceCode is the internal code to confirm the status of the flow ExpiresIn int `json:"expires_in"` // ExpiresIn when the code will expire - Interval int `json:"interval"` // Interval how often to verify the status of the code + // Interval int `json:"interval"` // Interval how often to verify the status of the code timeNow func() time.Time timeSleep func(time.Duration) @@ -95,7 +95,7 @@ func (c Config) PollToken(ctx context.Context, code *DeviceCode) (*Token, *core. timeSleep = time.Sleep } - checkInterval := time.Duration(code.Interval) * time.Second + checkInterval := time.Duration(60) * time.Second expiresAt := timeNow().Add(time.Duration(code.ExpiresIn) * time.Second) for { diff --git a/auth/code/device_flow_test.go b/auth/code/device_flow_test.go index 5c41195e6..c22dacdfd 100644 --- a/auth/code/device_flow_test.go +++ b/auth/code/device_flow_test.go @@ -22,77 +22,77 @@ import ( "github.com/go-test/deep" ) -func TestConfig_RequestCode(t *testing.T) { - config, mux, teardown := setup() - defer teardown() - - mux.HandleFunc("/api/private/unauth/account/device/authorize", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r) - fmt.Fprintf(w, `{ - "user_code": "QW3PYV7R", - "verification_uri": "%s/account/connect", - "device_code": "61eef18e310968047ff5e02a", - "expires_in": 600, - "interval": 10 - }`, baseURLPath) - }) - - results, _, err := config.RequestCode(ctx) - if err != nil { - t.Fatalf("RequestCode returned error: %v", err) - } - - expected := &DeviceCode{ - UserCode: "QW3PYV7R", - VerificationURI: baseURLPath + "/account/connect", - DeviceCode: "61eef18e310968047ff5e02a", - ExpiresIn: 600, - Interval: 10, - } - - if diff := deep.Equal(results, expected); diff != nil { - t.Error(diff) - } -} - -func TestConfig_GetToken(t *testing.T) { - config, mux, teardown := setup() - defer teardown() - - mux.HandleFunc("/api/private/unauth/account/device/token", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r) - fmt.Fprint(w, `{ - "access_token": "secret1", - "refresh_token": "secret2", - "scope": "openid", - "id_token": "idtoken", - "token_type": "Bearer", - "expires_in": 3600 - }`) - }) - code := &DeviceCode{ - DeviceCode: "61eef18e310968047ff5e02a", - ExpiresIn: 600, - Interval: 10, - } - results, _, err := config.GetToken(ctx, code.DeviceCode) - if err != nil { - t.Fatalf("GetToken returned error: %v", err) - } - - expected := &Token{ - AccessToken: "secret1", - RefreshToken: "secret2", - Scope: "openid", - IDToken: "idtoken", - TokenType: "Bearer", - ExpiresIn: 3600, - } - - if diff := deep.Equal(results, expected); diff != nil { - t.Error(diff) - } -} +// func TestConfig_RequestCode(t *testing.T) { +// config, mux, teardown := setup() +// defer teardown() + +// mux.HandleFunc("/api/private/unauth/account/device/authorize", func(w http.ResponseWriter, r *http.Request) { +// testMethod(t, r) +// fmt.Fprintf(w, `{ +// "user_code": "QW3PYV7R", +// "verification_uri": "%s/account/connect", +// "device_code": "61eef18e310968047ff5e02a", +// "expires_in": 600, +// "interval": 10 +// }`, baseURLPath) +// }) + +// results, _, err := config.RequestCode(ctx) +// if err != nil { +// t.Fatalf("RequestCode returned error: %v", err) +// } + +// expected := &DeviceCode{ +// UserCode: "QW3PYV7R", +// VerificationURI: baseURLPath + "/account/connect", +// DeviceCode: "61eef18e310968047ff5e02a", +// ExpiresIn: 600, +// Interval: 10, +// } + +// if diff := deep.Equal(results, expected); diff != nil { +// t.Error(diff) +// } +// } + +// func TestConfig_GetToken(t *testing.T) { +// config, mux, teardown := setup() +// defer teardown() + +// mux.HandleFunc("/api/private/unauth/account/device/token", func(w http.ResponseWriter, r *http.Request) { +// testMethod(t, r) +// fmt.Fprint(w, `{ +// "access_token": "secret1", +// "refresh_token": "secret2", +// "scope": "openid", +// "id_token": "idtoken", +// "token_type": "Bearer", +// "expires_in": 3600 +// }`) +// }) +// code := &DeviceCode{ +// DeviceCode: "61eef18e310968047ff5e02a", +// ExpiresIn: 600, +// Interval: 10, +// } +// results, _, err := config.GetToken(ctx, code.DeviceCode) +// if err != nil { +// t.Fatalf("GetToken returned error: %v", err) +// } + +// expected := &Token{ +// AccessToken: "secret1", +// RefreshToken: "secret2", +// Scope: "openid", +// IDToken: "idtoken", +// TokenType: "Bearer", +// ExpiresIn: 3600, +// } + +// if diff := deep.Equal(results, expected); diff != nil { +// t.Error(diff) +// } +// } func TestConfig_RefreshToken(t *testing.T) { config, mux, teardown := setup() @@ -129,44 +129,44 @@ func TestConfig_RefreshToken(t *testing.T) { } } -func TestConfig_PollToken(t *testing.T) { - config, mux, teardown := setup() - defer teardown() - - mux.HandleFunc("/api/private/unauth/account/device/token", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r) - fmt.Fprint(w, `{ - "access_token": "secret1", - "refresh_token": "secret2", - "scope": "openid", - "id_token": "idtoken", - "token_type": "Bearer", - "expires_in": 3600 - }`) - }) - code := &DeviceCode{ - DeviceCode: "61eef18e310968047ff5e02a", - ExpiresIn: 600, - Interval: 10, - } - results, _, err := config.PollToken(ctx, code) - if err != nil { - t.Fatalf("PollToken returned error: %v", err) - } - - expected := &Token{ - AccessToken: "secret1", - RefreshToken: "secret2", - Scope: "openid", - IDToken: "idtoken", - TokenType: "Bearer", - ExpiresIn: 3600, - } - - if diff := deep.Equal(results, expected); diff != nil { - t.Error(diff) - } -} +// func TestConfig_PollToken(t *testing.T) { +// config, mux, teardown := setup() +// defer teardown() + +// mux.HandleFunc("/api/private/unauth/account/device/token", func(w http.ResponseWriter, r *http.Request) { +// testMethod(t, r) +// fmt.Fprint(w, `{ +// "access_token": "secret1", +// "refresh_token": "secret2", +// "scope": "openid", +// "id_token": "idtoken", +// "token_type": "Bearer", +// "expires_in": 3600 +// }`) +// }) +// code := &DeviceCode{ +// DeviceCode: "61eef18e310968047ff5e02a", +// ExpiresIn: 600, +// Interval: 10, +// } +// results, _, err := config.PollToken(ctx, code) +// if err != nil { +// t.Fatalf("PollToken returned error: %v", err) +// } + +// expected := &Token{ +// AccessToken: "secret1", +// RefreshToken: "secret2", +// Scope: "openid", +// IDToken: "idtoken", +// TokenType: "Bearer", +// ExpiresIn: 3600, +// } + +// if diff := deep.Equal(results, expected); diff != nil { +// t.Error(diff) +// } +// } func TestConfig_RevokeToken(t *testing.T) { config, mux, teardown := setup() diff --git a/internal/core/client.go b/internal/core/client.go index f64b36191..3114612d0 100644 --- a/internal/core/client.go +++ b/internal/core/client.go @@ -53,6 +53,7 @@ type ErrorResponse struct { Reason string `json:"reason"` // Detail is more detailed description of the error. Detail string `json:"detail,omitempty"` + Temp string `json:"temp,omitempty"` } func (r *ErrorResponse) Error() string { diff --git a/mockadmin/teams_api.go b/mockadmin/teams_api.go index 782cde7c1..2b95cc4e7 100644 --- a/mockadmin/teams_api.go +++ b/mockadmin/teams_api.go @@ -4,12 +4,11 @@ package mockadmin import ( context "context" - - admin "go.mongodb.org/atlas-sdk/v20241113003/admin" - http "net/http" mock "github.com/stretchr/testify/mock" + + admin "go.mongodb.org/atlas-sdk/v20241113003/admin" ) // TeamsApi is an autogenerated mock type for the TeamsApi type @@ -52,9 +51,9 @@ type TeamsApi_AddAllTeamsToProject_Call struct { // - ctx context.Context // - groupId string // - teamRole *[]admin.TeamRole -func (_e *TeamsApi_Expecter) AddAllTeamsToProject(ctx any, groupId any, teamRole any) *TeamsApi_AddAllTeamsToProject_Call { - return &TeamsApi_AddAllTeamsToProject_Call{Call: _e.mock.On("AddAllTeamsToProject", ctx, groupId, teamRole)} -} +// func (_e *TeamsApi_Expecter) AddAllTeamsToProject(ctx any, groupId any, teamRole any) *TeamsApi_AddAllTeamsToProject_Call { +// return &TeamsApi_AddAllTeamsToProject_Call{Call: _e.mock.On("AddAllTeamsToProject", ctx, groupId, teamRole)} +// } func (_c *TeamsApi_AddAllTeamsToProject_Call) Run(run func(ctx context.Context, groupId string, teamRole *[]admin.TeamRole)) *TeamsApi_AddAllTeamsToProject_Call { _c.Call.Run(func(args mock.Arguments) { diff --git a/tools/releaser/scripts/breaking-changes.sh b/tools/releaser/scripts/breaking-changes.sh index 6e9c53e66..729c81934 100755 --- a/tools/releaser/scripts/breaking-changes.sh +++ b/tools/releaser/scripts/breaking-changes.sh @@ -1,37 +1,49 @@ #!/bin/bash -set -eu -GOPATH=$(go env GOPATH) +set -eux +# GOPATH=$(go env GOPATH) # Inputs: -# API_DIFF_OLD_COMMIT: commit before the API changes to compare with. If not provided, script will fail with "unbound variable" error -# API_DIFF_NEW_COMMIT: commit with the new API changes. If not provided, script will fail with "unbound variable" error # TARGET_BREAKING_CHANGES_FILE - file to save breaking changes TARGET_BREAKING_CHANGES_FILE=${TARGET_BREAKING_CHANGES_FILE:-""} script_path=$(dirname "$0") -echo "Installing go-apidiff" -go install github.com/joelanford/go-apidiff@latest > /dev/null +# shellcheck source=/dev/null +source "$script_path/extract-version.sh" +BASE_VERSION="github.com/mongodb/atlas-sdk-go/$SDK_MAJOR_VERSION@$SDK_VERSION" -echo "Running breaking changes check comparing commits ${API_DIFF_OLD_COMMIT} and ${API_DIFF_NEW_COMMIT}" +echo "Installing gorelease" +go install golang.org/x/exp/cmd/gorelease@latest >/dev/null pushd "$script_path/../../../" || exit ## workaround for --repo-path="../" not working echo "Changed directory to $(pwd)" set +e -BREAKING_CHANGES=$("$GOPATH/bin/go-apidiff" "${API_DIFF_OLD_COMMIT}" "${API_DIFF_NEW_COMMIT}" --compare-imports="false" --print-compatible="false") + +RAW_BREAKING_CHANGES=$(gorelease -base "$BASE_VERSION") +echo "gorelease -base $BASE_VERSION" +echo "raw breaking changes: $RAW_BREAKING_CHANGES" +echo "raw breaking changes end...." + +BREAKING_CHANGES=$(echo "$RAW_BREAKING_CHANGES" | awk ' + /^# go\./ {header="## " substr($0, 3); print header; next} + /## incompatible changes/ {print "### incompatible changes"; collecting=1; next} + collecting && /^#/ {collecting=0} + collecting {print} +') + set -e popd || exit if [ -z "$BREAKING_CHANGES" ]; then - echo "No major breaking changes detected" + echo "No major breaking changes detected" else - echo "Detected major breaking changes in the release" - if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then - echo "Breaking changes for the major release" - echo "$BREAKING_CHANGES" - else - echo "Creating the breaking changes file with following breaking changes:" - echo "$BREAKING_CHANGES" - echo -e "# Breaking Changes\n## SDK changes\n$BREAKING_CHANGES\n## API Changelog\n https://www.mongodb.com/docs/atlas/reference/api-resources-spec/changelog" \ - > "$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md" - fi + echo "Detected major breaking changes in the release" + if [ -z "$TARGET_BREAKING_CHANGES_FILE" ]; then + echo "Breaking changes for the major release" + echo "$BREAKING_CHANGES" + else + echo "Creating the breaking changes file with following breaking changes:" + echo "$BREAKING_CHANGES" + echo -e "# Breaking Changes\n## SDK changes\n$BREAKING_CHANGES\n## API Changelog\n https://www.mongodb.com/docs/atlas/reference/api-resources-spec/changelog" \ + >"$script_path/../breaking_changes/${TARGET_BREAKING_CHANGES_FILE}.md" + fi fi