From 6a939396cd4d136b2e4ff65ffcc950ac0a89dbf5 Mon Sep 17 00:00:00 2001 From: Alex Kalyvitis Date: Wed, 20 Jun 2018 17:18:08 +0200 Subject: [PATCH] finalise support for emails and add acceptance tests --- Gopkg.lock | 4 +- auth0/provider.go | 1 + auth0/resource_auth0_email.go | 19 ++++++++ auth0/resource_auth0_email_test.go | 45 +++++++++++++++++++ example/client/main.tf | 14 +++--- example/email/main.tf | 12 +++++ .../yieldr/go-auth0/management/connection.go | 11 +++++ .../yieldr/go-auth0/management/email.go | 2 +- 8 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 auth0/resource_auth0_email_test.go create mode 100644 example/email/main.tf diff --git a/Gopkg.lock b/Gopkg.lock index e7601164..7622a1dd 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -350,10 +350,10 @@ version = "v0.5.4" [[projects]] - branch = "master" name = "github.com/yieldr/go-auth0" packages = ["management"] - revision = "c0651c25dc756addbf61f74c3ff92830baf72a6c" + revision = "7436b4ddfc8bca5fa50c9d79033120c49d526914" + version = "v0.0.9" [[projects]] branch = "master" diff --git a/auth0/provider.go b/auth0/provider.go index 088ba21c..9a520c25 100644 --- a/auth0/provider.go +++ b/auth0/provider.go @@ -32,6 +32,7 @@ func Provider() *schema.Provider { "auth0_resource_server": newResourceServer(), "auth0_rule": newRule(), "auth0_rule_config": newRuleConfig(), + "auth0_email": newEmail(), }, ConfigureFunc: configure, } diff --git a/auth0/resource_auth0_email.go b/auth0/resource_auth0_email.go index 1a0a049a..5a14f636 100644 --- a/auth0/resource_auth0_email.go +++ b/auth0/resource_auth0_email.go @@ -84,6 +84,7 @@ func createEmail(d *schema.ResourceData, m interface{}) error { if err := api.Email.Create(e); err != nil { return err } + d.SetId(e.Name) return nil } @@ -93,9 +94,27 @@ func readEmail(d *schema.ResourceData, m interface{}) error { if err != nil { return err } + d.SetId(e.Name) d.Set("name", e.Name) d.Set("enabled", e.Enabled) d.Set("default_from_address", e.DefaultFromAddress) + + if credentials := e.Credentials; credentials != nil { + d.Set("credentials", []map[string]interface{}{ + { + "api_user": e.Credentials.APIUser, + "api_key": e.Credentials.APIKey, + "access_key_id": e.Credentials.AccessKeyID, + "secret_access_key": e.Credentials.SecretAccessKey, + "region": e.Credentials.Region, + "smtp_host": e.Credentials.SMTPHost, + "smtp_port": e.Credentials.SMTPPort, + "smtp_user": e.Credentials.SMTPUser, + "smtp_pass": e.Credentials.SMTPPass, + }, + }) + } + return nil } diff --git a/auth0/resource_auth0_email_test.go b/auth0/resource_auth0_email_test.go new file mode 100644 index 00000000..897f0347 --- /dev/null +++ b/auth0/resource_auth0_email_test.go @@ -0,0 +1,45 @@ +package auth0 + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccEmail(t *testing.T) { + + resource.Test(t, resource.TestCase{ + Providers: map[string]terraform.ResourceProvider{ + "auth0": Provider(), + }, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccEmailConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "name", "ses"), + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "enabled", "true"), + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "default_from_address", "accounts@example.com"), + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "credentials.0.access_key_id", "AKIAXXXXXXXXXXXXXXXX"), + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "credentials.0.secret_access_key", "7e8c2148xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), + resource.TestCheckResourceAttr("auth0_email.my_email_provider", "credentials.0.region", "us-east-1"), + ), + }, + }, + }) +} + +const testAccEmailConfig = ` +provider "auth0" {} + +resource "auth0_email" "my_email_provider" { + name = "ses" + enabled = true + default_from_address = "accounts@example.com" + credentials = { + access_key_id = "AKIAXXXXXXXXXXXXXXXX" + secret_access_key = "7e8c2148xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + region = "us-east-1" + } +} +` diff --git a/example/client/main.tf b/example/client/main.tf index c4005891..a14bc632 100644 --- a/example/client/main.tf +++ b/example/client/main.tf @@ -1,17 +1,17 @@ provider "auth0" {} resource "auth0_client" "my_app_client" { - name = "Example Application (Managed by Terraform)" - description = "Example Application Long Description" + name = "Example Penis Application (Managed by Terraform)" + description = "Example Penis Application Loooooong Description" app_type = "non_interactive" - is_first_party = false + is_first_party = true oidc_conformant = false - callbacks = ["https://example.com/callback"] - allowed_origins = ["https://example.com"] - web_origins = ["https://example.com"] + callbacks = ["https://peni.com/callback"] + allowed_origins = ["https://peni.com"] + web_origins = ["https://peni.com"] jwt_configuration = { - lifetime_in_seconds = 300 + lifetime_in_seconds = 120 secret_encoded = true alg = "RS256" } diff --git a/example/email/main.tf b/example/email/main.tf new file mode 100644 index 00000000..dc43f986 --- /dev/null +++ b/example/email/main.tf @@ -0,0 +1,12 @@ +provider "auth0" {} + +resource "auth0_email" "my_email_provider" { + name = "ses" + enabled = true + default_from_address = "accounts@example.com" + credentials = { + access_key_id = "AKIAXXXXXXXXXXXXXXXX" + secret_access_key = "7e8c2148xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + region = "us-east-1" + } +} diff --git a/vendor/github.com/yieldr/go-auth0/management/connection.go b/vendor/github.com/yieldr/go-auth0/management/connection.go index 40f406a7..82ba48f7 100644 --- a/vendor/github.com/yieldr/go-auth0/management/connection.go +++ b/vendor/github.com/yieldr/go-auth0/management/connection.go @@ -42,6 +42,7 @@ type Connection struct { Metadata interface{} `json:"metadata,omitempty"` } +// ConnectionOptions general options type ConnectionOptions struct { // Options for validation. @@ -71,6 +72,16 @@ type ConnectionOptions struct { // Options for adding parameters in the request to the upstream IdP. UpstreamParams interface{} `json:"upstream_params,omitempty"` + + ClientID string `json:"client_id,omitempty"` + ClientSecret string `json:"client_secret,omitempty"` + TenantDomain string `json:"tenant_domain,omitempty"` + DomainAliases []interface{} `json:"domain_aliases,omitempty"` + UseWsfed bool `json:"use_wsfed,omitempty"` + WaadProtocol string `json:"waad_protocol,omitempty"` + WaadCommonEndpoint bool `json:"waad_common_endpoint,omitempty"` + AppID string `json:"app_id,omitempty"` + AppDomain string `json:"app_domain,omitempty"` } type ConnectionManager struct { diff --git a/vendor/github.com/yieldr/go-auth0/management/email.go b/vendor/github.com/yieldr/go-auth0/management/email.go index ac7da7ca..181d4986 100644 --- a/vendor/github.com/yieldr/go-auth0/management/email.go +++ b/vendor/github.com/yieldr/go-auth0/management/email.go @@ -51,7 +51,7 @@ func (em *EmailManager) Create(e *Email) error { func (em *EmailManager) Read() (*Email, error) { e := new(Email) - err := em.m.get(em.m.getURI("emails", "provider"), e) + err := em.m.get(em.m.getURI("emails", "provider")+"?fields=name,enabled,default_from_address,credentials", e) return e, err }