Migrate grants to more structured output (#194)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-07-16 22:18:27 -04:00
1 parent 1a1d3058c9
commit 99653727bb
19 files changed
+757 -642

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package roles
import (
"github.com/hashicorp/watchtower/api"
)
type Grant struct {
Client *api.Client `json:"-"`
// The original user-supplied string.
// Output only.
Raw string `json:"raw,omitempty"`
// The canonically formatted string.
// Output only.
Canonical string `json:"canonical,omitempty"`
// The JSON representation of the grant.
// Output only.
Json *GrantJson `json:"json,omitempty"`
}
+20
View File
@@ -0,0 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package roles
import (
"github.com/hashicorp/watchtower/api"
)
type GrantJson struct {
Client *api.Client `json:"-"`
// The ID, if set.
// Output only.
Id string `json:"id,omitempty"`
// The type, if set.
// Output only.
Type string `json:"type,omitempty"`
// The actions.
// Output only.
Actions []string `json:"actions,omitempty"`
}
-41
View File
@@ -2,20 +2,12 @@
package roles
import (
"encoding/json"
"strings"
"github.com/fatih/structs"
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/internal/strutil"
)
type Principal struct {
Client *api.Client `json:"-"`
defaultFields []string
// The ID of the principal.
// Output only.
Id string `json:"id,omitempty"`
@@ -26,36 +18,3 @@ type Principal struct {
// Output only.
ScopeId string `json:"scope_id,omitempty"`
}
func (s *Principal) SetDefault(key string) {
lowerKey := strings.ToLower(key)
validMap := map[string]string{"id": "id", "scopeid": "scope_id", "type": "type"}
for k, v := range validMap {
if k == lowerKey || v == lowerKey {
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, v)
return
}
}
}
func (s *Principal) UnsetDefault(key string) {
lowerKey := strings.ToLower(key)
validMap := map[string]string{"id": "id", "scopeid": "scope_id", "type": "type"}
for k, v := range validMap {
if k == lowerKey || v == lowerKey {
s.defaultFields = strutil.StrListDelete(s.defaultFields, v)
return
}
}
}
func (s Principal) MarshalJSON() ([]byte, error) {
m := structs.Map(s)
if m == nil {
m = make(map[string]interface{})
}
for _, k := range s.defaultFields {
m[k] = nil
}
return json.Marshal(m)
}
+5 -8
View File
@@ -50,18 +50,15 @@ type Role struct {
Principals []*Principal `json:"principals,omitempty"`
// The grants that this role provides for its principals.
// Output only.
Grants []string `json:"grants,omitempty"`
// The canonical version of the grants in the grants field with the same index.
GrantStrings []string `json:"grant_strings,omitempty"`
// The parsed grant information.
// Output only.
GrantsCanonical []string `json:"grants_canonical,omitempty"`
// The JSON version of the grants in the grants field with the same index.
// Output only.
GrantsJson []string `json:"grants_json,omitempty"`
Grants []*Grant `json:"grants,omitempty"`
}
func (s *Role) SetDefault(key string) {
lowerKey := strings.ToLower(key)
validMap := map[string]string{"createdtime": "created_time", "description": "description", "disabled": "disabled", "grants": "grants", "grantscanonical": "grants_canonical", "grantscopeid": "grant_scope_id", "grantsjson": "grants_json", "id": "id", "name": "name", "principalids": "principal_ids", "principals": "principals", "updatedtime": "updated_time", "version": "version"}
validMap := map[string]string{"createdtime": "created_time", "description": "description", "disabled": "disabled", "grants": "grants", "grantscopeid": "grant_scope_id", "grantstrings": "grant_strings", "id": "id", "name": "name", "principalids": "principal_ids", "principals": "principals", "updatedtime": "updated_time", "version": "version"}
for k, v := range validMap {
if k == lowerKey || v == lowerKey {
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, v)
@@ -72,7 +69,7 @@ func (s *Role) SetDefault(key string) {
func (s *Role) UnsetDefault(key string) {
lowerKey := strings.ToLower(key)
validMap := map[string]string{"createdtime": "created_time", "description": "description", "disabled": "disabled", "grants": "grants", "grantscanonical": "grants_canonical", "grantscopeid": "grant_scope_id", "grantsjson": "grants_json", "id": "id", "name": "name", "principalids": "principal_ids", "principals": "principals", "updatedtime": "updated_time", "version": "version"}
validMap := map[string]string{"createdtime": "created_time", "description": "description", "disabled": "disabled", "grants": "grants", "grantscopeid": "grant_scope_id", "grantstrings": "grant_strings", "id": "id", "name": "name", "principalids": "principal_ids", "principals": "principals", "updatedtime": "updated_time", "version": "version"}
for k, v := range validMap {
if k == lowerKey || v == lowerKey {
s.defaultFields = strutil.StrListDelete(s.defaultFields, v)