Add alias CLI CRUDL commands (#4353)

* Add alias CLI CRUDL commands
This commit is contained in:
Todd committed 2024-02-29 15:51:24 -08:00
1 parent eceb1fd40e
commit 78e10864c4
18 files changed
+1218 -58

No files matched your search

+12 -1
View File
@@ -28,6 +28,7 @@ type Alias struct {
Version uint32 `json:"version,omitempty"`
Value string `json:"value,omitempty"`
DestinationId string `json:"destination_id,omitempty"`
Type string `json:"type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
AuthorizedActions []string `json:"authorized_actions,omitempty"`
@@ -114,7 +115,7 @@ func (c *Client) ApiClient() *api.Client {
return c.client
}
func (c *Client) Create(ctx context.Context, scopeId string, opt ...Option) (*AliasCreateResult, error) {
func (c *Client) Create(ctx context.Context, resourceType string, alias string, scopeId string, opt ...Option) (*AliasCreateResult, error) {
if scopeId == "" {
return nil, fmt.Errorf("empty scopeId value passed into Create request")
}
@@ -124,6 +125,16 @@ func (c *Client) Create(ctx context.Context, scopeId string, opt ...Option) (*Al
if c.client == nil {
return nil, fmt.Errorf("nil client")
}
if resourceType == "" {
return nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.postMap["type"] = resourceType
}
if alias == "" {
return nil, fmt.Errorf("empty alias value passed into Create request")
} else {
opts.postMap["value"] = alias
}
opts.postMap["scope_id"] = scopeId
@@ -0,0 +1,9 @@
// Code generated by "make api"; DO NOT EDIT.
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package aliases
type AuthorizeSessionArguments struct {
HostId string `json:"host_id,omitempty"`
}
@@ -0,0 +1,40 @@
// Code generated by "make api"; DO NOT EDIT.
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package aliases
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type TargetAliasAttributes struct {
AuthorizeSessionArguments *AuthorizeSessionArguments `json:"authorize_session_arguments,omitempty"`
}
func AttributesMapToTargetAliasAttributes(in map[string]interface{}) (*TargetAliasAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out TargetAliasAttributes
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 *Alias) GetTargetAliasAttributes() (*TargetAliasAttributes, error) {
if pt.Type != "target" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but alias is of type %s", "target", pt.Type)
}
return AttributesMapToTargetAliasAttributes(pt.Attributes)
}