Skip to content

Commit

Permalink
Feat: add support for update credentials (#709)
Browse files Browse the repository at this point in the history
* Feat: add support for update credentials

* update mockgen

* WIP

* WIP

* WIP

* Added update
  • Loading branch information
TomerHeber committed Sep 18, 2023
1 parent 2501418 commit 51748f7
Show file tree
Hide file tree
Showing 85 changed files with 316 additions and 259 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
go install go.uber.org/mock/mockgen@v0.2.0
go generate client/api_client.go
- name: Go fmt
run: |
Expand All @@ -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
24 changes: 10 additions & 14 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
29 changes: 12 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,31 @@ name: release
on:
push:
tags:
- 'v*.*.*'
- "v*.*.*"

env:
GO_VERSION: 1.19
GO_VERSION: "1.20"

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Unshallow
- name: Checkout
uses: actions/checkout@v4
- 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: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
go-version: "${{ env.GO_VERSION }}"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ resource "env0_template" "example" {

## Development Setup

> **Supported Go Version: 1.19**
> **Supported Go Version: 1.20**
### Build

Expand Down Expand Up @@ -185,7 +185,7 @@ export PATH=$PATH:$(go env GOPATH) # if not
2. Install mockgen

```
go install github.com/golang/mock/mockgen@v1.6.0
go install go.uber.org/mock/mockgen@v0.2.0
```

3. Make sure to add this line in files that include the interface you'd wish to mock:
Expand Down
2 changes: 1 addition & 1 deletion client/agent_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

. "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("Agent Project Assignment", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

. "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("Agent Client", func() {
Expand Down
1 change: 1 addition & 0 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ApiClientInterface interface {
SshKeyCreate(payload SshKeyCreatePayload) (*SshKey, error)
SshKeyDelete(id string) error
CredentialsCreate(request CredentialCreatePayload) (Credentials, error)
CredentialsUpdate(id string, request CredentialCreatePayload) (Credentials, error)
CloudCredentials(id string) (Credentials, error)
CloudCredentialsList() ([]Credentials, error)
CloudCredentialsDelete(id string) error
Expand Down
17 changes: 16 additions & 1 deletion client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package client_test

import (
. "github.com/env0/terraform-provider-env0/client"
"github.com/golang/mock/gomock"
"github.com/jinzhu/copier"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

var _ = Describe("ApiKey Client", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/approval_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"

. "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("Approval Policy Client", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

. "github.com/env0/terraform-provider-env0/client"
"github.com/env0/terraform-provider-env0/client/http"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

// This file wraps the test suite for the entire client folder
Expand Down
19 changes: 18 additions & 1 deletion client/cloud_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return Credentials{}, err
}

return result, nil
}

func (client *ApiClient) CredentialsUpdate(id string, request CredentialCreatePayload) (Credentials, error) {
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
}

Expand Down
2 changes: 1 addition & 1 deletion client/cloud_credentials_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

. "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("Credentials Project Assignment", func() {
Expand Down
42 changes: 41 additions & 1 deletion client/cloud_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -115,6 +115,46 @@ var _ = Describe("CloudCredentials", func() {
})
})

Describe("AwsCredentialsUpdate", func() {
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
Expand Down
2 changes: 1 addition & 1 deletion client/configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"

. "github.com/env0/terraform-provider-env0/client"
"github.com/golang/mock/gomock"
"github.com/jinzhu/copier"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

var _ = Describe("Configuration Variable", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/cost_credentials_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

. "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(" Cost Credentials Project Assignment", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/custom_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package client_test

import (
. "github.com/env0/terraform-provider-env0/client"
"github.com/golang/mock/gomock"
"github.com/jinzhu/copier"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

var _ = Describe("Custom Flow Client", func() {
Expand Down
2 changes: 1 addition & 1 deletion client/environment_drift_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"

. "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("EnvironmentDriftDetection", func() {
Expand Down
Loading

0 comments on commit 51748f7

Please sign in to comment.