Add methods to get attributes more easily in Go API (#2299)

* Add methods to get attributes more easily in Go API

* Add type check
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2022-07-28 18:17:30 -04:00
1 parent ab3fe75537
commit a67085f663
14 files changed
+480 -24

No files matched your search

@@ -1,6 +1,12 @@
// Code generated by "make api"; DO NOT EDIT.
package accounts
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type OidcAccountAttributes struct {
Issuer string `json:"issuer,omitempty"`
Subject string `json:"subject,omitempty"`
@@ -9,3 +15,28 @@ type OidcAccountAttributes struct {
TokenClaims map[string]interface{} `json:"token_claims,omitempty"`
UserinfoClaims map[string]interface{} `json:"userinfo_claims,omitempty"`
}
func AttributesMapToOidcAccountAttributes(in map[string]interface{}) (*OidcAccountAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out OidcAccountAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Account) GetOidcAccountAttributes() (*OidcAccountAttributes, error) {
if pt.Type != "oidc" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but account is of type %s", "oidc", pt.Type)
}
return AttributesMapToOidcAccountAttributes(pt.Attributes)
}
@@ -1,7 +1,38 @@
// Code generated by "make api"; DO NOT EDIT.
package accounts
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type PasswordAccountAttributes struct {
LoginName string `json:"login_name,omitempty"`
Password string `json:"password,omitempty"`
}
func AttributesMapToPasswordAccountAttributes(in map[string]interface{}) (*PasswordAccountAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out PasswordAccountAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Account) GetPasswordAccountAttributes() (*PasswordAccountAttributes, error) {
if pt.Type != "password" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but account is of type %s", "password", pt.Type)
}
return AttributesMapToPasswordAccountAttributes(pt.Attributes)
}
@@ -1,6 +1,12 @@
// Code generated by "make api"; DO NOT EDIT.
package authmethods
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type OidcAuthMethodAttributes struct {
State string `json:"state,omitempty"`
Issuer string `json:"issuer,omitempty"`
@@ -18,3 +24,28 @@ type OidcAuthMethodAttributes struct {
DisableDiscoveredConfigValidation bool `json:"disable_discovered_config_validation,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
}
func AttributesMapToOidcAuthMethodAttributes(in map[string]interface{}) (*OidcAuthMethodAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out OidcAuthMethodAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *AuthMethod) GetOidcAuthMethodAttributes() (*OidcAuthMethodAttributes, error) {
if pt.Type != "oidc" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but auth-method is of type %s", "oidc", pt.Type)
}
return AttributesMapToOidcAuthMethodAttributes(pt.Attributes)
}
@@ -1,7 +1,38 @@
// Code generated by "make api"; DO NOT EDIT.
package authmethods
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type PasswordAuthMethodAttributes struct {
MinLoginNameLength uint32 `json:"min_login_name_length,omitempty"`
MinPasswordLength uint32 `json:"min_password_length,omitempty"`
}
func AttributesMapToPasswordAuthMethodAttributes(in map[string]interface{}) (*PasswordAuthMethodAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out PasswordAuthMethodAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *AuthMethod) GetPasswordAuthMethodAttributes() (*PasswordAuthMethodAttributes, error) {
if pt.Type != "password" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but auth-method is of type %s", "password", pt.Type)
}
return AttributesMapToPasswordAuthMethodAttributes(pt.Attributes)
}
@@ -1,8 +1,39 @@
// Code generated by "make api"; DO NOT EDIT.
package credentiallibraries
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type VaultCredentialLibraryAttributes struct {
Path string `json:"path,omitempty"`
HttpMethod string `json:"http_method,omitempty"`
HttpRequestBody string `json:"http_request_body,omitempty"`
}
func AttributesMapToVaultCredentialLibraryAttributes(in map[string]interface{}) (*VaultCredentialLibraryAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out VaultCredentialLibraryAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *CredentialLibrary) GetVaultCredentialLibraryAttributes() (*VaultCredentialLibraryAttributes, error) {
if pt.Type != "vault" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but credential-library is of type %s", "vault", pt.Type)
}
return AttributesMapToVaultCredentialLibraryAttributes(pt.Attributes)
}
@@ -1,8 +1,39 @@
// Code generated by "make api"; DO NOT EDIT.
package credentials
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type SshPrivateKeyAttributes struct {
Username string `json:"username,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
PrivateKeyHmac string `json:"private_key_hmac,omitempty"`
}
func AttributesMapToSshPrivateKeyAttributes(in map[string]interface{}) (*SshPrivateKeyAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out SshPrivateKeyAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Credential) GetSshPrivateKeyAttributes() (*SshPrivateKeyAttributes, error) {
if pt.Type != "sshprivatekey" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but credential is of type %s", "sshprivatekey", pt.Type)
}
return AttributesMapToSshPrivateKeyAttributes(pt.Attributes)
}
@@ -1,8 +1,39 @@
// Code generated by "make api"; DO NOT EDIT.
package credentials
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type UsernamePasswordAttributes struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
PasswordHmac string `json:"password_hmac,omitempty"`
}
func AttributesMapToUsernamePasswordAttributes(in map[string]interface{}) (*UsernamePasswordAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out UsernamePasswordAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Credential) GetUsernamePasswordAttributes() (*UsernamePasswordAttributes, error) {
if pt.Type != "usernamepassword" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but credential is of type %s", "usernamepassword", pt.Type)
}
return AttributesMapToUsernamePasswordAttributes(pt.Attributes)
}
@@ -1,6 +1,12 @@
// Code generated by "make api"; DO NOT EDIT.
package credentialstores
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type VaultCredentialStoreAttributes struct {
Address string `json:"address,omitempty"`
Namespace string `json:"namespace,omitempty"`
@@ -14,3 +20,28 @@ type VaultCredentialStoreAttributes struct {
ClientCertificateKeyHmac string `json:"client_certificate_key_hmac,omitempty"`
WorkerFilter string `json:"worker_filter,omitempty"`
}
func AttributesMapToVaultCredentialStoreAttributes(in map[string]interface{}) (*VaultCredentialStoreAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out VaultCredentialStoreAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *CredentialStore) GetVaultCredentialStoreAttributes() (*VaultCredentialStoreAttributes, error) {
if pt.Type != "vault" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but credential-store is of type %s", "vault", pt.Type)
}
return AttributesMapToVaultCredentialStoreAttributes(pt.Attributes)
}
+31
View File
@@ -1,6 +1,37 @@
// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type StaticHostAttributes struct {
Address string `json:"address,omitempty"`
}
func AttributesMapToStaticHostAttributes(in map[string]interface{}) (*StaticHostAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out StaticHostAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Host) GetStaticHostAttributes() (*StaticHostAttributes, error) {
if pt.Type != "static" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but host is of type %s", "static", pt.Type)
}
return AttributesMapToStaticHostAttributes(pt.Attributes)
}
@@ -1,6 +1,37 @@
// Code generated by "make api"; DO NOT EDIT.
package managedgroups
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type OidcManagedGroupAttributes struct {
Filter string `json:"filter,omitempty"`
}
func AttributesMapToOidcManagedGroupAttributes(in map[string]interface{}) (*OidcManagedGroupAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out OidcManagedGroupAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *ManagedGroup) GetOidcManagedGroupAttributes() (*OidcManagedGroupAttributes, error) {
if pt.Type != "oidc" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but managed-group is of type %s", "oidc", pt.Type)
}
return AttributesMapToOidcManagedGroupAttributes(pt.Attributes)
}
+31
View File
@@ -1,6 +1,37 @@
// Code generated by "make api"; DO NOT EDIT.
package targets
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type SshTargetAttributes struct {
DefaultPort uint32 `json:"default_port,omitempty"`
}
func AttributesMapToSshTargetAttributes(in map[string]interface{}) (*SshTargetAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out SshTargetAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Target) GetSshTargetAttributes() (*SshTargetAttributes, error) {
if pt.Type != "ssh" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but target is of type %s", "ssh", pt.Type)
}
return AttributesMapToSshTargetAttributes(pt.Attributes)
}
+31
View File
@@ -1,6 +1,37 @@
// Code generated by "make api"; DO NOT EDIT.
package targets
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type TcpTargetAttributes struct {
DefaultPort uint32 `json:"default_port,omitempty"`
}
func AttributesMapToTcpTargetAttributes(in map[string]interface{}) (*TcpTargetAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out TcpTargetAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *Target) GetTcpTargetAttributes() (*TcpTargetAttributes, error) {
if pt.Type != "tcp" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but target is of type %s", "tcp", pt.Type)
}
return AttributesMapToTcpTargetAttributes(pt.Attributes)
}