Skip to content

Commit

Permalink
v0.0.22 - Update libs to v0.0.14
Browse files Browse the repository at this point in the history
* Initialize ResourceManager with base url for Service Registry rather than a url specifically for services
* Introduce notion of default Authenticator to be used with McmaHttpClient and set it when only one Authenticator is registered
  • Loading branch information
evanverneyfink committed Oct 14, 2022
1 parent 0467a25 commit f4c918d
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 56 deletions.
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ description: |-
```terraform
# No auth
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
}
# AWS auth with profile
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
aws4_auth {
region = "us-east-1"
profile = "myprofile"
Expand All @@ -29,7 +29,7 @@ provider "mcma" {
# AWS auth with keys
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
aws4_auth {
region = "us-east-1"
access_key = "accesskey"
Expand All @@ -43,12 +43,12 @@ provider "mcma" {

### Required

- `services_url` (String) The url to the services endpoint of the MCMA Service Registry
- `service_registry_url` (String) The url to the services endpoint of the MCMA Service Registry

### Optional

- `aws4_auth` (Block Set) (see [below for nested schema](#nestedblock--aws4_auth))
- `services_auth_type` (String) The auth type to use for the services endpoint of the MCMA Service Registry
- `service_registry_auth_type` (String) The auth type to use for the services endpoint of the MCMA Service Registry

<a id="nestedblock--aws4_auth"></a>
### Nested Schema for `aws4_auth`
Expand Down
6 changes: 3 additions & 3 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# No auth
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
}

# AWS auth with profile
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
aws4_auth {
region = "us-east-1"
profile = "myprofile"
Expand All @@ -14,7 +14,7 @@ provider "mcma" {

# AWS auth with keys
provider "mcma" {
services_url = "https://service-registry-example.mcma.io/api/services"
service_registry_url = "https://service-registry-example.mcma.io/api/"
aws4_auth {
region = "us-east-1"
access_key = "accesskey"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ebu/terraform-provider-mcma
go 1.18

require (
github.com/ebu/mcma-libraries-go v0.0.13
github.com/ebu/mcma-libraries-go v0.0.14
github.com/hashicorp/terraform-plugin-docs v0.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ebu/mcma-libraries-go v0.0.13 h1:UgJcM/54947ZllMuqwxsSPqBqSlXfLIvkTucjI0e2Rs=
github.com/ebu/mcma-libraries-go v0.0.13/go.mod h1:RnT/sTbg7ICp6NHDxyj/xX9xI+bqbcm9SUkPTIJnqs4=
github.com/ebu/mcma-libraries-go v0.0.14 h1:ZIsQ2f+COcvsS8gAeAKyFK98qNUw6AI7OmXCa5y0uts=
github.com/ebu/mcma-libraries-go v0.0.14/go.mod h1:RnT/sTbg7ICp6NHDxyj/xX9xI+bqbcm9SUkPTIJnqs4=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
3 changes: 2 additions & 1 deletion mcma/auth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package mcma

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"reflect"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

func GetAuthDataString(authData map[string]interface{}, key string, required bool) (string, diag.Diagnostics) {
Expand Down
13 changes: 7 additions & 6 deletions mcma/aws_auth.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package mcma

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"os"

mcma "github.com/ebu/mcma-libraries-go/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
)

func GetAWS4Authenticator(authData map[string]interface{}) (mcma.Authenticator, diag.Diagnostics) {
func GetAWS4Authenticator(authData map[string]interface{}) (mcmaclient.Authenticator, diag.Diagnostics) {
region, d := GetAuthDataString(authData, "region", false)
if d != nil {
return nil, d
Expand All @@ -34,16 +35,16 @@ func GetAWS4Authenticator(authData map[string]interface{}) (mcma.Authenticator,
if d != nil {
return nil, d
}
return mcma.NewAWS4AuthenticatorFromKeys(accessKey, secretKey, sessionToken, region), nil
return mcmaclient.NewAWS4AuthenticatorFromKeys(accessKey, secretKey, sessionToken, region), nil
}

profile, d := GetAuthDataString(authData, "profile", false)
if d != nil {
return nil, d
}
if len(profile) > 0 {
return mcma.NewAWS4AuthenticatorFromProfile(profile, region), nil
return mcmaclient.NewAWS4AuthenticatorFromProfile(profile, region), nil
}

return mcma.NewAWS4AuthenticatorFromEnvVars(), nil
return mcmaclient.NewAWS4AuthenticatorFromEnvVars(), nil
}
25 changes: 13 additions & 12 deletions mcma/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package mcma
import (
"context"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
)

func init() {
Expand All @@ -15,12 +16,12 @@ func init() {
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"services_url": {
"service_registry_url": {
Type: schema.TypeString,
Description: "The url to the services endpoint of the MCMA Service Registry",
Required: true,
},
"services_auth_type": {
"service_registry_auth_type": {
Type: schema.TypeString,
Description: "The auth type to use for the services endpoint of the MCMA Service Registry",
Optional: true,
Expand Down Expand Up @@ -89,26 +90,26 @@ func addAuthToMap(
}

func configure(d *schema.ResourceData) (interface{}, diag.Diagnostics) {
servicesUrl := d.Get("services_url").(string)
if servicesUrl == "" {
serviceRegistryUrl := d.Get("service_registry_url").(string)
if serviceRegistryUrl == "" {
return nil, nil
}
servicesAuthType := d.Get("services_auth_type").(string)
serviceRegistryAuthType := d.Get("service_registry_auth_type").(string)

authMap := make(map[string]mcmaclient.Authenticator)
addAuthToMap(authMap, d, "aws4", GetAWS4Authenticator)

if len(authMap) == 1 && servicesAuthType == "" {
if len(authMap) == 1 && serviceRegistryAuthType == "" {
for s := range authMap {
servicesAuthType = s
serviceRegistryAuthType = s
}
}

var resourceManager mcmaclient.ResourceManager
if len(servicesAuthType) != 0 {
resourceManager = mcmaclient.NewResourceManager(servicesUrl, servicesAuthType)
if len(serviceRegistryAuthType) != 0 {
resourceManager = mcmaclient.NewResourceManager(serviceRegistryUrl, serviceRegistryAuthType)
} else {
resourceManager = mcmaclient.NewResourceManagerNoAuth(servicesUrl)
resourceManager = mcmaclient.NewResourceManagerNoAuth(serviceRegistryUrl)
}

for key, a := range authMap {
Expand All @@ -124,7 +125,7 @@ func getResourceManager(m interface{}) (*mcmaclient.ResourceManager, diag.Diagno
diag.Diagnostic{
Severity: diag.Error,
Summary: "ResourceManager not initialized.",
Detail: "Url for MCMA service registry was not provided, and the MCMA_SERVICES_URL environment variable is not set.",
Detail: "Url for MCMA service registry was not provided, and the MCMA_SERVICE_REGISTRY_URL environment variable is not set.",
},
}
}
Expand Down
19 changes: 10 additions & 9 deletions mcma/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mcma

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"os"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var testAccProvider *schema.Provider
Expand All @@ -22,11 +23,11 @@ type aws4AuthBlock struct {
secretKey string
}

func getProviderConfig(servicesUrl string, servicesAuthType string, authBlocks []aws4AuthBlock) string {
func getProviderConfig(serviceRegistryUrl string, serviceRegistryAuthType string, authBlocks []aws4AuthBlock) string {
providerConfig := "provider \"mcma\" {\n"
providerConfig += " services_url = \"" + servicesUrl + "\"\n"
if servicesAuthType != "" {
providerConfig += " services_auth_type = \"" + servicesAuthType + "\"\n"
providerConfig += " service_registry_url = \"" + serviceRegistryUrl + "\"\n"
if serviceRegistryAuthType != "" {
serviceRegistryAuthType += " service_registry_auth_type = \"" + serviceRegistryAuthType + "\"\n"
}
if authBlocks != nil && len(authBlocks) > 0 {
for _, authBlock := range authBlocks {
Expand All @@ -50,19 +51,19 @@ func getProviderConfig(servicesUrl string, servicesAuthType string, authBlocks [
return providerConfig
}

func getAwsProfileProviderConfig(servicesUrl string, region string, profile string) string {
func getAwsProfileProviderConfig(serviceRegistryUrl string, region string, profile string) string {
authBlocks := make([]aws4AuthBlock, 1)
authBlocks[0] = aws4AuthBlock{
region: region,
profile: profile,
}
return getProviderConfig(servicesUrl, "", authBlocks)
return getProviderConfig(serviceRegistryUrl, "", authBlocks)
}

func getAwsProfileProviderConfigFromEnvVars() string {
return getAwsProfileProviderConfig(os.Getenv("MCMA_AWS_SERVICES_URL"), os.Getenv("MCMA_AWS_REGION"), os.Getenv("MCMA_AWS_PROFILE"))
return getAwsProfileProviderConfig(os.Getenv("MCMA_AWS_SERVICE_REGISTRY_URL"), os.Getenv("MCMA_AWS_REGION"), os.Getenv("MCMA_AWS_PROFILE"))
}

func getKubernetesProviderConfigFromEnvVars() string {
return getProviderConfig(os.Getenv("MCMA_KUBERNETES_SERVICES_URL"), "", nil)
return getProviderConfig(os.Getenv("MCMA_KUBERNETES_SERVICE_REGISTRY_URL"), "", nil)
}
5 changes: 3 additions & 2 deletions mcma/resource_job_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package mcma

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"reflect"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

mcmamodel "github.com/ebu/mcma-libraries-go/model"
)

Expand Down
12 changes: 7 additions & 5 deletions mcma/resource_job_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package mcma

import (
"fmt"
mcmaclient "github.com/ebu/mcma-libraries-go/client"
mcmamodel "github.com/ebu/mcma-libraries-go/model"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"reflect"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
mcmamodel "github.com/ebu/mcma-libraries-go/model"
)

func TestAccMcmaJobProfile_basic(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions mcma/resource_mcma_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
8 changes: 5 additions & 3 deletions mcma/resource_mcma_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package mcma

import (
"fmt"
mcmaclient "github.com/ebu/mcma-libraries-go/client"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"testing"
"time"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
)

func TestAccMcmaResource_basic(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions mcma/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package mcma

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"reflect"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

mcmamodel "github.com/ebu/mcma-libraries-go/model"
)

Expand Down
12 changes: 7 additions & 5 deletions mcma/resource_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package mcma

import (
"fmt"
mcmaclient "github.com/ebu/mcma-libraries-go/client"
mcmamodel "github.com/ebu/mcma-libraries-go/model"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"reflect"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

mcmaclient "github.com/ebu/mcma-libraries-go/client"
mcmamodel "github.com/ebu/mcma-libraries-go/model"
)

func TestAccMcmaService_basic(t *testing.T) {
Expand Down

0 comments on commit f4c918d

Please sign in to comment.