Skip to content
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

Add direct push provider, fixes #534 #535

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/resources/guardian.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ Optional:

- `amazon_sns` (Block List, Max: 1) Configuration for Amazon SNS. (see [below for nested schema](#nestedblock--push--amazon_sns))
- `custom_app` (Block List, Max: 1) Configuration for the Guardian Custom App. (see [below for nested schema](#nestedblock--push--custom_app))
- `provider` (String) Provider to use, one of `guardian`, `sns`.
- `direct_apns` (Block List, Max: 1) Configuration for the Apple Push Notification service (APNs) settings. (see [below for nested schema](#nestedblock--push--direct_apns))
- `direct_fcm` (Block List, Max: 1) Configuration for Firebase Cloud Messaging (FCM) settings. (see [below for nested schema](#nestedblock--push--direct_fcm))
- `provider` (String) Provider to use, one of `direct`, `guardian`, `sns`.

<a id="nestedblock--push--amazon_sns"></a>
### Nested Schema for `push.amazon_sns`
Expand All @@ -163,6 +165,28 @@ Optional:
- `google_app_link` (String) Google Store URL. Must be HTTPS or an empty string.


<a id="nestedblock--push--direct_apns"></a>
### Nested Schema for `push.direct_apns`

Required:

- `bundle_id` (String) The Apple Push Notification service Bundle ID.
- `p12` (String, Sensitive) The base64 encoded certificate in P12 format.
- `sandbox` (Boolean) Set to true to use the sandbox iOS app environment, otherwise set to false to use the production iOS app environment.

Optional:

- `enabled` (Boolean) Indicates whether the Apple Push Notification service is enabled.


<a id="nestedblock--push--direct_fcm"></a>
### Nested Schema for `push.direct_fcm`

Required:

- `server_key` (String, Sensitive) The Firebase Cloud Messaging Server Key. For security purposes, we don’t retrieve your existing FCM server key to check for drift.



<a id="nestedblock--webauthn_platform"></a>
### Nested Schema for `webauthn_platform`
Expand Down
46 changes: 46 additions & 0 deletions internal/auth0/guardian/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ func updatePush(d *schema.ResourceData, api *management.Management) error {
}
}

if d.HasChange("push.0.direct_apns") {
if err = updateDirectAPNS(push.GetAttr("direct_apns"), api); err != nil {
return true
}
}

if d.HasChange("push.0.direct_fcm") {
if err = updateDirectFCM(push.GetAttr("direct_fcm"), api); err != nil {
return true
}
}

if d.HasChange("push.0.amazon_sns") {
if err = updateAmazonSNS(push.GetAttr("amazon_sns"), api); err != nil {
return true
Expand Down Expand Up @@ -323,3 +335,37 @@ func updateCustomApp(options cty.Value, api *management.Management) error {

return err
}

func updateDirectAPNS(options cty.Value, api *management.Management) error {
var err error

options.ForEachElement(func(_ cty.Value, config cty.Value) (stop bool) {
err = api.Guardian.MultiFactor.Push.UpdateDirectAPNS(
&management.MultiFactorPushDirectAPNS{
Sandbox: value.Bool(config.GetAttr("sandbox")),
BundleID: value.String(config.GetAttr("bundle_id")),
P12: value.String(config.GetAttr("p12")),
},
)

return stop
})

return err
}

func updateDirectFCM(options cty.Value, api *management.Management) error {
var err error

options.ForEachElement(func(_ cty.Value, config cty.Value) (stop bool) {
err = api.Guardian.MultiFactor.Push.UpdateDirectFCM(
&management.MultiFactorPushDirectFCM{
ServerKey: value.String(config.GetAttr("server_key")),
},
)

return stop
})

return err
}
20 changes: 20 additions & 0 deletions internal/auth0/guardian/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ func flattenPush(d *schema.ResourceData, enabled bool, api *management.Managemen
},
}

directAPNS, err := api.Guardian.MultiFactor.Push.DirectAPNS()
if err != nil {
return nil, err
}

pushData["direct_apns"] = []interface{}{
map[string]interface{}{
"sandbox": directAPNS.GetSandbox(),
"p12": d.Get("push.0.direct_apns.0.p12"), // Does not get read back.
"bundle_id": directAPNS.GetBundleID(),
"enabled": directAPNS.GetEnabled(),
},
}

pushData["direct_fcm"] = []interface{}{
map[string]interface{}{
"server_key": d.Get("push.0.direct_fcm.0.server_key"), // Does not get read back.
},
}

if pushProvider.GetProvider() == "sns" {
amazonSNS, err := api.Guardian.MultiFactor.Push.AmazonSNS()
if err != nil {
Expand Down
59 changes: 57 additions & 2 deletions internal/auth0/guardian/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func NewResource() *schema.Resource {
"provider": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"guardian", "sns"}, false),
Description: "Provider to use, one of `guardian`, `sns`.",
ValidateFunc: validation.StringInSlice([]string{"direct", "guardian", "sns"}, false),
Description: "Provider to use, one of `direct`, `guardian`, `sns`.",
},
"amazon_sns": {
Type: schema.TypeList,
Expand Down Expand Up @@ -348,6 +348,61 @@ func NewResource() *schema.Resource {
},
},
},
"direct_apns": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
RequiredWith: []string{"push.0.provider"},
Description: "Configuration for the Apple Push Notification service (APNs) settings.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sandbox": {
Type: schema.TypeBool,
Required: true,
Description: "Set to true to use the sandbox iOS app environment, " +
"otherwise set to false to use the production iOS app environment.",
},
"bundle_id": {
Type: schema.TypeString,
Required: true,
Description: "The Apple Push Notification service Bundle ID.",
},
"p12": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: "The base64 encoded certificate in P12 format.",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Indicates whether the Apple Push Notification service is enabled.",
},
},
},
},
"direct_fcm": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
RequiredWith: []string{"push.0.provider"},
Description: "Configuration for Firebase Cloud Messaging (FCM) settings.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"server_key": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: "The Firebase Cloud Messaging Server Key. " +
"For security purposes, we don’t retrieve your existing FCM server key " +
"to check for drift.",
},
},
},
},
},
},
},
Expand Down
60 changes: 60 additions & 0 deletions internal/auth0/guardian/resource_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package guardian_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stretchr/testify/require"

"github.com/auth0/terraform-provider-auth0/internal/acctest"
)
Expand Down Expand Up @@ -443,6 +446,36 @@ resource "auth0_guardian" "foo" {
}
`

const testAccConfigurePushUpdateDirectAPNS = `
resource "auth0_guardian" "foo" {
policy = "all-applications"
push {
enabled = true
provider = "direct"

direct_apns {
sandbox = false
bundle_id = "com.my.app"
p12 = %q
}
}
}
`

const testAccConfigurePushUpdateDirectFCM = `
resource "auth0_guardian" "foo" {
policy = "all-applications"
push {
enabled = true
provider = "direct"

direct_fcm {
server_key = "abc123"
}
}
}
`

const testAccConfigurePushDelete = `
resource "auth0_guardian" "foo" {
policy = "all-applications"
Expand All @@ -453,6 +486,9 @@ resource "auth0_guardian" "foo" {
`

func TestAccGuardianPush(t *testing.T) {
apnsCertificate, err := os.ReadFile("./../../../test/data/apns.p12")
require.NoError(t, err)

acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -498,6 +534,30 @@ func TestAccGuardianPush(t *testing.T) {
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.custom_app.0.google_app_link", "https://play.google.com/store/apps/details?id=com.my.app"),
),
},
{
Config: fmt.Sprintf(testAccConfigurePushUpdateDirectAPNS, apnsCertificate),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_guardian.foo", "policy", "all-applications"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.#", "1"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.enabled", "true"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.provider", "direct"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.direct_apns.#", "1"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.direct_apns.0.sandbox", "false"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.direct_apns.0.bundle_id", "com.my.app"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.direct_apns.0.enabled", "true"),
resource.TestCheckResourceAttrSet("auth0_guardian.foo", "push.0.direct_apns.0.p12"),
),
},
{
Config: testAccConfigurePushUpdateDirectFCM,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_guardian.foo", "policy", "all-applications"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.#", "1"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.enabled", "true"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.provider", "direct"),
resource.TestCheckResourceAttr("auth0_guardian.foo", "push.0.direct_fcm.#", "1"),
),
},
{
Config: testAccConfigurePushDelete,
Check: resource.ComposeTestCheckFunc(
Expand Down
1 change: 1 addition & 0 deletions test/data/apns.p12
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MIIPWQIBAzCCDx8GCSqGSIb3DQEHAaCCDxAEgg8MMIIPCDCCBT8GCSqGSIb3DQEHBqCCBTAwggUsAgEAMIIFJQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIEqASt2nke/cCAggAgIIE+OfXs2QaQi6YCoX8miVklKSBTaRo4H3beDeRdKM9+EunR361uyTPAcMtnxedEBtJcGtV0rXGn5OW70Spux8KW8rj2TW3cMe8qn+6iZyauv+G3VkOGiHdY5BAYRea3oyPwmMEfvLkYLUYxcZip22M8U0rpR9AUy+eVk7RxYSXa9YqIkwRDqkLY1lUhtROxdwpXE5hk+9YqnUYyrQm4rsIVJJT+G8Yqdn950v0bQZnG6VipvHrnUTMotQxZDHOENFeH4PJkRhdbvRpAC7ayTZaSqjbV6BjFnA3hCy/5xHtWQukCEilSySDZ82/l8nn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