Merge BYOW GA branch to main (#2398)
* feat(workers): Add ability to read and reinitialize cert authority (#2312) * feat(workers): Return Release Version on worker list and read (#2377) * feat(cli): Read and reinitialize worker certificate authority (#2387)
This commit is contained in:
1 parent
cee5ff7599
commit
18dff62b7b
50 files changed
+2401
-462
No files matched your search
@@ -25,6 +25,14 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
ReadResponseType = "read"
|
||||
UpdateResponseType = "update"
|
||||
CreateResponseType = "create"
|
||||
ListResponseType = "list"
|
||||
DeleteResponseType = "delete"
|
||||
)
|
||||
|
||||
type sliceSubtypeInfo struct {
|
||||
SliceType string
|
||||
VarName string
|
||||
@@ -109,7 +117,7 @@ type structInfo struct {
|
||||
fieldOverrides []fieldInfo
|
||||
|
||||
// createResponseTypes controls for which structs response types are created
|
||||
createResponseTypes bool
|
||||
createResponseTypes []string
|
||||
|
||||
// fieldFilter is a set of field names that will not result in generated API
|
||||
// fields
|
||||
@@ -175,7 +183,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// User related resources
|
||||
@@ -203,7 +211,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "users",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// Group related resources
|
||||
@@ -231,7 +239,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "groups",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// Role related resources
|
||||
@@ -273,7 +281,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "roles",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// Auth Methods related resources
|
||||
@@ -332,7 +340,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "auth-methods",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// Accounts
|
||||
@@ -368,7 +376,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "accounts",
|
||||
parentTypeName: "auth-method",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
// Managed Groups
|
||||
{
|
||||
@@ -400,7 +408,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "managed-groups",
|
||||
parentTypeName: "auth-method",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
// Auth Tokens
|
||||
{
|
||||
@@ -413,7 +421,7 @@ var inputStructs = []*structInfo{
|
||||
listTemplate,
|
||||
},
|
||||
pluralResourceName: "auth-tokens",
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
// Credentials
|
||||
@@ -459,7 +467,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "credential-stores",
|
||||
parentTypeName: "scope",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
fieldOverrides: []fieldInfo{
|
||||
{
|
||||
@@ -501,7 +509,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "credential-libraries",
|
||||
parentTypeName: "credential-store",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
{
|
||||
inProto: &credentials.UsernamePasswordAttributes{},
|
||||
@@ -574,7 +582,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "credentials",
|
||||
parentTypeName: "credential-store",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
|
||||
// Host related resources
|
||||
@@ -625,7 +633,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
pluralResourceName: "host-catalogs",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
{
|
||||
@@ -642,7 +650,7 @@ var inputStructs = []*structInfo{
|
||||
pluralResourceName: "hosts",
|
||||
parentTypeName: "host-catalog",
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
{
|
||||
inProto: &hosts.StaticHostAttributes{},
|
||||
@@ -673,7 +681,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
},
|
||||
{
|
||||
inProto: &targets.HostSet{},
|
||||
@@ -807,7 +815,7 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
},
|
||||
versionEnabled: true,
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
},
|
||||
{
|
||||
@@ -835,10 +843,19 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
},
|
||||
pluralResourceName: "sessions",
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
fieldFilter: []string{"private_key"},
|
||||
recursiveListing: true,
|
||||
},
|
||||
{
|
||||
inProto: &workers.Certificate{},
|
||||
outFile: "workers/certificate.gen.go",
|
||||
},
|
||||
{
|
||||
inProto: &workers.CertificateAuthority{},
|
||||
outFile: "workers/certificate_authority.gen.go",
|
||||
createResponseTypes: []string{ReadResponseType},
|
||||
},
|
||||
{
|
||||
inProto: &workers.Worker{},
|
||||
outFile: "workers/worker.gen.go",
|
||||
@@ -890,7 +907,7 @@ var inputStructs = []*structInfo{
|
||||
VarName: "apiTags",
|
||||
},
|
||||
},
|
||||
createResponseTypes: true,
|
||||
createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType},
|
||||
recursiveListing: true,
|
||||
versionEnabled: true,
|
||||
},
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"github.com/iancoleman/strcase"
|
||||
)
|
||||
|
||||
@@ -46,7 +47,7 @@ type templateInput struct {
|
||||
SliceSubtypes map[string]sliceSubtypeInfo
|
||||
ExtraFields []fieldInfo
|
||||
VersionEnabled bool
|
||||
CreateResponseTypes bool
|
||||
CreateResponseTypes []string
|
||||
RecursiveListing bool
|
||||
}
|
||||
|
||||
@@ -570,7 +571,15 @@ func (c *Client) {{ $fullName }}(ctx context.Context, id string, version uint32,
|
||||
{{ end }}
|
||||
`))
|
||||
|
||||
var structTemplate = template.Must(template.New("").Parse(
|
||||
func hasResponseType(types []string, typ string) bool {
|
||||
return strutil.StrListContains(types, typ)
|
||||
}
|
||||
|
||||
var structTemplate = template.Must(template.New("").Funcs(
|
||||
template.FuncMap{
|
||||
"hasResponseType": hasResponseType,
|
||||
},
|
||||
).Parse(
|
||||
fmt.Sprint(`// Code generated by "make api"; DO NOT EDIT.
|
||||
package {{ .Package }}
|
||||
|
||||
@@ -587,14 +596,14 @@ import (
|
||||
|
||||
type {{ .Name }} struct { {{ range .Fields }}
|
||||
{{ .Name }} {{ .FieldType }} `, "`json:\"{{ .ProtoName }},omitempty\"`", `{{ end }}
|
||||
{{ if .CreateResponseTypes }}
|
||||
{{ if ( not ( eq ( len ( .CreateResponseTypes ) ) 0 ) )}}
|
||||
response *api.Response
|
||||
{{ else if ( eq .Name "Error" ) }}
|
||||
response *Response
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ if .CreateResponseTypes }}
|
||||
{{ if ( hasResponseType .CreateResponseTypes "read" ) }}
|
||||
type {{ .Name }}ReadResult struct {
|
||||
Item *{{ .Name }}
|
||||
response *api.Response
|
||||
@@ -607,10 +616,11 @@ func (n {{ .Name }}ReadResult) GetItem() *{{ .Name }} {
|
||||
func (n {{ .Name }}ReadResult) GetResponse() *api.Response {
|
||||
return n.response
|
||||
}
|
||||
{{ end }}
|
||||
{{ if ( hasResponseType .CreateResponseTypes "create" ) }} type {{ .Name }}CreateResult = {{ .Name }}ReadResult {{ end }}
|
||||
{{ if ( hasResponseType .CreateResponseTypes "update" ) }} type {{ .Name }}UpdateResult = {{ .Name }}ReadResult {{ end }}
|
||||
|
||||
type {{ .Name }}CreateResult = {{ .Name }}ReadResult
|
||||
type {{ .Name }}UpdateResult = {{ .Name }}ReadResult
|
||||
|
||||
{{ if ( hasResponseType .CreateResponseTypes "delete" ) }}
|
||||
type {{ .Name }}DeleteResult struct {
|
||||
response *api.Response
|
||||
}
|
||||
@@ -623,7 +633,8 @@ func (n {{ .Name }}DeleteResult) GetItem() interface{} {
|
||||
func (n {{ .Name }}DeleteResult) GetResponse() *api.Response {
|
||||
return n.response
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
{{ if ( hasResponseType .CreateResponseTypes "list" ) }}
|
||||
type {{ .Name }}ListResult struct {
|
||||
Items []*{{ .Name }}
|
||||
response *api.Response
|
||||
|
||||
Reference in new issue
Block a user