Update attribute fields to be proto struct so generated api becomes map[string]any
This commit is contained in:
1 parent
4785f2388f
commit
d1a5f3a2ff
10 files changed
+261
-205
No files matched your search
@@ -5,11 +5,11 @@
|
||||
package sessionrecordings
|
||||
|
||||
type Host struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
HostCatalog *HostCatalog `json:"host_catalog,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Attributes *StaticHostAttributes `json:"attributes,omitempty"`
|
||||
ExternalId string `json:"external_id,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
HostCatalog *HostCatalog `json:"host_catalog,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
ExternalId string `json:"external_id,omitempty"`
|
||||
}
|
||||
@@ -4,6 +4,37 @@
|
||||
|
||||
package sessionrecordings
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -4,6 +4,37 @@
|
||||
|
||||
package sessionrecordings
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -9,14 +9,15 @@ import (
|
||||
)
|
||||
|
||||
type Target struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
SessionMaxSeconds uint32 `json:"session_max_seconds,omitempty"`
|
||||
SessionConnectionLimit int32 `json:"session_connection_limit,omitempty"`
|
||||
WorkerFilter string `json:"worker_filter,omitempty"`
|
||||
EgressWorkerFilter string `json:"egress_worker_filter,omitempty"`
|
||||
IngressWorkerFilter string `json:"ingress_worker_filter,omitempty"`
|
||||
Attributes *SshTargetAttributes `json:"attributes,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
SessionMaxSeconds uint32 `json:"session_max_seconds,omitempty"`
|
||||
SessionConnectionLimit int32 `json:"session_connection_limit,omitempty"`
|
||||
WorkerFilter string `json:"worker_filter,omitempty"`
|
||||
EgressWorkerFilter string `json:"egress_worker_filter,omitempty"`
|
||||
IngressWorkerFilter string `json:"ingress_worker_filter,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
Reference in new issue
Block a user