Refactor common token fields and operations into a helper (#5953)

This commit is contained in:
Jeff Mitchell
2019-01-30 16:23:28 -05:00
committed by GitHub
parent aa9e55b874
commit 66c226c593
40 changed files with 1139 additions and 757 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/google/go-github/github"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/helper/policyutil"
"github.com/hashicorp/vault/helper/strutil"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
@@ -68,38 +69,35 @@ func (b *backend) pathLogin(ctx context.Context, req *logical.Request, data *fra
return nil, err
}
resp := &logical.Response{
Auth: &logical.Auth{
InternalData: map[string]interface{}{
"token": token,
},
Policies: verifyResp.Policies,
Metadata: map[string]string{
"username": *verifyResp.User.Login,
"org": *verifyResp.Org.Login,
},
DisplayName: *verifyResp.User.Login,
LeaseOptions: logical.LeaseOptions{
TTL: config.TTL,
MaxTTL: config.MaxTTL,
Renewable: true,
},
Alias: &logical.Alias{
Name: *verifyResp.User.Login,
},
auth := &logical.Auth{
InternalData: map[string]interface{}{
"token": token,
},
Metadata: map[string]string{
"username": *verifyResp.User.Login,
"org": *verifyResp.Org.Login,
},
DisplayName: *verifyResp.User.Login,
Alias: &logical.Alias{
Name: *verifyResp.User.Login,
},
}
config.PopulateTokenAuth(auth)
auth.Policies = append(auth.Policies, verifyResp.Policies...)
auth.Policies = strutil.RemoveDuplicates(auth.Policies, false)
for _, teamName := range verifyResp.TeamNames {
if teamName == "" {
continue
}
resp.Auth.GroupAliases = append(resp.Auth.GroupAliases, &logical.Alias{
auth.GroupAliases = append(auth.GroupAliases, &logical.Alias{
Name: teamName,
})
}
return resp, nil
return &logical.Response{
Auth: auth,
}, nil
}
func (b *backend) pathLoginRenew(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {