Migrate grants to more structured output (#194)
This commit is contained in:
1 parent
1a1d3058c9
commit
99653727bb
19 files changed
+757
-642
No files matched your search
@@ -11,31 +11,35 @@ type structInfo struct {
|
||||
structFields string
|
||||
parentName string
|
||||
detailName string
|
||||
outputOnly bool
|
||||
templateType templateType
|
||||
nameJsonMap map[string]string
|
||||
}
|
||||
|
||||
var inputStructs = []*structInfo{
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "Error",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/error.gen.go",
|
||||
outName: "Error",
|
||||
outPkg: "api",
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "Error",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/error.gen.go",
|
||||
outName: "Error",
|
||||
outPkg: "api",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "ErrorDetails",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/error_details.gen.go",
|
||||
outName: "ErrorDetails",
|
||||
outPkg: "api",
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "ErrorDetails",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/error_details.gen.go",
|
||||
outName: "ErrorDetails",
|
||||
outPkg: "api",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "FieldError",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/field_error.gen.go",
|
||||
outName: "FieldError",
|
||||
outPkg: "api",
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/error.pb.go",
|
||||
inName: "FieldError",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/field_error.gen.go",
|
||||
outName: "FieldError",
|
||||
outPkg: "api",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/hosts/host.pb.go",
|
||||
@@ -101,11 +105,28 @@ var inputStructs = []*structInfo{
|
||||
outPkg: "roles",
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/roles/role.pb.go",
|
||||
inName: "Principal",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/roles/principal.gen.go",
|
||||
outName: "Principal",
|
||||
outPkg: "roles",
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/roles/role.pb.go",
|
||||
inName: "Principal",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/roles/principal.gen.go",
|
||||
outName: "Principal",
|
||||
outPkg: "roles",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/roles/role.pb.go",
|
||||
inName: "Grant",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/roles/grant.gen.go",
|
||||
outName: "Grant",
|
||||
outPkg: "roles",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/roles/role.pb.go",
|
||||
inName: "GrantJson",
|
||||
outFile: os.Getenv("GEN_BASEPATH") + "/api/roles/grant_json.gen.go",
|
||||
outName: "GrantJson",
|
||||
outPkg: "roles",
|
||||
outputOnly: true,
|
||||
},
|
||||
{
|
||||
inFile: os.Getenv("GEN_BASEPATH") + "/internal/gen/controller/api/resources/hosts/host_catalog.pb.go",
|
||||
|
||||
@@ -78,7 +78,7 @@ func parsePBs() {
|
||||
}
|
||||
|
||||
// Add default fields if a base resource
|
||||
if inputStruct.templateType == templateTypeResource {
|
||||
if inputStruct.templateType == templateTypeResource && !inputStruct.outputOnly {
|
||||
st.Fields.List = append([]*ast.Field{{
|
||||
Names: []*ast.Ident{
|
||||
{
|
||||
|
||||
@@ -26,11 +26,13 @@ func writeStructTemplates() {
|
||||
Package string
|
||||
StructFields string
|
||||
NameJsonMap map[string]string
|
||||
OutputOnly bool
|
||||
}{
|
||||
Name: inputStruct.outName,
|
||||
Package: inputStruct.outPkg,
|
||||
StructFields: inputStruct.structFields,
|
||||
NameJsonMap: inputStruct.nameJsonMap,
|
||||
OutputOnly: inputStruct.outputOnly,
|
||||
})
|
||||
|
||||
case templateTypeDetail:
|
||||
@@ -45,7 +47,6 @@ func writeStructTemplates() {
|
||||
ParentName: inputStruct.parentName,
|
||||
DetailName: inputStruct.detailName,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
outFile, err := filepath.Abs(inputStruct.outFile)
|
||||
@@ -84,6 +85,7 @@ type {{ .Name }} struct {
|
||||
{{ .StructFields }}
|
||||
}
|
||||
|
||||
{{ if (not .OutputOnly) }}
|
||||
func (s *{{ .Name }}) SetDefault(key string) {
|
||||
lowerKey := strings.ToLower(key)
|
||||
validMap := {{ printf "%#v" .NameJsonMap }}
|
||||
@@ -116,6 +118,7 @@ func (s {{ .Name }}) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
{{ end }}
|
||||
`))
|
||||
|
||||
var detailTemplate = template.Must(template.New("").Parse(
|
||||
|
||||
Reference in new issue
Block a user