This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package management | ||
|
||
type HookSecrets = map[string]string | ||
|
||
type HookSecretsManager struct { | ||
*Management | ||
} | ||
|
||
func newHookSecretsManager(m *Management) *HookSecretsManager { | ||
return &HookSecretsManager{m} | ||
} | ||
|
||
// Upserts hook secrets | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Hooks/post_secrets | ||
func (m *HookSecretsManager) Upsert(hookId string, r *HookSecrets) (err error) { | ||
return m.post(m.hookPath(hookId), r) | ||
} | ||
|
||
// Reads hook secrets | ||
// | ||
// Note: For security, hook secret values cannot be retrieved outside rule | ||
// execution (they all appear as "_VALUE_NOT_SHOWN_") | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Rules_Configs/get_rules_configs | ||
func (m *HookSecretsManager) Read(hookId string) (r *HookSecrets, err error) { | ||
err = m.get(m.hookPath(hookId), &r) | ||
return | ||
} | ||
|
||
// Delete a list of hook secret keys from a given hook's secrets identified by its hookId and the keys | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Rules_Configs/delete_rules_configs_by_key | ||
func (m *HookSecretsManager) Delete(hookId string, keys ...string) (err error) { | ||
return m.request("DELETE", m.hookPath(hookId), keys) | ||
} | ||
|
||
|
||
func (m *HookSecretsManager) hookPath(hookId string) string { | ||
return m.uri("hooks", hookId, "secrets") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package management | ||
|
||
import ( | ||
"gopkg.in/auth0.v4/internal/testing/expect" | ||
"testing" | ||
|
||
"gopkg.in/auth0.v4" | ||
) | ||
|
||
func TestHookSecrets(t *testing.T) { | ||
|
||
r := &map[string]string{ | ||
"SECRET1": "value1", | ||
"SECRET2": "value2", | ||
} | ||
|
||
hook := &Hook{ | ||
Name: auth0.String("test-hook-secrets"), | ||
Script: auth0.String("function (user, context, callback) { callback(null, { user }); }"), | ||
TriggerID: auth0.String("pre-user-registration"), | ||
Enabled: auth0.Bool(false), | ||
} | ||
|
||
err := m.Hook.Create(hook) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Cleanup(func() { | ||
if err = m.Hook.Delete(hook.GetID()); err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
t.Run("Upsert", func(t *testing.T) { | ||
err = m.HookSecrets.Upsert(hook.GetID(), r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%v\n", r) | ||
}) | ||
|
||
t.Run("Read", func(t *testing.T) { | ||
result, err := m.HookSecrets.Read(hook.GetID()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%v\n", r) | ||
|
||
expect.Expect(t, (*result)["SECRET1"], "_VALUE_NOT_SHOWN_") | ||
expect.Expect(t, (*result)["SECRET2"], "_VALUE_NOT_SHOWN_") | ||
}) | ||
|
||
t.Run("Delete", func(t *testing.T) { | ||
err = m.HookSecrets.Delete(hook.GetID(), "SECRET1") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
result, err := m.HookSecrets.Read(hook.GetID()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%v\n", r) | ||
|
||
expect.Expect(t, (*result)["SECRET1"], "") | ||
expect.Expect(t, (*result)["SECRET2"], "_VALUE_NOT_SHOWN_") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters