-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add support for update credentials #709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ env: | |
ENV0_API_ENDPOINT: ${{ secrets.ENV0_API_ENDPOINT }} | ||
ENV0_API_KEY: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_KEY }} # API Key for organization 'TF-provider-integration-tests' @ dev | ||
ENV0_API_SECRET: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_SECRET }} | ||
GO_VERSION: 1.19 | ||
GO_VERSION: "1.20" | ||
TERRAFORM_VERSION: 1.1.7 | ||
|
||
jobs: | ||
|
@@ -18,14 +18,14 @@ jobs: | |
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
- name: Generate mocks | ||
run: | | ||
go install github.com/golang/mock/mockgen@v1.6.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been deprecated. Ownership moved to Uber. |
||
go install go.uber.org/mock/mockgen@v0.2.0 | ||
go generate client/api_client.go | ||
- name: Go fmt | ||
run: | | ||
|
@@ -45,12 +45,12 @@ jobs: | |
integration-tests: | ||
name: Integration Tests | ||
runs-on: ubuntu-20.04 | ||
container: golang:1.19-alpine3.17 | ||
container: golang:1.20-alpine3.18 | ||
timeout-minutes: 20 | ||
steps: | ||
- name: Install Terraform | ||
run: apk add terraform | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
- name: Run Harness tests | ||
run: go run tests/harness.go |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,34 +6,30 @@ on: | |
- main | ||
|
||
env: | ||
GO_VERSION: 1.19 | ||
GO_VERSION: "1.20" | ||
|
||
jobs: | ||
generate-docs: | ||
name: Generate Docs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.ENV0_BOT_PAT }} | ||
|
||
- name: Unshallow | ||
run: git fetch --prune --unshallow | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- | ||
name: Update generated docs | ||
go-version: "${{ env.GO_VERSION }}" | ||
- name: Update generated docs | ||
run: ./generate-docs.sh | ||
- | ||
name: Commit changes | ||
- name: Commit changes | ||
uses: EndBug/add-and-commit@v9 | ||
with: | ||
author_name: update generated docs action | ||
author_email: [email protected] | ||
message: 'Update docs' | ||
add: 'docs/*' | ||
message: "Update docs" | ||
add: "docs/*" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,10 +143,27 @@ func (client *ApiClient) CredentialsCreate(request CredentialCreatePayload) (Cre | |
request.SetOrganizationId(organizationId) | ||
|
||
var result Credentials | ||
err = client.http.Post("/credentials", request, &result) | ||
if err := client.http.Post("/credentials", request, &result); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. github diff mixup... this did not change other than this line. |
||
return Credentials{}, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (client *ApiClient) CredentialsUpdate(id string, request CredentialCreatePayload) (Credentials, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is all new |
||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return Credentials{}, err | ||
} | ||
|
||
request.SetOrganizationId(organizationId) | ||
|
||
var result Credentials | ||
|
||
if err := client.http.Patch("/credentials/"+id, request, &result); err != nil { | ||
return Credentials{}, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ package client_test | |
|
||
import ( | ||
. "github.com/env0/terraform-provider-env0/client" | ||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("CloudCredentials", func() { | ||
|
@@ -115,6 +115,46 @@ var _ = Describe("CloudCredentials", func() { | |
}) | ||
}) | ||
|
||
Describe("AwsCredentialsUpdate", func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unit test for the new update API. |
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
payloadValue := AwsCredentialsValuePayload{ | ||
RoleArn: "role", | ||
} | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Patch("/credentials/"+mockCredentials.Id, &AwsCredentialsCreatePayload{ | ||
Name: credentialsName, | ||
OrganizationId: organizationId, | ||
Type: "AWS_ASSUMED_ROLE_FOR_DEPLOYMENT", | ||
Value: payloadValue, | ||
}, | ||
gomock.Any()). | ||
Do(func(path string, request interface{}, response *Credentials) { | ||
*response = mockCredentials | ||
}) | ||
|
||
credentials, _ = apiClient.CredentialsUpdate(credentials.Id, &AwsCredentialsCreatePayload{ | ||
Name: credentialsName, | ||
Value: payloadValue, | ||
Type: "AWS_ASSUMED_ROLE_FOR_DEPLOYMENT", | ||
}) | ||
}) | ||
|
||
It("Should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("Should send PATCH request with params", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should return key", func() { | ||
Expect(credentials).To(Equal(mockCredentials)) | ||
}) | ||
}) | ||
|
||
Describe("GcpCredentialsCreate", func() { | ||
const gcpRequestType = "GCP_SERVICE_ACCOUNT_FOR_DEPLOYMENT" | ||
mockGcpCredentials := mockCredentials | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to add quotes. There's a bug/issue if this isn't done. (Will use go 1.2).