Separate accounts/host catalogs/host sets into their own packages (#311)
This commit is contained in:
1 parent
936c970635
commit
17ecb6f2ce
64 files changed
+2298
-2265
No files matched your search
@@ -4,10 +4,13 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/accounts"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/groups"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hosts"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostsets"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/roles"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/users"
|
||||
@@ -211,9 +214,10 @@ var inputStructs = []*structInfo{
|
||||
outFile: "authmethods/password_auth_method_attributes.gen.go",
|
||||
subtypeName: "PasswordAuthMethod",
|
||||
},
|
||||
// Accounts
|
||||
{
|
||||
inProto: &authmethods.Account{},
|
||||
outFile: "authmethods/account.gen.go",
|
||||
inProto: &accounts.Account{},
|
||||
outFile: "accounts/account.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
@@ -226,8 +230,8 @@ var inputStructs = []*structInfo{
|
||||
versionEnabled: true,
|
||||
},
|
||||
{
|
||||
inProto: &authmethods.PasswordAccountAttributes{},
|
||||
outFile: "authmethods/password_account_attributes.gen.go",
|
||||
inProto: &accounts.PasswordAccountAttributes{},
|
||||
outFile: "accounts/password_account_attributes.gen.go",
|
||||
subtypeName: "PasswordAccount",
|
||||
},
|
||||
// Auth Tokens
|
||||
@@ -244,8 +248,8 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
// Host related resources
|
||||
{
|
||||
inProto: &hosts.HostCatalog{},
|
||||
outFile: "hosts/host_catalog.gen.go",
|
||||
inProto: &hostcatalogs.HostCatalog{},
|
||||
outFile: "hostcatalogs/host_catalog.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
@@ -278,8 +282,8 @@ var inputStructs = []*structInfo{
|
||||
subtypeName: "StaticHost",
|
||||
},
|
||||
{
|
||||
inProto: &hosts.HostSet{},
|
||||
outFile: "hosts/host_set.gen.go",
|
||||
inProto: &hostsets.HostSet{},
|
||||
outFile: "hostsets/host_set.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
|
||||
@@ -59,7 +59,6 @@ func getArgsAndPaths(in []string, action string) (colArgs, resArgs []string, col
|
||||
}
|
||||
|
||||
type templateInput struct {
|
||||
ClientName string
|
||||
Name string
|
||||
Package string
|
||||
Fields []fieldInfo
|
||||
@@ -79,7 +78,6 @@ func fillTemplates() {
|
||||
for _, in := range inputStructs {
|
||||
outBuf := new(bytes.Buffer)
|
||||
input := templateInput{
|
||||
ClientName: in.generatedStructure.name + "s",
|
||||
Name: in.generatedStructure.name,
|
||||
Package: in.generatedStructure.pkg,
|
||||
Fields: in.generatedStructure.fields,
|
||||
@@ -200,7 +198,7 @@ func fillTemplates() {
|
||||
}
|
||||
|
||||
var listTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) List(ctx context.Context, {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }}opt... Option) ([]*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
func (c *Client) List(ctx context.Context, {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }}opt... Option) ([]*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into List request")
|
||||
}
|
||||
@@ -247,7 +245,7 @@ func (c *{{ .ClientName }}Client) List(ctx context.Context, {{ range .Collection
|
||||
`))
|
||||
|
||||
var readTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Read(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Read(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Read request")
|
||||
}
|
||||
@@ -289,7 +287,7 @@ func (c *{{ .ClientName }}Client) Read(ctx context.Context, {{ range .ResourceFu
|
||||
`))
|
||||
|
||||
var deleteTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (bool, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Delete(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (bool, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return false, nil, fmt.Errorf("empty {{ . }} value passed into Delete request")
|
||||
}
|
||||
@@ -334,7 +332,7 @@ func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .Resource
|
||||
`))
|
||||
|
||||
var createTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType string, {{ end }} {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
func (c *Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType string, {{ end }} {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Create request")
|
||||
}
|
||||
@@ -381,7 +379,7 @@ func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreat
|
||||
`))
|
||||
|
||||
var updateTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Update(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Update(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Update request")
|
||||
}{{ end }}
|
||||
@@ -456,7 +454,7 @@ var sliceSubTypeTemplate = template.Must(template.New("").Funcs(
|
||||
{{ $fullName := print $op $key }}
|
||||
{{ $actionName := kebabCase $fullName }}
|
||||
{{ $resPath := getPathWithAction $input.PathArgs $actionName }}
|
||||
func (c *{{ $input.ClientName }}Client) {{ $fullName }}(ctx context.Context, {{ range $input.ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, {{ $value }} []string, opt... Option) (*{{ $input.Name }}, *api.Error, error) { {{ range $input.ResourceFunctionArgs }}
|
||||
func (c *Client) {{ $fullName }}(ctx context.Context, {{ range $input.ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, {{ $value }} []string, opt... Option) (*{{ $input.Name }}, *api.Error, error) { {{ range $input.ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into {{ $fullName }} request")
|
||||
}{{ end }}
|
||||
@@ -547,12 +545,12 @@ type {{ .Name }} struct { {{ range .Fields }}
|
||||
`)))
|
||||
|
||||
var clientTemplate = template.Must(template.New("").Parse(`
|
||||
type {{ .ClientName }}Client struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func New{{ .Name }}sClient(c *api.Client) *{{ .ClientName }}Client {
|
||||
return &{{ .ClientName }}Client{ client: c }
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{ client: c }
|
||||
}
|
||||
`))
|
||||
|
||||
|
||||
Reference in new issue
Block a user