Decode to both the struct and a map and add access (#349)

This will allow for better TF integration.
pull/352/head
Jeff Mitchell 6 years ago committed by GitHub
parent c689af4306
commit b7524f8cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@
package accounts
import (
"bytes"
"context"
"errors"
"fmt"
@ -26,6 +27,17 @@ type Account struct {
Type string `json:"type,omitempty"`
AuthMethodId string `json:"auth_method_id,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Account) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Account) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,7 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package accounts
import "bytes"
type PasswordAccountAttributes struct {
LoginName string `json:"login_name,omitempty"`
Password string `json:"password,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n PasswordAccountAttributes) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n PasswordAccountAttributes) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package authmethods
import (
"bytes"
"context"
"errors"
"fmt"
@ -26,6 +27,17 @@ type AuthMethod struct {
Version uint32 `json:"version,omitempty"`
Type string `json:"type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n AuthMethod) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n AuthMethod) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,7 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package authmethods
import "bytes"
type PasswordAuthMethodAttributes struct {
MinLoginNameLength uint32 `json:"min_login_name_length,omitempty"`
MinPasswordLength uint32 `json:"min_password_length,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n PasswordAuthMethodAttributes) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n PasswordAuthMethodAttributes) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package authtokens
import (
"bytes"
"context"
"fmt"
"net/http"
@ -23,6 +24,17 @@ type AuthToken struct {
UpdatedTime time.Time `json:"updated_time,omitempty"`
ApproximateLastUsedTime time.Time `json:"approximate_last_used_time,omitempty"`
ExpirationTime time.Time `json:"expiration_time,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n AuthToken) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n AuthToken) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,9 +1,22 @@
// Code generated by "make api"; DO NOT EDIT.
package api
import "bytes"
type Error struct {
Status int32 `json:"status,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Details *ErrorDetails `json:"details,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Error) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Error) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -1,8 +1,21 @@
// Code generated by "make api"; DO NOT EDIT.
package api
import "bytes"
type ErrorDetails struct {
TraceId string `json:"TraceId,omitempty"`
RequestId string `json:"request_id,omitempty"`
RequestFields []*FieldError `json:"request_fields,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n ErrorDetails) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n ErrorDetails) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -1,7 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package api
import "bytes"
type FieldError struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n FieldError) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n FieldError) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package groups
import (
"bytes"
"context"
"errors"
"fmt"
@ -26,6 +27,17 @@ type Group struct {
Version uint32 `json:"version,omitempty"`
MemberIds []string `json:"member_ids,omitempty"`
Members []*Member `json:"members,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Group) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Group) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,7 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package groups
import "bytes"
type Member struct {
Id string `json:"id,omitempty"`
ScopeId string `json:"scope_id,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Member) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Member) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package hostcatalogs
import (
"bytes"
"context"
"errors"
"fmt"
@ -26,6 +27,17 @@ type HostCatalog struct {
Version uint32 `json:"version,omitempty"`
Type string `json:"type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n HostCatalog) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n HostCatalog) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -2,6 +2,7 @@
package hosts
import (
"bytes"
"context"
"errors"
"fmt"
@ -27,6 +28,17 @@ type Host struct {
Type string `json:"type,omitempty"`
HostSetIds []string `json:"host_set_ids,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Host) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Host) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,6 +1,19 @@
// Code generated by "make api"; DO NOT EDIT.
package hosts
import "bytes"
type StaticHostAttributes struct {
Address string `json:"address,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n StaticHostAttributes) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n StaticHostAttributes) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package hostsets
import (
"bytes"
"context"
"errors"
"fmt"
@ -27,6 +28,17 @@ type HostSet struct {
HostCatalogId string `json:"host_catalog_id,omitempty"`
HostIds []string `json:"host_ids,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n HostSet) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n HostSet) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -555,6 +555,17 @@ import (
type {{ .Name }} struct { {{ range .Fields }}
{{ .Name }} {{ .FieldType }} `, "`json:\"{{ .ProtoName }},omitempty\"`", `{{ end }}
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n {{ .Name }}) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n {{ .Name }}) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
`)))

@ -14,6 +14,7 @@ type Response struct {
resp *http.Response
Body *bytes.Buffer
Map map[string]interface{}
}
// HttpResponse returns the underlying HTTP response
@ -50,14 +51,21 @@ func (r *Response) Decode(inStruct interface{}) (*Error, error) {
return nil, fmt.Errorf("error reading response body: %w", err)
}
if r.Body.Len() != 0 {
dec := json.NewDecoder(bytes.NewReader(r.Body.Bytes()))
if r.Body.Len() > 0 {
reader := bytes.NewReader(r.Body.Bytes())
dec := json.NewDecoder(reader)
if r.resp.StatusCode >= 400 {
inStruct = apiErr
}
r.Map = make(map[string]interface{})
if err := dec.Decode(&r.Map); err != nil {
return nil, fmt.Errorf("error decoding response to map: %w; response was %s", err, r.Body.String())
}
if inStruct != nil {
if err := dec.Decode(inStruct); err != nil {
return nil, fmt.Errorf("error decoding response: %w; response was %s", err, r.Body.String())
reader.Seek(0, 0)
dec = json.NewDecoder(reader)
if err := dec.Decode(&inStruct); err != nil {
return nil, fmt.Errorf("error decoding response to struct: %w; response was %s", err, r.Body.String())
}
}
}

@ -1,8 +1,21 @@
// Code generated by "make api"; DO NOT EDIT.
package roles
import "bytes"
type Grant struct {
Raw string `json:"raw,omitempty"`
Canonical string `json:"canonical,omitempty"`
Json *GrantJson `json:"json,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Grant) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Grant) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -1,8 +1,21 @@
// Code generated by "make api"; DO NOT EDIT.
package roles
import "bytes"
type GrantJson struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Actions []string `json:"actions,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n GrantJson) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n GrantJson) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -1,8 +1,21 @@
// Code generated by "make api"; DO NOT EDIT.
package roles
import "bytes"
type Principal struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
ScopeId string `json:"scope_id,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Principal) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Principal) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package roles
import (
"bytes"
"context"
"errors"
"fmt"
@ -29,6 +30,17 @@ type Role struct {
Principals []*Principal `json:"principals,omitempty"`
GrantStrings []string `json:"grant_strings,omitempty"`
Grants []*Grant `json:"grants,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Role) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Role) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -2,6 +2,7 @@
package scopes
import (
"bytes"
"context"
"errors"
"fmt"
@ -24,6 +25,17 @@ type Scope struct {
UpdatedTime time.Time `json:"updated_time,omitempty"`
Version uint32 `json:"version,omitempty"`
Type string `json:"type,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Scope) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Scope) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -1,10 +1,23 @@
// Code generated by "make api"; DO NOT EDIT.
package scopes
import "bytes"
type ScopeInfo struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ParentScopeId string `json:"parent_scope_id,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n ScopeInfo) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n ScopeInfo) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -1,7 +1,20 @@
// Code generated by "make api"; DO NOT EDIT.
package targets
import "bytes"
type HostSet struct {
Id string `json:"id,omitempty"`
HostCatalogId string `json:"host_catalog_id,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n HostSet) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n HostSet) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}

@ -2,6 +2,7 @@
package targets
import (
"bytes"
"context"
"errors"
"fmt"
@ -28,6 +29,17 @@ type Target struct {
HostSetIds []string `json:"host_set_ids,omitempty"`
HostSets []*HostSet `json:"host_sets,omitempty"`
DefaultPort uint32 `json:"default_port,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n Target) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n Target) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

@ -2,6 +2,7 @@
package users
import (
"bytes"
"context"
"errors"
"fmt"
@ -24,6 +25,17 @@ type User struct {
CreatedTime time.Time `json:"created_time,omitempty"`
UpdatedTime time.Time `json:"updated_time,omitempty"`
Version uint32 `json:"version,omitempty"`
lastResponseBody *bytes.Buffer
lastResponseMap map[string]interface{}
}
func (n User) LastResponseBody() *bytes.Buffer {
return n.lastResponseBody
}
func (n User) LastResponseMap() map[string]interface{} {
return n.lastResponseMap
}
// Client is a client for this collection

Loading…
Cancel
Save