Update target credential library service, API, SDK, CLI (#1343)
This commit is contained in:
1 parent
83c65d0d4b
commit
86c9a90554
27 files changed
+1474
-1127
No files matched your search
+151
-47
@@ -22,6 +22,11 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type sliceSubtypeInfo struct {
|
||||
SliceType string
|
||||
VarName string
|
||||
}
|
||||
|
||||
type structureInfo struct {
|
||||
pkg string
|
||||
name string
|
||||
@@ -57,12 +62,13 @@ type structInfo struct {
|
||||
parentTypeName string
|
||||
|
||||
// mappings of names of resources and param names for sub slice types, e.g.
|
||||
// role principals and group members
|
||||
sliceSubtypes map[string]string
|
||||
// role principals and group members. If sliceSubtypeInfo is blank for a
|
||||
// key, the function is created but no required parameter is produced.
|
||||
sliceSubtypes map[string]sliceSubtypeInfo
|
||||
|
||||
// outputOnly indicates that we shouldn't create options for setting members
|
||||
// for mapping src field struct
|
||||
outputOnly bool
|
||||
// skipOptions indicates that we shouldn't create options for setting
|
||||
// members for mapping src field struct
|
||||
skipOptions bool
|
||||
|
||||
// versionEnabled indicates that we should build a Version handler in
|
||||
// update. Some structs are embedded in others and shouldn't have version
|
||||
@@ -72,6 +78,14 @@ type structInfo struct {
|
||||
// This is used for building the api path.
|
||||
pluralResourceName string
|
||||
|
||||
// packageOverride can be used when sourcing a package from a different
|
||||
// place as the target, e.g. for sourcing services structs
|
||||
packageOverride string
|
||||
|
||||
// nameOverride can be used to override the name coming from the proto,
|
||||
// useful to avoid collisions
|
||||
nameOverride string
|
||||
|
||||
// typeOnCreate indicates that create will be creating a concrete
|
||||
// implementation of an abstract type and thus a type field is necessary
|
||||
typeOnCreate bool
|
||||
@@ -99,30 +113,30 @@ type structInfo struct {
|
||||
|
||||
var inputStructs = []*structInfo{
|
||||
{
|
||||
inProto: &api.Error{},
|
||||
outFile: "error.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &api.Error{},
|
||||
outFile: "error.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &api.ErrorDetails{},
|
||||
outFile: "error_details.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &api.ErrorDetails{},
|
||||
outFile: "error_details.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &api.WrappedError{},
|
||||
outFile: "wrapped_error.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &api.WrappedError{},
|
||||
outFile: "wrapped_error.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &api.FieldError{},
|
||||
outFile: "field_error.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &api.FieldError{},
|
||||
outFile: "field_error.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
// Scope related resources
|
||||
{
|
||||
inProto: &scopes.ScopeInfo{},
|
||||
outFile: "scopes/scope_info.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &scopes.ScopeInfo{},
|
||||
outFile: "scopes/scope_info.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &scopes.Scope{},
|
||||
@@ -156,9 +170,9 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
// User related resources
|
||||
{
|
||||
inProto: &users.Account{},
|
||||
outFile: "users/account.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &users.Account{},
|
||||
outFile: "users/account.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &users.User{},
|
||||
@@ -171,8 +185,11 @@ var inputStructs = []*structInfo{
|
||||
deleteTemplate,
|
||||
listTemplate,
|
||||
},
|
||||
sliceSubtypes: map[string]string{
|
||||
"Accounts": "accountIds",
|
||||
sliceSubtypes: map[string]sliceSubtypeInfo{
|
||||
"Accounts": {
|
||||
SliceType: "[]string",
|
||||
VarName: "accountIds",
|
||||
},
|
||||
},
|
||||
pluralResourceName: "users",
|
||||
versionEnabled: true,
|
||||
@@ -181,9 +198,9 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
// Group related resources
|
||||
{
|
||||
inProto: &groups.Member{},
|
||||
outFile: "groups/member.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &groups.Member{},
|
||||
outFile: "groups/member.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &groups.Group{},
|
||||
@@ -196,8 +213,11 @@ var inputStructs = []*structInfo{
|
||||
deleteTemplate,
|
||||
listTemplate,
|
||||
},
|
||||
sliceSubtypes: map[string]string{
|
||||
"Members": "memberIds",
|
||||
sliceSubtypes: map[string]sliceSubtypeInfo{
|
||||
"Members": {
|
||||
SliceType: "[]string",
|
||||
VarName: "memberIds",
|
||||
},
|
||||
},
|
||||
pluralResourceName: "groups",
|
||||
versionEnabled: true,
|
||||
@@ -206,19 +226,19 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
// Role related resources
|
||||
{
|
||||
inProto: &roles.Grant{},
|
||||
outFile: "roles/grant.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &roles.Grant{},
|
||||
outFile: "roles/grant.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &roles.Principal{},
|
||||
outFile: "roles/principal.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &roles.Principal{},
|
||||
outFile: "roles/principal.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &roles.GrantJson{},
|
||||
outFile: "roles/grant_json.gen.go",
|
||||
outputOnly: true,
|
||||
inProto: &roles.GrantJson{},
|
||||
outFile: "roles/grant_json.gen.go",
|
||||
skipOptions: true,
|
||||
},
|
||||
{
|
||||
inProto: &roles.Role{},
|
||||
@@ -231,9 +251,15 @@ var inputStructs = []*structInfo{
|
||||
deleteTemplate,
|
||||
listTemplate,
|
||||
},
|
||||
sliceSubtypes: map[string]string{
|
||||
"Principals": "principalIds",
|
||||
"Grants": "grantStrings",
|
||||
sliceSubtypes: map[string]sliceSubtypeInfo{
|
||||
"Principals": {
|
||||
SliceType: "[]string",
|
||||
VarName: "principalIds",
|
||||
},
|
||||
"Grants": {
|
||||
SliceType: "[]string",
|
||||
VarName: "grantStrings",
|
||||
},
|
||||
},
|
||||
pluralResourceName: "roles",
|
||||
versionEnabled: true,
|
||||
@@ -403,6 +429,67 @@ var inputStructs = []*structInfo{
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
},
|
||||
// Credentials
|
||||
{
|
||||
inProto: &credentialstores.VaultCredentialStoreAttributes{},
|
||||
outFile: "credentialstores/vault_credential_store_attributes.gen.go",
|
||||
subtypeName: "VaultCredentialStore",
|
||||
},
|
||||
{
|
||||
inProto: &credentialstores.CredentialStore{},
|
||||
outFile: "credentialstores/credential_store.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
readTemplate,
|
||||
updateTemplate,
|
||||
deleteTemplate,
|
||||
listTemplate,
|
||||
},
|
||||
pluralResourceName: "credential-stores",
|
||||
parentTypeName: "scope",
|
||||
typeOnCreate: true,
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
recursiveListing: true,
|
||||
fieldOverrides: []fieldInfo{
|
||||
{
|
||||
Name: "Address",
|
||||
SkipDefault: true,
|
||||
},
|
||||
{
|
||||
Name: "Token",
|
||||
SkipDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
inProto: &credentiallibraries.VaultCredentialLibraryAttributes{},
|
||||
outFile: "credentiallibraries/vault_credential_library_attributes.gen.go",
|
||||
subtypeName: "VaultCredentialLibrary",
|
||||
fieldOverrides: []fieldInfo{
|
||||
{
|
||||
Name: "Path",
|
||||
SkipDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
inProto: &credentiallibraries.CredentialLibrary{},
|
||||
outFile: "credentiallibraries/credential_library.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
readTemplate,
|
||||
updateTemplate,
|
||||
deleteTemplate,
|
||||
listTemplate,
|
||||
},
|
||||
pluralResourceName: "credential-libraries",
|
||||
parentTypeName: "credential-store",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
},
|
||||
// Host related resources
|
||||
{
|
||||
inProto: &hostcatalogs.HostCatalog{},
|
||||
@@ -455,8 +542,11 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "host-sets",
|
||||
parentTypeName: "host-catalog",
|
||||
sliceSubtypes: map[string]string{
|
||||
"Hosts": "hostIds",
|
||||
sliceSubtypes: map[string]sliceSubtypeInfo{
|
||||
"Hosts": {
|
||||
SliceType: "[]string",
|
||||
VarName: "hostIds",
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
@@ -472,6 +562,12 @@ var inputStructs = []*structInfo{
|
||||
{
|
||||
inProto: &targets.SessionCredential{},
|
||||
outFile: "targets/session_credential.gen.go",
|
||||
fieldOverrides: []fieldInfo{
|
||||
{
|
||||
Name: "Secret",
|
||||
FieldType: "json.RawMessage",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
inProto: &targets.SessionAuthorization{},
|
||||
@@ -500,9 +596,12 @@ var inputStructs = []*structInfo{
|
||||
listTemplate,
|
||||
},
|
||||
pluralResourceName: "targets",
|
||||
sliceSubtypes: map[string]string{
|
||||
"HostSets": "hostSetIds",
|
||||
"CredentialLibraries": "credentialLibraryIds",
|
||||
sliceSubtypes: map[string]sliceSubtypeInfo{
|
||||
"HostSets": {
|
||||
SliceType: "[]string",
|
||||
VarName: "hostSetIds",
|
||||
},
|
||||
"CredentialLibraries": {},
|
||||
},
|
||||
extraOptions: []fieldInfo{
|
||||
{
|
||||
@@ -523,6 +622,11 @@ var inputStructs = []*structInfo{
|
||||
FieldType: "string",
|
||||
SkipDefault: true,
|
||||
},
|
||||
{
|
||||
Name: "ApplicationCredentialLibraryIds",
|
||||
ProtoName: "application_credential_library_ids",
|
||||
FieldType: "[]string",
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
typeOnCreate: true,
|
||||
|
||||
@@ -43,7 +43,7 @@ type templateInput struct {
|
||||
CollectionPath string
|
||||
ResourcePath string
|
||||
ParentTypeName string
|
||||
SliceSubtypes map[string]string
|
||||
SliceSubtypes map[string]sliceSubtypeInfo
|
||||
ExtraOptions []fieldInfo
|
||||
VersionEnabled bool
|
||||
TypeOnCreate bool
|
||||
@@ -69,11 +69,28 @@ func fillTemplates() {
|
||||
CreateResponseTypes: in.createResponseTypes,
|
||||
RecursiveListing: in.recursiveListing,
|
||||
}
|
||||
if in.packageOverride != "" {
|
||||
input.Package = in.packageOverride
|
||||
}
|
||||
if in.nameOverride != "" {
|
||||
input.Name = in.nameOverride
|
||||
}
|
||||
|
||||
if len(in.pluralResourceName) > 0 {
|
||||
input.CollectionFunctionArg, input.CollectionPath, input.ResourcePath = getArgsAndPaths(in.pluralResourceName, in.parentTypeName, "")
|
||||
}
|
||||
|
||||
for _, override := range in.fieldOverrides {
|
||||
for i, field := range in.generatedStructure.fields {
|
||||
if field.Name == override.Name {
|
||||
if override.FieldType != "" {
|
||||
field.FieldType = override.FieldType
|
||||
}
|
||||
in.generatedStructure.fields[i] = field
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := structTemplate.Execute(outBuf, input); err != nil {
|
||||
fmt.Printf("error executing struct template for resource %s: %v\n", in.generatedStructure.name, err)
|
||||
os.Exit(1)
|
||||
@@ -95,7 +112,7 @@ func fillTemplates() {
|
||||
// collate them all here for writing later. The map argument of the
|
||||
// package map is to prevent duplicates since we may have multiple e.g.
|
||||
// Name or Description fields.
|
||||
if !in.outputOnly {
|
||||
if !in.skipOptions {
|
||||
pkgOptionMap := map[string]fieldInfo{}
|
||||
for _, val := range input.Fields {
|
||||
if val.GenerateSdkOption {
|
||||
@@ -466,13 +483,17 @@ var sliceSubtypeTemplate = template.Must(template.New("").Funcs(
|
||||
{{ $fullName := print $op $key }}
|
||||
{{ $actionName := kebabCase $fullName }}
|
||||
{{ $resPath := getPathWithAction $input.PluralResourceName $input.ParentTypeName $actionName }}
|
||||
func (c *Client) {{ $fullName }}(ctx context.Context, id string, version uint32, {{ $value }} []string, opt... Option) (*{{ $input.Name }}UpdateResult, error) {
|
||||
func (c *Client) {{ $fullName }}(ctx context.Context, id string, version uint32, {{ if ( not ( eq $value.VarName "" ) ) }}{{ $value.VarName }} {{ $value.SliceType }},{{ end }} opt... Option) (*{{ $input.Name }}UpdateResult, error) {
|
||||
if id == "" {
|
||||
return nil, fmt.Errorf("empty id value passed into {{ $fullName }} request")
|
||||
}
|
||||
{{ if ( not ( eq $op "Set" ) ) }}if len({{ $value }}) == 0 {
|
||||
return nil, errors.New("empty {{ $value }} passed into {{ $fullName }} request")
|
||||
}{{ end }}
|
||||
{{ if ( not ( eq $op "Set" ) ) }}
|
||||
{{ if ( not ( eq $value.VarName "" ) ) }}
|
||||
if len({{ $value.VarName }}) == 0 {
|
||||
return nil, errors.New("empty {{ $value.VarName }} passed into {{ $fullName }} request")
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
if c.client == nil {
|
||||
return nil, errors.New("nil client")
|
||||
}
|
||||
@@ -501,7 +522,9 @@ func (c *Client) {{ $fullName }}(ctx context.Context, id string, version uint32,
|
||||
}
|
||||
{{ end }}
|
||||
opts.postMap["version"] = version
|
||||
opts.postMap["{{ snakeCase $value }}"] = {{ $value }}
|
||||
{{ if ( not ( eq $value.VarName "" ) ) }}
|
||||
opts.postMap["{{ snakeCase $value.VarName }}"] = {{ $value.VarName }}
|
||||
{{ end }}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", {{ $resPath }}, opts.postMap, apiOpts...)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user