Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

add "HookSecrets" support #107

Merged
merged 6 commits into from
Apr 7, 2020
Merged

Conversation

yinzara
Copy link
Contributor

@yinzara yinzara commented Apr 2, 2020

Mind making a tagged release after? :)

@yinzara yinzara force-pushed the feature/hook-secrets branch 4 times, most recently from 54156fe to a27e44a Compare April 2, 2020 23:04
@yinzara yinzara force-pushed the feature/hook-secrets branch from a27e44a to bb1c40a Compare April 2, 2020 23:07

func newHookSecretsManager(m *Management) *HookSecretsManager {
return &HookSecretsManager{m}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add this to the HookManager instead. See the UserManager and RoleManager for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. I'll move it into the hook manager.

// 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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST /api/v2/hooks/{id}/secrets doesn't have upsert semantics. Posting a map that contains an existing field will result in a conflict.

{
  "statusCode": 409,
  "error": "Conflict",
  "message": "Error: Secret exists",
  "errorCode": "SecretExists"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG It's even worse than that. The PATCH doesn't work if you specify a new secret field. I found the only way to add a new secret to a hook that already has a secret is to completely DELETE all secrets for that hook then "POST" with all keys and values (even though you can't retrieve the values via the API). I've got a ticket open with Auth0 support about this.

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When moved to the HookManager this could be called Secrets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can add a Keys() []string method to HookSecrets to help with specifying keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


func (m *HookSecretsManager) hookPath(hookId string) string {
return m.uri("hooks", hookId, "secrets")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm being a little pedantic here but this is not the hooks path, it's the hooks secrets path. I'd also remove it altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it. I hate duplicating code but I see how it's kinda already copied and pasted everywhere already. I'll remove it.

t.Fatal(err)
}

t.Cleanup(func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of this function! Thanks! TIL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of it until my IDE told me it existed :)

@yinzara yinzara force-pushed the feature/hook-secrets branch 2 times, most recently from 34ad06d to a9672b0 Compare April 3, 2020 19:03
@yinzara yinzara force-pushed the feature/hook-secrets branch from a9672b0 to f78a5b7 Compare April 3, 2020 19:04
if len(k) > 0 {
keys[i] = k
}
i++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nil check has the potential to leave the keys slice with less elements than it was made to hold right? Why must we check for len(k) > 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only question remaining from my side, otherwise this PR is good to go

@alexkappa alexkappa merged commit b24d2c7 into go-auth0:master Apr 7, 2020
@alexkappa
Copy link
Contributor

Thanks Matt!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants