-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
VAULT-6433: Add namespace path to MFA read/list endpoints #16911
Conversation
@@ -1361,6 +1361,10 @@ func (b *LoginMFABackend) mfaLoginEnforcementConfigByNameAndNamespace(name, name | |||
func (b *LoginMFABackend) mfaLoginEnforcementConfigToMap(eConfig *mfa.MFAEnforcementConfig) (map[string]interface{}, error) { | |||
resp := make(map[string]interface{}) | |||
resp["name"] = eConfig.Name | |||
ns, err := b.namespacer.NamespaceByID(context.Background(), eConfig.NamespaceID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle the error if it is not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure - I don't like failing silently but similarly, the endpoint wouldn't have complained before and would have e.g. returned error, so I thought it best to keep the previous behaviour somewhat consistent (i.e. not introducing ways it could fail now where it wouldn't before).
I'm happy to change to e.g. returning the error if you feel it's appropriate!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this check is done all over the place. My preference would be to do it here as well. But, I don't have a strong feeling about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about changing this logic to the following instead?
ns, err := b.namespacer.NamespaceByID(context.Background(), eConfig.NamespaceID)
if ns == nil || err != nil {
return nil, err
}
resp["namespace_path"] = ns.Path
...
It's a bit more concise, but the same logic, so feel free to ignore :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, changed!
vault/login_mfa.go
Outdated
@@ -1417,6 +1421,10 @@ func (b *MFABackend) mfaConfigToMap(mConfig *mfa.Config) (map[string]interface{} | |||
respData["id"] = mConfig.ID | |||
respData["name"] = mConfig.Name | |||
respData["namespace_id"] = mConfig.NamespaceID | |||
ns, err := b.namespacer.NamespaceByID(context.Background(), mConfig.NamespaceID) | |||
if ns != nil && err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment about error handling here
Looks good. Just a minor comment about error handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One minor nit, feel free to ignore.
@@ -1361,6 +1361,10 @@ func (b *LoginMFABackend) mfaLoginEnforcementConfigByNameAndNamespace(name, name | |||
func (b *LoginMFABackend) mfaLoginEnforcementConfigToMap(eConfig *mfa.MFAEnforcementConfig) (map[string]interface{}, error) { | |||
resp := make(map[string]interface{}) | |||
resp["name"] = eConfig.Name | |||
ns, err := b.namespacer.NamespaceByID(context.Background(), eConfig.NamespaceID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about changing this logic to the following instead?
ns, err := b.namespacer.NamespaceByID(context.Background(), eConfig.NamespaceID)
if ns == nil || err != nil {
return nil, err
}
resp["namespace_path"] = ns.Path
...
It's a bit more concise, but the same logic, so feel free to ignore :).
namespace_path is now returned: