When using tokenutil, return []string not nil for empty slices (#7019)

This conveys type information instead of being a JSON null.
This commit is contained in:
Jeff Mitchell
2019-06-29 16:36:21 -04:00
committed by GitHub
parent d5e86f35d9
commit 46ce1bedd3
2 changed files with 9 additions and 1 deletions

View File

@@ -172,7 +172,7 @@ func (b *backend) pathUserRead(ctx context.Context, req *logical.Request, d *fra
data["max_ttl"] = int64(user.MaxTTL.Seconds())
}
if len(user.Policies) > 0 {
data["policies"] = user.Policies
data["policies"] = data["token_policies"]
}
if len(user.BoundCIDRs) > 0 {
data["bound_cidrs"] = user.BoundCIDRs

View File

@@ -212,6 +212,14 @@ func (t *TokenParams) PopulateTokenData(m map[string]interface{}) {
m["token_type"] = t.TokenType.String()
m["token_ttl"] = int64(t.TokenTTL.Seconds())
m["token_num_uses"] = t.TokenNumUses
if len(t.TokenPolicies) == 0 {
m["token_policies"] = []string{}
}
if len(t.TokenBoundCIDRs) == 0 {
m["token_bound_cidrs"] = []string{}
}
}
// PopulateTokenAuth populates Auth with parameters