Update attribute fields to be proto struct so generated api becomes map[string]any

This commit is contained in:
Todd authored and Timothy Messier committed 2023-05-31 12:18:22 +00:00
1 parent 4785f2388f
commit d1a5f3a2ff
10 files changed
+261 -205

No files matched your search

+14 -4
View File
@@ -1017,16 +1017,26 @@ var inputStructs = []*structInfo{
outFile: "sessionrecordings/target.gen.go",
},
{
inProto: &session_recordings.SshTargetAttributes{},
outFile: "sessionrecordings/ssh_target_attributes.gen.go",
inProto: &session_recordings.SshTargetAttributes{},
outFile: "sessionrecordings/ssh_target_attributes.gen.go",
subtypeName: "Ssh",
parentTypeName: "Target",
templates: []*template.Template{
mapstructureConversionTemplate,
},
},
{
inProto: &session_recordings.Host{},
outFile: "sessionrecordings/host.gen.go",
},
{
inProto: &session_recordings.StaticHostAttributes{},
outFile: "sessionrecordings/static_host_attributes.gen.go",
inProto: &session_recordings.StaticHostAttributes{},
outFile: "sessionrecordings/static_host_attributes.gen.go",
subtypeName: "Static",
parentTypeName: "Host",
templates: []*template.Template{
mapstructureConversionTemplate,
},
},
{
inProto: &session_recordings.HostCatalog{},
@@ -249,8 +249,8 @@ func printItemTable(item *sessionrecordings.SessionRecording, resp *api.Response
targetMap["Ingress Worker Filter"] = item.CreateTimeValues.Target.IngressWorkerFilter
}
if item.CreateTimeValues.Target.Attributes != nil {
if item.CreateTimeValues.Target.Attributes.DefaultPort != 0 {
targetMap["Default Port"] = item.CreateTimeValues.Target.Attributes.DefaultPort
if attr, err := item.CreateTimeValues.Target.GetSshTargetAttributes(); err == nil && attr != nil && attr.DefaultPort != 0 {
targetMap["Default Port"] = attr.DefaultPort
}
}
maxTargetLength := base.MaxAttributesLength(targetMap, nil, nil)
@@ -278,8 +278,8 @@ func printItemTable(item *sessionrecordings.SessionRecording, resp *api.Response
hostMap["External ID"] = item.CreateTimeValues.Host.ExternalId
}
if item.CreateTimeValues.Host.Attributes != nil {
if item.CreateTimeValues.Host.Attributes.Address != "" {
hostMap["Address"] = item.CreateTimeValues.Host.Attributes.Address
if attr, err := item.CreateTimeValues.Host.GetStaticHostAttributes(); err == nil && attr != nil && attr.Address != "" {
hostMap["Address"] = attr.Address
}
}
maxHostLength := base.MaxAttributesLength(hostMap, nil, nil)
+6 -22
View File
@@ -5642,7 +5642,7 @@
"title": "The type of the host. This will be either \"static\" or \"plugin\""
},
"attributes": {
"$ref": "#/definitions/controller.api.resources.sessionrecordings.v1.StaticHostAttributes",
"type": "object",
"description": "The attributes that are applicable for the specific Host."
},
"external_id": {
@@ -5783,26 +5783,6 @@
},
"description": "SessionRecording contains information about the recording of a Session."
},
"controller.api.resources.sessionrecordings.v1.SshTargetAttributes": {
"type": "object",
"properties": {
"default_port": {
"type": "integer",
"format": "int64",
"description": "The default SSH port that is used when connecting to the endpoint."
}
},
"title": "SshTargetAttributes contains attributes relevant to Targets of type \"ssh\""
},
"controller.api.resources.sessionrecordings.v1.StaticHostAttributes": {
"type": "object",
"properties": {
"address": {
"type": "string",
"title": "The address specified on a static host"
}
}
},
"controller.api.resources.sessionrecordings.v1.Target": {
"type": "object",
"properties": {
@@ -5844,8 +5824,12 @@
"type": "string",
"description": "Optional boolean expressions to filter the ingress workers that are allowed to satisfy this request."
},
"type": {
"type": "string",
"description": "The type of the Target."
},
"attributes": {
"$ref": "#/definitions/controller.api.resources.sessionrecordings.v1.SshTargetAttributes",
"type": "object",
"description": "The attributes that are applicable for the specific Target."
}
},
@@ -146,19 +146,14 @@ message Host {
string type = 5; // @gotags: class:"public"
oneof attrs {
// We are using the name attributes here because at the time of
// writing this there is only ssh target attributes for Session Recordings.
// When we add another target type for Session Recordings we will need to
// add a generic Struct with the field named "attributes", and then use the
// method used in other places that assign to these strongly typed
// attributes and then use a response interceptor to populate the
// struct field named "attributes" from the other oneof fields. This is
// going to be a breaking change (in terms of proto compatibility) but
// since this is only consumed in JSON format, that should be transparent
// to the end user.
// Here we use the google.protobuf.Struct so the generated structs in
// api/ are map[string]interface{}. Future work will include having
// well defined proto messages which contain exactly the fields expected
// in the attributes depending on the type of this resource, similar to
// how attributes are done when attributes is a top level field.
// The attributes that are applicable for the specific Host.
StaticHostAttributes attributes = 6; // @gotags: class:"public"
google.protobuf.Struct attributes = 6; // @gotags: class:"public"
}
// The external id of the Host, if any.
@@ -199,20 +194,18 @@ message Target {
// Optional boolean expressions to filter the ingress workers that are allowed to satisfy this request.
string ingress_worker_filter = 9 [json_name = "ingress_worker_filter"]; // @gotags: class:"public"
// The type of the Target.
string type = 10; // @gotags: `class:"public"`
oneof attrs {
// We are using the name attributes here because at the time of
// writing this there is only ssh target attributes for Session Recordings.
// When we add another target type for Session Recordings we will need to
// add a generic Struct with the field named "attributes", and then use the
// method used in other places that assign to these strongly typed
// attributes and then use a response interceptor to populate the
// struct field named "attributes" from the other oneof fields. This is
// going to be a breaking change (in terms of proto compatibility) but
// since this is only consumed in JSON format, that should be transparent
// to the end user.
// Here we use the google.protobuf.Struct so the generated structs in
// api/ are map[string]interface{}. Future work will include having
// well defined proto messages which contain exactly the fields expected
// in the attributes depending on the type of this resource, similar to
// how attributes are done when attributes is a top level field.
// The attributes that are applicable for the specific Target.
SshTargetAttributes attributes = 10;
google.protobuf.Struct attributes = 11; // @gotags: class:"public"
}
}