mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
Use SanitizeTTL in credential request path instead of config
This commit is contained in:
@@ -51,11 +51,31 @@ func (b *backend) pathConfigWrite(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ttlStr := data.Get("ttl").(string)
|
var ttl time.Duration
|
||||||
maxTTLStr := data.Get("max_ttl").(string)
|
var err error
|
||||||
ttl, maxTTL, err := b.SanitizeTTL(ttlStr, maxTTLStr)
|
ttlRaw, ok := data.GetOk("ttl")
|
||||||
|
if !ok {
|
||||||
|
ttl = b.System().DefaultLeaseTTL()
|
||||||
|
} else if len(ttlRaw.(string)) == 0 {
|
||||||
|
ttl = 0
|
||||||
|
} else {
|
||||||
|
ttl, err = time.ParseDuration(ttlRaw.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return logical.ErrorResponse(fmt.Sprintf("err: %s", err)), nil
|
return logical.ErrorResponse(fmt.Sprintf("Invalid 'ttl':%s", err)), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var maxTTL time.Duration
|
||||||
|
maxTTLRaw, ok := data.GetOk("max_ttl")
|
||||||
|
if !ok {
|
||||||
|
maxTTL = b.System().MaxLeaseTTL()
|
||||||
|
} else if len(maxTTLRaw.(string)) == 0 {
|
||||||
|
maxTTL = 0
|
||||||
|
} else {
|
||||||
|
maxTTL, err = time.ParseDuration(maxTTLRaw.(string))
|
||||||
|
if err != nil {
|
||||||
|
return logical.ErrorResponse(fmt.Sprintf("Invalid 'max_ttl':%s", err)), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry, err := logical.StorageEntryJSON("config", config{
|
entry, err := logical.StorageEntryJSON("config", config{
|
||||||
|
|||||||
@@ -124,6 +124,11 @@ func (b *backend) pathLogin(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ttl, _, err := b.SanitizeTTL(config.TTL.String(), config.MaxTTL.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Auth: &logical.Auth{
|
Auth: &logical.Auth{
|
||||||
Policies: policiesList,
|
Policies: policiesList,
|
||||||
@@ -133,9 +138,9 @@ func (b *backend) pathLogin(
|
|||||||
},
|
},
|
||||||
DisplayName: *user.Login,
|
DisplayName: *user.Login,
|
||||||
LeaseOptions: logical.LeaseOptions{
|
LeaseOptions: logical.LeaseOptions{
|
||||||
TTL: config.TTL,
|
TTL: ttl,
|
||||||
GracePeriod: config.TTL / 10,
|
GracePeriod: ttl / 10,
|
||||||
Renewable: config.TTL > 0,
|
Renewable: ttl > 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user