Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feat_cloud_cost_credentials-#218
  • Loading branch information
samuel-br committed Apr 5, 2022
2 parents 71a740a + 2e045e5 commit 3fbe944
Show file tree
Hide file tree
Showing 45 changed files with 2,142 additions and 1,471 deletions.
3 changes: 2 additions & 1 deletion client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ type ApiClientInterface interface {
ProjectEnvironments(projectId string) ([]Environment, error)
Environment(id string) (Environment, error)
EnvironmentCreate(payload EnvironmentCreate) (Environment, error)
EnvironmentDestroy(id string) (Environment, error)
EnvironmentDestroy(id string) (EnvironmentDeployResponse, error)
EnvironmentUpdate(id string, payload EnvironmentUpdate) (Environment, error)
EnvironmentDeploy(id string, payload DeployRequest) (EnvironmentDeployResponse, error)
EnvironmentUpdateTTL(id string, payload TTL) (Environment, error)
EnvironmentScheduling(environmentId string) (EnvironmentScheduling, error)
EnvironmentSchedulingUpdate(environmentId string, payload EnvironmentScheduling) (EnvironmentScheduling, error)
EnvironmentSchedulingDelete(environmentId string) error
Deployment(id string) (DeploymentLog, error)
WorkflowTrigger(environmentId string) ([]WorkflowTrigger, error)
WorkflowTriggerUpsert(environmentId string, request WorkflowTriggerUpsertPayload) ([]WorkflowTrigger, error)
EnvironmentDriftDetection(environmentId string) (EnvironmentSchedulingExpression, error)
Expand Down
19 changes: 17 additions & 2 deletions client/api_client_mock.go

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

16 changes: 16 additions & 0 deletions client/api_key.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package client

type ApiKey struct {
Id string `json:"id"`
Name string `json:"name"`
ApiKeyId string `json:"apiKeyId"`
ApiKeySecret string `json:"apiKeySecret"`
LastUsedAt string `json:"lastUsedAt"`
OrganizationId string `json:"organizationId"`
CreatedAt string `json:"createdAt"`
CreatedBy string `json:"createdBy"`
CreatedByUser User `json:"createdByUser"`
}

type ApiKeyCreatePayload struct {
Name string `json:"name"`
}

type ApiKeyCreatePayloadWith struct {
ApiKeyCreatePayload
OrganizationId string `json:"organizationId"`
Expand Down
73 changes: 73 additions & 0 deletions client/cloud_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,79 @@ import (
"fmt"
)

type AwsCredentialsType string
type GcpCredentialsType string
type AzureCredentialsType string

type Credentials struct {
Id string `json:"id"`
Name string `json:"name"`
OrganizationId string `json:"organizationId"`
Type string `json:"type"`
}

type AzureCredentialsCreatePayload struct {
Name string `json:"name"`
OrganizationId string `json:"organizationId"`
Type AzureCredentialsType `json:"type"`
Value AzureCredentialsValuePayload `json:"value"`
}

type AzureCredentialsValuePayload struct {
ClientId string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
SubscriptionId string `json:"subscriptionId"`
TenantId string `json:"tenantId"`
}

type AwsCredentialsCreatePayload struct {
Name string `json:"name"`
OrganizationId string `json:"organizationId"`
Type AwsCredentialsType `json:"type"`
Value AwsCredentialsValuePayload `json:"value"`
}

type AwsCredentialsValuePayload struct {
RoleArn string `json:"roleArn"`
ExternalId string `json:"externalId"`
AccessKeyId string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
}

type GoogleCostCredentialsCreatePayload struct {
Name string `json:"name"`
OrganizationId string `json:"organizationId"`
Type GcpCredentialsType `json:"type"`
Value GoogleCostCredentialsValeuPayload `json:"value"`
}

type GoogleCostCredentialsValeuPayload struct {
TableId string `json:"tableid"`
Secret string `json:"secret"`
}

type GcpCredentialsCreatePayload struct {
Name string `json:"name"`
OrganizationId string `json:"organizationId"`
Type GcpCredentialsType `json:"type"`
Value GcpCredentialsValuePayload `json:"value"`
}

type GcpCredentialsValuePayload struct {
ProjectId string `json:"projectId"`
ServiceAccountKey string `json:"serviceAccountKey"`
}

const (
GoogleCostCredentiassType GcpCredentialsType = "GCP_CREDENTIALS"
AzureCostCredentialsType AzureCredentialsType = "AZURE_CREDENTIALS"
AwsCostCredentialsType AwsCredentialsType = "AWS_ASSUMED_ROLE"
AwsAssumedRoleCredentialsType AwsCredentialsType = "AWS_ASSUMED_ROLE_FOR_DEPLOYMENT"
AwsAccessKeysCredentialsType AwsCredentialsType = "AWS_ACCESS_KEYS_FOR_DEPLOYMENT"
GcpServiceAccountCredentialsType GcpCredentialsType = "GCP_SERVICE_ACCOUNT_FOR_DEPLOYMENT"
AzureServicePrincipalCredentialsType AzureCredentialsType = "AZURE_SERVICE_PRINCIPAL_FOR_DEPLOYMENT"
)

func (self *ApiClient) CloudCredentials(id string) (Credentials, error) {
var credentials, err = self.CloudCredentialsList()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions client/cloud_credentials_project_assignment.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package client

type CloudCredentialIdsInProjectResponse struct {
CredentialIds []string `json:"credentialIds"`
}

type CloudCredentialsProjectAssignment struct {
Id string `json:"id"`
CredentialId string `json:"credentialId"`
ProjectId string `json:"projectId"`
}

func (self *ApiClient) AssignCloudCredentialsToProject(projectId string, credentialId string) (CloudCredentialsProjectAssignment, error) {
var result CloudCredentialsProjectAssignment

Expand Down
13 changes: 13 additions & 0 deletions client/common_models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package client

type User struct {
CreatedAt string `json:"created_at"`
Email string `json:"email"`
FamilyName string `json:"family_name"`
GivenName string `json:"given_name"`
Name string `json:"name"`
Picture string `json:"picture"`
UserId string `json:"user_id"`
LastLogin string `json:"last_login"`
AppMetadata map[string]interface{} `json:"app_metadata"`
}
61 changes: 61 additions & 0 deletions client/configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,67 @@ import (
"errors"
)

type Scope string

const (
ScopeGlobal Scope = "GLOBAL"
ScopeTemplate Scope = "BLUEPRINT"
ScopeProject Scope = "PROJECT"
ScopeEnvironment Scope = "ENVIRONMENT"
ScopeDeployment Scope = "DEPLOYMENT"
ScopeDeploymentLog Scope = "DEPLOYMENT_LOG"
)

type Format string

const (
Text Format = ""
HCL Format = "HCL"
JSON Format = "JSON"
)

type ConfigurationVariableSchema struct {
Type string `json:"type"`
Enum []string `json:"enum"`
Format Format `json:"format,omitempty"`
}

type ConfigurationVariable struct {
ScopeId string `json:"scopeId,omitempty"`
Value string `json:"value"`
OrganizationId string `json:"organizationId,omitempty"`
UserId string `json:"userId,omitempty"`
IsSensitive *bool `json:"isSensitive,omitempty"`
Scope Scope `json:"scope,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type *ConfigurationVariableType `json:"type,omitempty"`
Schema *ConfigurationVariableSchema `json:"schema,omitempty"`
ToDelete *bool `json:"toDelete,omitempty"`
IsReadonly *bool `json:"isReadonly,omitempty"`
IsRequired *bool `json:"isRequired,omitempty"`
}

type ConfigurationVariableCreateParams struct {
Name string
Value string
IsSensitive bool
Scope Scope
ScopeId string
Type ConfigurationVariableType
EnumValues []string
Description string
Format Format
IsReadonly bool
IsRequired bool
}

type ConfigurationVariableUpdateParams struct {
CommonParams ConfigurationVariableCreateParams
Id string
}

func (self *ApiClient) ConfigurationVariablesById(id string) (ConfigurationVariable, error) {
var result ConfigurationVariable

Expand Down
29 changes: 29 additions & 0 deletions client/configuration_variable_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client_test

import (
"encoding/json"

. "github.com/env0/terraform-provider-env0/client"
"github.com/golang/mock/gomock"
"github.com/jinzhu/copier"
Expand Down Expand Up @@ -35,6 +37,33 @@ var _ = Describe("Configuration Variable", func() {
IsRequired: &isRequired,
}

Describe("ConfigurationVariable", func() {
Describe("Schema", func() {
It("On schema type is free text, enum should be nil", func() {
var parsedPayload ConfigurationVariable
json.Unmarshal([]byte(`{"schema": {"type": "string"}}`), &parsedPayload)
Expect(parsedPayload.Schema.Type).Should(Equal("string"))
Expect(parsedPayload.Schema.Enum).Should(BeNil())
})

It("On schema type is dropdown, enum should be present", func() {
var parsedPayload ConfigurationVariable
json.Unmarshal([]byte(`{"schema": {"type": "string", "enum": ["hello"]}}`), &parsedPayload)
Expect(parsedPayload.Schema.Type).Should(Equal("string"))
Expect(parsedPayload.Schema.Enum).Should(BeEquivalentTo([]string{"hello"}))
})
})

Describe("Enums", func() {
It("Should convert enums correctly", func() {
var parsedPayload ConfigurationVariable
json.Unmarshal([]byte(`{"scope":"PROJECT", "type": 1}`), &parsedPayload)
Expect(parsedPayload.Scope).Should(Equal(ScopeProject))
Expect(*parsedPayload.Type).Should(Equal(ConfigurationVariableTypeTerraform))
})
})
})

Describe("ConfigurationVariablesById", func() {
id := "configurationId"
var found ConfigurationVariable
Expand Down
6 changes: 6 additions & 0 deletions client/cost_credentials_project_assignment.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package client

type CostCredentialProjectAssignment struct {
ProjectId string `json:"projectId"`
CredentialsId string `json:"credentialsId"`
CredentialsType string `json:"credentialsType"`
}

func (self *ApiClient) AssignCostCredentialsToProject(projectId string, credentialId string) (CostCredentialProjectAssignment, error) {
var result CostCredentialProjectAssignment

Expand Down
Loading

0 comments on commit 3fbe944

Please sign in to comment.