Use helper for existence check. Avoid panic by fetching default values for field data
This commit is contained in:
parent
1513ade19a
commit
2914ff7502
|
@ -60,12 +60,12 @@ func (b *backend) userExistenceCheck(req *logical.Request, data *framework.Field
|
||||||
return false, fmt.Errorf("missing username")
|
return false, fmt.Errorf("missing username")
|
||||||
}
|
}
|
||||||
|
|
||||||
entry, err := req.Storage.Get("user/" + strings.ToLower(username))
|
userEntry, err := b.user(req.Storage, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry != nil, nil
|
return userEntry != nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) user(s logical.Storage, n string) (*UserEntry, error) {
|
func (b *backend) user(s logical.Storage, n string) (*UserEntry, error) {
|
||||||
|
@ -150,11 +150,11 @@ func (b *backend) userCreateUpdate(req *logical.Request, d *framework.FieldData)
|
||||||
userEntry.Policies = policies
|
userEntry.Policies = policies
|
||||||
}
|
}
|
||||||
|
|
||||||
ttlStrRaw, ttlSet := d.GetOk("ttl")
|
_, ttlSet := d.GetOk("ttl")
|
||||||
maxTTLStrRaw, maxTTLSet := d.GetOk("max_ttl")
|
_, maxTTLSet := d.GetOk("max_ttl")
|
||||||
if ttlSet || maxTTLSet {
|
if ttlSet || maxTTLSet {
|
||||||
ttlStr := ttlStrRaw.(string)
|
ttlStr := d.Get("ttl").(string)
|
||||||
maxTTLStr := maxTTLStrRaw.(string)
|
maxTTLStr := d.Get("max_ttl").(string)
|
||||||
userEntry.TTL, userEntry.MaxTTL, err = b.SanitizeTTL(ttlStr, maxTTLStr)
|
userEntry.TTL, userEntry.MaxTTL, err = b.SanitizeTTL(ttlStr, maxTTLStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return logical.ErrorResponse(fmt.Sprintf("err: %s", err)), nil
|
return logical.ErrorResponse(fmt.Sprintf("err: %s", err)), nil
|
||||||
|
|
|
@ -102,6 +102,7 @@ necessary.
|
||||||
<dt>Description</dt>
|
<dt>Description</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Create a new user or update an existing user.
|
Create a new user or update an existing user.
|
||||||
|
This path honors the distinction between the `create` and `update` capabilities inside ACL policies.
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>Method</dt>
|
<dt>Method</dt>
|
||||||
|
|
Loading…
Reference in a new issue