From 67b1f12889e3aecbcac18fe2f57a04d245654554 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:08:02 +0000 Subject: [PATCH 1/4] v3: Add more listable on Name or(not and) ID Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- v3/generator/operations/operations.go | 13 ++- v3/operations.go | 127 +++++++++++++++++++++++--- 2 files changed, 124 insertions(+), 16 deletions(-) diff --git a/v3/generator/operations/operations.go b/v3/generator/operations/operations.go index 7edbb337b..d87e8ad21 100644 --- a/v3/generator/operations/operations.go +++ b/v3/generator/operations/operations.go @@ -271,7 +271,7 @@ const findableTemplate = ` // Find{{ .TypeName }} attempts to find an {{ .TypeName }} by name or ID. func (l {{ .ListTypeName }}) Find{{ .TypeName }}(nameOrID string) ({{ .TypeName }}, error) { for i, elem := range l.{{ .ListFieldName }} { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if {{ .Condition }} { return l.{{ .ListFieldName }}[i], nil } } @@ -284,6 +284,7 @@ type Findable struct { TypeName string ListTypeName string ListFieldName string + Condition string } // renderFindable renders a find method on listable resource. @@ -343,16 +344,24 @@ func renderFindable(funcName string, s *base.SchemaProxy) ([]byte, error) { } _, hasName := item.Properties.Get("name") _, hasID := item.Properties.Get("id") - if hasName && hasID { + if hasName || hasID { output := bytes.NewBuffer([]byte{}) t, err := template.New("Findable").Parse(findableTemplate) if err != nil { return nil, err } + condition := "string(elem.Name) == nameOrID || elem.ID.String() == nameOrID" + if !hasID { + condition = "string(elem.Name) == nameOrID" + } + if !hasName { + condition = "elem.ID.String() == nameOrID" + } if err := t.Execute(output, Findable{ ListTypeName: funcName + "Response", ListFieldName: helpers.ToCamel(propName), TypeName: typeName, + Condition: condition, }); err != nil { return nil, err } diff --git a/v3/operations.go b/v3/operations.go index df0383c0e..9bba6cb65 100755 --- a/v3/operations.go +++ b/v3/operations.go @@ -19,7 +19,7 @@ type ListAntiAffinityGroupsResponse struct { // FindAntiAffinityGroup attempts to find an AntiAffinityGroup by name or ID. func (l ListAntiAffinityGroupsResponse) FindAntiAffinityGroup(nameOrID string) (AntiAffinityGroup, error) { for i, elem := range l.AntiAffinityGroups { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.AntiAffinityGroups[i], nil } } @@ -217,6 +217,17 @@ type ListAPIKeysResponse struct { APIKeys []IAMAPIKey `json:"api-keys,omitempty"` } +// FindIAMAPIKey attempts to find an IAMAPIKey by name or ID. +func (l ListAPIKeysResponse) FindIAMAPIKey(nameOrID string) (IAMAPIKey, error) { + for i, elem := range l.APIKeys { + if string(elem.Name) == nameOrID { + return l.APIKeys[i], nil + } + } + + return IAMAPIKey{}, fmt.Errorf("%q not found in ListAPIKeysResponse: %w", nameOrID, ErrNotFound) +} + // List API keys func (c Client) ListAPIKeys(ctx context.Context) (*ListAPIKeysResponse, error) { path := "/api-key" @@ -410,7 +421,7 @@ type ListBlockStorageVolumesResponse struct { // FindBlockStorageVolume attempts to find an BlockStorageVolume by name or ID. func (l ListBlockStorageVolumesResponse) FindBlockStorageVolume(nameOrID string) (BlockStorageVolume, error) { for i, elem := range l.BlockStorageVolumes { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.BlockStorageVolumes[i], nil } } @@ -545,7 +556,7 @@ type ListBlockStorageSnapshotsResponse struct { // FindBlockStorageSnapshot attempts to find an BlockStorageSnapshot by name or ID. func (l ListBlockStorageSnapshotsResponse) FindBlockStorageSnapshot(nameOrID string) (BlockStorageSnapshot, error) { for i, elem := range l.BlockStorageSnapshots { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.BlockStorageSnapshots[i], nil } } @@ -5691,6 +5702,17 @@ type ListDBAASServicesResponse struct { DBAASServices []DBAASServiceCommon `json:"dbaas-services,omitempty"` } +// FindDBAASServiceCommon attempts to find an DBAASServiceCommon by name or ID. +func (l ListDBAASServicesResponse) FindDBAASServiceCommon(nameOrID string) (DBAASServiceCommon, error) { + for i, elem := range l.DBAASServices { + if string(elem.Name) == nameOrID { + return l.DBAASServices[i], nil + } + } + + return DBAASServiceCommon{}, fmt.Errorf("%q not found in ListDBAASServicesResponse: %w", nameOrID, ErrNotFound) +} + // List DBaaS services func (c Client) ListDBAASServices(ctx context.Context) (*ListDBAASServicesResponse, error) { path := "/dbaas-service" @@ -5865,6 +5887,17 @@ type ListDBAASServiceTypesResponse struct { DBAASServiceTypes []DBAASServiceType `json:"dbaas-service-types,omitempty"` } +// FindDBAASServiceType attempts to find an DBAASServiceType by name or ID. +func (l ListDBAASServiceTypesResponse) FindDBAASServiceType(nameOrID string) (DBAASServiceType, error) { + for i, elem := range l.DBAASServiceTypes { + if string(elem.Name) == nameOrID { + return l.DBAASServiceTypes[i], nil + } + } + + return DBAASServiceType{}, fmt.Errorf("%q not found in ListDBAASServiceTypesResponse: %w", nameOrID, ErrNotFound) +} + // List available service types for DBaaS func (c Client) ListDBAASServiceTypes(ctx context.Context) (*ListDBAASServiceTypesResponse, error) { path := "/dbaas-service-type" @@ -6522,7 +6555,7 @@ type ListDeployTargetsResponse struct { // FindDeployTarget attempts to find an DeployTarget by name or ID. func (l ListDeployTargetsResponse) FindDeployTarget(nameOrID string) (DeployTarget, error) { for i, elem := range l.DeployTargets { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.DeployTargets[i], nil } } @@ -6620,6 +6653,17 @@ type ListDNSDomainsResponse struct { DNSDomains []DNSDomain `json:"dns-domains,omitempty"` } +// FindDNSDomain attempts to find an DNSDomain by name or ID. +func (l ListDNSDomainsResponse) FindDNSDomain(nameOrID string) (DNSDomain, error) { + for i, elem := range l.DNSDomains { + if elem.ID.String() == nameOrID { + return l.DNSDomains[i], nil + } + } + + return DNSDomain{}, fmt.Errorf("%q not found in ListDNSDomainsResponse: %w", nameOrID, ErrNotFound) +} + // List DNS domains func (c Client) ListDNSDomains(ctx context.Context) (*ListDNSDomainsResponse, error) { path := "/dns-domain" @@ -6726,7 +6770,7 @@ type ListDNSDomainRecordsResponse struct { // FindDNSDomainRecord attempts to find an DNSDomainRecord by name or ID. func (l ListDNSDomainRecordsResponse) FindDNSDomainRecord(nameOrID string) (DNSDomainRecord, error) { for i, elem := range l.DNSDomainRecords { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.DNSDomainRecords[i], nil } } @@ -7144,6 +7188,17 @@ type ListElasticIPSResponse struct { ElasticIPS []ElasticIP `json:"elastic-ips,omitempty"` } +// FindElasticIP attempts to find an ElasticIP by name or ID. +func (l ListElasticIPSResponse) FindElasticIP(nameOrID string) (ElasticIP, error) { + for i, elem := range l.ElasticIPS { + if elem.ID.String() == nameOrID { + return l.ElasticIPS[i], nil + } + } + + return ElasticIP{}, fmt.Errorf("%q not found in ListElasticIPSResponse: %w", nameOrID, ErrNotFound) +} + // List Elastic IPs func (c Client) ListElasticIPS(ctx context.Context) (*ListElasticIPSResponse, error) { path := "/elastic-ip" @@ -7724,7 +7779,7 @@ type ListIAMRolesResponse struct { // FindIAMRole attempts to find an IAMRole by name or ID. func (l ListIAMRolesResponse) FindIAMRole(nameOrID string) (IAMRole, error) { for i, elem := range l.IAMRoles { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.IAMRoles[i], nil } } @@ -8081,7 +8136,7 @@ type ListInstancesResponse struct { // FindListInstancesResponseInstances attempts to find an ListInstancesResponseInstances by name or ID. func (l ListInstancesResponse) FindListInstancesResponseInstances(nameOrID string) (ListInstancesResponseInstances, error) { for i, elem := range l.Instances { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.Instances[i], nil } } @@ -8252,7 +8307,7 @@ type ListInstancePoolsResponse struct { // FindInstancePool attempts to find an InstancePool by name or ID. func (l ListInstancePoolsResponse) FindInstancePool(nameOrID string) (InstancePool, error) { for i, elem := range l.InstancePools { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.InstancePools[i], nil } } @@ -8753,6 +8808,17 @@ type ListInstanceTypesResponse struct { InstanceTypes []InstanceType `json:"instance-types,omitempty"` } +// FindInstanceType attempts to find an InstanceType by name or ID. +func (l ListInstanceTypesResponse) FindInstanceType(nameOrID string) (InstanceType, error) { + for i, elem := range l.InstanceTypes { + if elem.ID.String() == nameOrID { + return l.InstanceTypes[i], nil + } + } + + return InstanceType{}, fmt.Errorf("%q not found in ListInstanceTypesResponse: %w", nameOrID, ErrNotFound) +} + // List Compute instance Types func (c Client) ListInstanceTypes(ctx context.Context) (*ListInstanceTypesResponse, error) { path := "/instance-type" @@ -9630,7 +9696,7 @@ type ListLoadBalancersResponse struct { // FindLoadBalancer attempts to find an LoadBalancer by name or ID. func (l ListLoadBalancersResponse) FindLoadBalancer(nameOrID string) (LoadBalancer, error) { for i, elem := range l.LoadBalancers { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.LoadBalancers[i], nil } } @@ -10327,7 +10393,7 @@ type ListPrivateNetworksResponse struct { // FindPrivateNetwork attempts to find an PrivateNetwork by name or ID. func (l ListPrivateNetworksResponse) FindPrivateNetwork(nameOrID string) (PrivateNetwork, error) { for i, elem := range l.PrivateNetworks { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.PrivateNetworks[i], nil } } @@ -11197,7 +11263,7 @@ type ListSecurityGroupsResponse struct { // FindSecurityGroup attempts to find an SecurityGroup by name or ID. func (l ListSecurityGroupsResponse) FindSecurityGroup(nameOrID string) (SecurityGroup, error) { for i, elem := range l.SecurityGroups { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.SecurityGroups[i], nil } } @@ -11782,7 +11848,7 @@ type ListSKSClustersResponse struct { // FindSKSCluster attempts to find an SKSCluster by name or ID. func (l ListSKSClustersResponse) FindSKSCluster(nameOrID string) (SKSCluster, error) { for i, elem := range l.SKSClusters { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.SKSClusters[i], nil } } @@ -12969,7 +13035,7 @@ type ListSnapshotsResponse struct { // FindSnapshot attempts to find an Snapshot by name or ID. func (l ListSnapshotsResponse) FindSnapshot(nameOrID string) (Snapshot, error) { for i, elem := range l.Snapshots { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.Snapshots[i], nil } } @@ -13216,6 +13282,17 @@ type ListSOSBucketsUsageResponse struct { SOSBucketsUsage []SOSBucketUsage `json:"sos-buckets-usage,omitempty"` } +// FindSOSBucketUsage attempts to find an SOSBucketUsage by name or ID. +func (l ListSOSBucketsUsageResponse) FindSOSBucketUsage(nameOrID string) (SOSBucketUsage, error) { + for i, elem := range l.SOSBucketsUsage { + if string(elem.Name) == nameOrID { + return l.SOSBucketsUsage[i], nil + } + } + + return SOSBucketUsage{}, fmt.Errorf("%q not found in ListSOSBucketsUsageResponse: %w", nameOrID, ErrNotFound) +} + // List SOS Buckets Usage func (c Client) ListSOSBucketsUsage(ctx context.Context) (*ListSOSBucketsUsageResponse, error) { path := "/sos-buckets-usage" @@ -13326,6 +13403,17 @@ type ListSSHKeysResponse struct { SSHKeys []SSHKey `json:"ssh-keys,omitempty"` } +// FindSSHKey attempts to find an SSHKey by name or ID. +func (l ListSSHKeysResponse) FindSSHKey(nameOrID string) (SSHKey, error) { + for i, elem := range l.SSHKeys { + if string(elem.Name) == nameOrID { + return l.SSHKeys[i], nil + } + } + + return SSHKey{}, fmt.Errorf("%q not found in ListSSHKeysResponse: %w", nameOrID, ErrNotFound) +} + // List SSH keys func (c Client) ListSSHKeys(ctx context.Context) (*ListSSHKeysResponse, error) { path := "/ssh-key" @@ -13519,7 +13607,7 @@ type ListTemplatesResponse struct { // FindTemplate attempts to find an Template by name or ID. func (l ListTemplatesResponse) FindTemplate(nameOrID string) (Template, error) { for i, elem := range l.Templates { - if elem.Name == nameOrID || elem.ID.String() == nameOrID { + if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { return l.Templates[i], nil } } @@ -13885,6 +13973,17 @@ type ListZonesResponse struct { Zones []Zone `json:"zones,omitempty"` } +// FindZone attempts to find an Zone by name or ID. +func (l ListZonesResponse) FindZone(nameOrID string) (Zone, error) { + for i, elem := range l.Zones { + if string(elem.Name) == nameOrID { + return l.Zones[i], nil + } + } + + return Zone{}, fmt.Errorf("%q not found in ListZonesResponse: %w", nameOrID, ErrNotFound) +} + // List Zones func (c Client) ListZones(ctx context.Context) (*ListZonesResponse, error) { path := "/zone" From fbc8dce0b95077a0cb91df158253ddbbe567ca94 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:11:24 +0000 Subject: [PATCH 2/4] CHANGELOG Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf392a1f3..de28a94ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +Unreleased +---------- + +- v3: Add more listable on Name or(not and) ID #642 + 3.1.0 ---------- From 275fc20694fd32cb9826a2c2b747c043f7e145bc Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:17:21 +0000 Subject: [PATCH 3/4] Reuse generated listable code Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- v3/client.go | 10 +++++----- v3/generator/client/client.tmpl | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/v3/client.go b/v3/client.go index 912271d57..804a37800 100755 --- a/v3/client.go +++ b/v3/client.go @@ -46,13 +46,13 @@ func (c Client) GetZoneAPIEndpoint(ctx context.Context, zoneName ZoneName) (Endp if err != nil { return "", fmt.Errorf("get zone api endpoint: %w", err) } - for _, zone := range resp.Zones { - if zone.Name == zoneName { - return zone.APIEndpoint, nil - } + + zone, err := resp.FindZone(string(zoneName)) + if err != nil { + return "", fmt.Errorf("get zone api endpoint: %w", err) } - return "", fmt.Errorf("get zone api endpoint: zone name %s not found", zoneName) + return zone.APIEndpoint, nil } // Client represents an Exoscale API client. diff --git a/v3/generator/client/client.tmpl b/v3/generator/client/client.tmpl index 19ccebab4..79fe2fbe0 100644 --- a/v3/generator/client/client.tmpl +++ b/v3/generator/client/client.tmpl @@ -24,13 +24,13 @@ func (c Client) GetZoneAPIEndpoint(ctx context.Context, zoneName ZoneName) (Endp if err != nil { return "", fmt.Errorf("get zone api endpoint: %w", err) } - for _, zone := range resp.Zones { - if zone.Name == zoneName { - return zone.APIEndpoint, nil - } + + zone, err := resp.FindZone(string(zoneName)) + if err != nil { + return "", fmt.Errorf("get zone api endpoint: %w", err) } - return "", fmt.Errorf("get zone api endpoint: zone name %s not found", zoneName) + return zone.APIEndpoint, nil } // Client represents an Exoscale API client. From 03c254bf42d8a7c2ba249022a620e6064ce2e6a4 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:20:45 +0000 Subject: [PATCH 4/4] Add better names Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- v3/generator/operations/operations.go | 15 ++-- v3/operations.go | 100 +++++++++++++------------- 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/v3/generator/operations/operations.go b/v3/generator/operations/operations.go index d87e8ad21..682d741d0 100644 --- a/v3/generator/operations/operations.go +++ b/v3/generator/operations/operations.go @@ -268,19 +268,20 @@ func renderRequestParametersSchema(name string, op *v3.Operation) ([]byte, error } const findableTemplate = ` -// Find{{ .TypeName }} attempts to find an {{ .TypeName }} by name or ID. -func (l {{ .ListTypeName }}) Find{{ .TypeName }}(nameOrID string) ({{ .TypeName }}, error) { +// Find{{ .TypeName }} attempts to find an {{ .TypeName }} by {{ .ParamName }}. +func (l {{ .ListTypeName }}) Find{{ .TypeName }}({{ .ParamName }} string) ({{ .TypeName }}, error) { for i, elem := range l.{{ .ListFieldName }} { if {{ .Condition }} { return l.{{ .ListFieldName }}[i], nil } } - return {{ .TypeName }}{}, fmt.Errorf("%q not found in {{ .ListTypeName }}: %w", nameOrID, ErrNotFound) + return {{ .TypeName }}{}, fmt.Errorf("%q not found in {{ .ListTypeName }}: %w", {{ .ParamName }}, ErrNotFound) } ` type Findable struct { + ParamName string TypeName string ListTypeName string ListFieldName string @@ -350,18 +351,22 @@ func renderFindable(funcName string, s *base.SchemaProxy) ([]byte, error) { if err != nil { return nil, err } + paramName := "nameOrID" condition := "string(elem.Name) == nameOrID || elem.ID.String() == nameOrID" if !hasID { - condition = "string(elem.Name) == nameOrID" + paramName = "name" + condition = "string(elem.Name) == " + paramName } if !hasName { - condition = "elem.ID.String() == nameOrID" + paramName = "ID" + condition = "elem.ID.String() == " + paramName } if err := t.Execute(output, Findable{ ListTypeName: funcName + "Response", ListFieldName: helpers.ToCamel(propName), TypeName: typeName, Condition: condition, + ParamName: paramName, }); err != nil { return nil, err } diff --git a/v3/operations.go b/v3/operations.go index 9bba6cb65..8a103355b 100755 --- a/v3/operations.go +++ b/v3/operations.go @@ -16,7 +16,7 @@ type ListAntiAffinityGroupsResponse struct { AntiAffinityGroups []AntiAffinityGroup `json:"anti-affinity-groups,omitempty"` } -// FindAntiAffinityGroup attempts to find an AntiAffinityGroup by name or ID. +// FindAntiAffinityGroup attempts to find an AntiAffinityGroup by nameOrID. func (l ListAntiAffinityGroupsResponse) FindAntiAffinityGroup(nameOrID string) (AntiAffinityGroup, error) { for i, elem := range l.AntiAffinityGroups { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -217,15 +217,15 @@ type ListAPIKeysResponse struct { APIKeys []IAMAPIKey `json:"api-keys,omitempty"` } -// FindIAMAPIKey attempts to find an IAMAPIKey by name or ID. -func (l ListAPIKeysResponse) FindIAMAPIKey(nameOrID string) (IAMAPIKey, error) { +// FindIAMAPIKey attempts to find an IAMAPIKey by name. +func (l ListAPIKeysResponse) FindIAMAPIKey(name string) (IAMAPIKey, error) { for i, elem := range l.APIKeys { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.APIKeys[i], nil } } - return IAMAPIKey{}, fmt.Errorf("%q not found in ListAPIKeysResponse: %w", nameOrID, ErrNotFound) + return IAMAPIKey{}, fmt.Errorf("%q not found in ListAPIKeysResponse: %w", name, ErrNotFound) } // List API keys @@ -418,7 +418,7 @@ type ListBlockStorageVolumesResponse struct { BlockStorageVolumes []BlockStorageVolume `json:"block-storage-volumes,omitempty"` } -// FindBlockStorageVolume attempts to find an BlockStorageVolume by name or ID. +// FindBlockStorageVolume attempts to find an BlockStorageVolume by nameOrID. func (l ListBlockStorageVolumesResponse) FindBlockStorageVolume(nameOrID string) (BlockStorageVolume, error) { for i, elem := range l.BlockStorageVolumes { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -553,7 +553,7 @@ type ListBlockStorageSnapshotsResponse struct { BlockStorageSnapshots []BlockStorageSnapshot `json:"block-storage-snapshots,omitempty"` } -// FindBlockStorageSnapshot attempts to find an BlockStorageSnapshot by name or ID. +// FindBlockStorageSnapshot attempts to find an BlockStorageSnapshot by nameOrID. func (l ListBlockStorageSnapshotsResponse) FindBlockStorageSnapshot(nameOrID string) (BlockStorageSnapshot, error) { for i, elem := range l.BlockStorageSnapshots { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -5702,15 +5702,15 @@ type ListDBAASServicesResponse struct { DBAASServices []DBAASServiceCommon `json:"dbaas-services,omitempty"` } -// FindDBAASServiceCommon attempts to find an DBAASServiceCommon by name or ID. -func (l ListDBAASServicesResponse) FindDBAASServiceCommon(nameOrID string) (DBAASServiceCommon, error) { +// FindDBAASServiceCommon attempts to find an DBAASServiceCommon by name. +func (l ListDBAASServicesResponse) FindDBAASServiceCommon(name string) (DBAASServiceCommon, error) { for i, elem := range l.DBAASServices { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.DBAASServices[i], nil } } - return DBAASServiceCommon{}, fmt.Errorf("%q not found in ListDBAASServicesResponse: %w", nameOrID, ErrNotFound) + return DBAASServiceCommon{}, fmt.Errorf("%q not found in ListDBAASServicesResponse: %w", name, ErrNotFound) } // List DBaaS services @@ -5887,15 +5887,15 @@ type ListDBAASServiceTypesResponse struct { DBAASServiceTypes []DBAASServiceType `json:"dbaas-service-types,omitempty"` } -// FindDBAASServiceType attempts to find an DBAASServiceType by name or ID. -func (l ListDBAASServiceTypesResponse) FindDBAASServiceType(nameOrID string) (DBAASServiceType, error) { +// FindDBAASServiceType attempts to find an DBAASServiceType by name. +func (l ListDBAASServiceTypesResponse) FindDBAASServiceType(name string) (DBAASServiceType, error) { for i, elem := range l.DBAASServiceTypes { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.DBAASServiceTypes[i], nil } } - return DBAASServiceType{}, fmt.Errorf("%q not found in ListDBAASServiceTypesResponse: %w", nameOrID, ErrNotFound) + return DBAASServiceType{}, fmt.Errorf("%q not found in ListDBAASServiceTypesResponse: %w", name, ErrNotFound) } // List available service types for DBaaS @@ -6552,7 +6552,7 @@ type ListDeployTargetsResponse struct { DeployTargets []DeployTarget `json:"deploy-targets,omitempty"` } -// FindDeployTarget attempts to find an DeployTarget by name or ID. +// FindDeployTarget attempts to find an DeployTarget by nameOrID. func (l ListDeployTargetsResponse) FindDeployTarget(nameOrID string) (DeployTarget, error) { for i, elem := range l.DeployTargets { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -6653,15 +6653,15 @@ type ListDNSDomainsResponse struct { DNSDomains []DNSDomain `json:"dns-domains,omitempty"` } -// FindDNSDomain attempts to find an DNSDomain by name or ID. -func (l ListDNSDomainsResponse) FindDNSDomain(nameOrID string) (DNSDomain, error) { +// FindDNSDomain attempts to find an DNSDomain by ID. +func (l ListDNSDomainsResponse) FindDNSDomain(ID string) (DNSDomain, error) { for i, elem := range l.DNSDomains { - if elem.ID.String() == nameOrID { + if elem.ID.String() == ID { return l.DNSDomains[i], nil } } - return DNSDomain{}, fmt.Errorf("%q not found in ListDNSDomainsResponse: %w", nameOrID, ErrNotFound) + return DNSDomain{}, fmt.Errorf("%q not found in ListDNSDomainsResponse: %w", ID, ErrNotFound) } // List DNS domains @@ -6767,7 +6767,7 @@ type ListDNSDomainRecordsResponse struct { DNSDomainRecords []DNSDomainRecord `json:"dns-domain-records,omitempty"` } -// FindDNSDomainRecord attempts to find an DNSDomainRecord by name or ID. +// FindDNSDomainRecord attempts to find an DNSDomainRecord by nameOrID. func (l ListDNSDomainRecordsResponse) FindDNSDomainRecord(nameOrID string) (DNSDomainRecord, error) { for i, elem := range l.DNSDomainRecords { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -7188,15 +7188,15 @@ type ListElasticIPSResponse struct { ElasticIPS []ElasticIP `json:"elastic-ips,omitempty"` } -// FindElasticIP attempts to find an ElasticIP by name or ID. -func (l ListElasticIPSResponse) FindElasticIP(nameOrID string) (ElasticIP, error) { +// FindElasticIP attempts to find an ElasticIP by ID. +func (l ListElasticIPSResponse) FindElasticIP(ID string) (ElasticIP, error) { for i, elem := range l.ElasticIPS { - if elem.ID.String() == nameOrID { + if elem.ID.String() == ID { return l.ElasticIPS[i], nil } } - return ElasticIP{}, fmt.Errorf("%q not found in ListElasticIPSResponse: %w", nameOrID, ErrNotFound) + return ElasticIP{}, fmt.Errorf("%q not found in ListElasticIPSResponse: %w", ID, ErrNotFound) } // List Elastic IPs @@ -7776,7 +7776,7 @@ type ListIAMRolesResponse struct { IAMRoles []IAMRole `json:"iam-roles,omitempty"` } -// FindIAMRole attempts to find an IAMRole by name or ID. +// FindIAMRole attempts to find an IAMRole by nameOrID. func (l ListIAMRolesResponse) FindIAMRole(nameOrID string) (IAMRole, error) { for i, elem := range l.IAMRoles { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -8133,7 +8133,7 @@ type ListInstancesResponse struct { Instances []ListInstancesResponseInstances `json:"instances,omitempty"` } -// FindListInstancesResponseInstances attempts to find an ListInstancesResponseInstances by name or ID. +// FindListInstancesResponseInstances attempts to find an ListInstancesResponseInstances by nameOrID. func (l ListInstancesResponse) FindListInstancesResponseInstances(nameOrID string) (ListInstancesResponseInstances, error) { for i, elem := range l.Instances { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -8304,7 +8304,7 @@ type ListInstancePoolsResponse struct { InstancePools []InstancePool `json:"instance-pools,omitempty"` } -// FindInstancePool attempts to find an InstancePool by name or ID. +// FindInstancePool attempts to find an InstancePool by nameOrID. func (l ListInstancePoolsResponse) FindInstancePool(nameOrID string) (InstancePool, error) { for i, elem := range l.InstancePools { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -8808,15 +8808,15 @@ type ListInstanceTypesResponse struct { InstanceTypes []InstanceType `json:"instance-types,omitempty"` } -// FindInstanceType attempts to find an InstanceType by name or ID. -func (l ListInstanceTypesResponse) FindInstanceType(nameOrID string) (InstanceType, error) { +// FindInstanceType attempts to find an InstanceType by ID. +func (l ListInstanceTypesResponse) FindInstanceType(ID string) (InstanceType, error) { for i, elem := range l.InstanceTypes { - if elem.ID.String() == nameOrID { + if elem.ID.String() == ID { return l.InstanceTypes[i], nil } } - return InstanceType{}, fmt.Errorf("%q not found in ListInstanceTypesResponse: %w", nameOrID, ErrNotFound) + return InstanceType{}, fmt.Errorf("%q not found in ListInstanceTypesResponse: %w", ID, ErrNotFound) } // List Compute instance Types @@ -9693,7 +9693,7 @@ type ListLoadBalancersResponse struct { LoadBalancers []LoadBalancer `json:"load-balancers,omitempty"` } -// FindLoadBalancer attempts to find an LoadBalancer by name or ID. +// FindLoadBalancer attempts to find an LoadBalancer by nameOrID. func (l ListLoadBalancersResponse) FindLoadBalancer(nameOrID string) (LoadBalancer, error) { for i, elem := range l.LoadBalancers { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -10390,7 +10390,7 @@ type ListPrivateNetworksResponse struct { PrivateNetworks []PrivateNetwork `json:"private-networks,omitempty"` } -// FindPrivateNetwork attempts to find an PrivateNetwork by name or ID. +// FindPrivateNetwork attempts to find an PrivateNetwork by nameOrID. func (l ListPrivateNetworksResponse) FindPrivateNetwork(nameOrID string) (PrivateNetwork, error) { for i, elem := range l.PrivateNetworks { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -11260,7 +11260,7 @@ type ListSecurityGroupsResponse struct { SecurityGroups []SecurityGroup `json:"security-groups,omitempty"` } -// FindSecurityGroup attempts to find an SecurityGroup by name or ID. +// FindSecurityGroup attempts to find an SecurityGroup by nameOrID. func (l ListSecurityGroupsResponse) FindSecurityGroup(nameOrID string) (SecurityGroup, error) { for i, elem := range l.SecurityGroups { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -11845,7 +11845,7 @@ type ListSKSClustersResponse struct { SKSClusters []SKSCluster `json:"sks-clusters,omitempty"` } -// FindSKSCluster attempts to find an SKSCluster by name or ID. +// FindSKSCluster attempts to find an SKSCluster by nameOrID. func (l ListSKSClustersResponse) FindSKSCluster(nameOrID string) (SKSCluster, error) { for i, elem := range l.SKSClusters { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -13032,7 +13032,7 @@ type ListSnapshotsResponse struct { Snapshots []Snapshot `json:"snapshots,omitempty"` } -// FindSnapshot attempts to find an Snapshot by name or ID. +// FindSnapshot attempts to find an Snapshot by nameOrID. func (l ListSnapshotsResponse) FindSnapshot(nameOrID string) (Snapshot, error) { for i, elem := range l.Snapshots { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -13282,15 +13282,15 @@ type ListSOSBucketsUsageResponse struct { SOSBucketsUsage []SOSBucketUsage `json:"sos-buckets-usage,omitempty"` } -// FindSOSBucketUsage attempts to find an SOSBucketUsage by name or ID. -func (l ListSOSBucketsUsageResponse) FindSOSBucketUsage(nameOrID string) (SOSBucketUsage, error) { +// FindSOSBucketUsage attempts to find an SOSBucketUsage by name. +func (l ListSOSBucketsUsageResponse) FindSOSBucketUsage(name string) (SOSBucketUsage, error) { for i, elem := range l.SOSBucketsUsage { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.SOSBucketsUsage[i], nil } } - return SOSBucketUsage{}, fmt.Errorf("%q not found in ListSOSBucketsUsageResponse: %w", nameOrID, ErrNotFound) + return SOSBucketUsage{}, fmt.Errorf("%q not found in ListSOSBucketsUsageResponse: %w", name, ErrNotFound) } // List SOS Buckets Usage @@ -13403,15 +13403,15 @@ type ListSSHKeysResponse struct { SSHKeys []SSHKey `json:"ssh-keys,omitempty"` } -// FindSSHKey attempts to find an SSHKey by name or ID. -func (l ListSSHKeysResponse) FindSSHKey(nameOrID string) (SSHKey, error) { +// FindSSHKey attempts to find an SSHKey by name. +func (l ListSSHKeysResponse) FindSSHKey(name string) (SSHKey, error) { for i, elem := range l.SSHKeys { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.SSHKeys[i], nil } } - return SSHKey{}, fmt.Errorf("%q not found in ListSSHKeysResponse: %w", nameOrID, ErrNotFound) + return SSHKey{}, fmt.Errorf("%q not found in ListSSHKeysResponse: %w", name, ErrNotFound) } // List SSH keys @@ -13604,7 +13604,7 @@ type ListTemplatesResponse struct { Templates []Template `json:"templates,omitempty"` } -// FindTemplate attempts to find an Template by name or ID. +// FindTemplate attempts to find an Template by nameOrID. func (l ListTemplatesResponse) FindTemplate(nameOrID string) (Template, error) { for i, elem := range l.Templates { if string(elem.Name) == nameOrID || elem.ID.String() == nameOrID { @@ -13973,15 +13973,15 @@ type ListZonesResponse struct { Zones []Zone `json:"zones,omitempty"` } -// FindZone attempts to find an Zone by name or ID. -func (l ListZonesResponse) FindZone(nameOrID string) (Zone, error) { +// FindZone attempts to find an Zone by name. +func (l ListZonesResponse) FindZone(name string) (Zone, error) { for i, elem := range l.Zones { - if string(elem.Name) == nameOrID { + if string(elem.Name) == name { return l.Zones[i], nil } } - return Zone{}, fmt.Errorf("%q not found in ListZonesResponse: %w", nameOrID, ErrNotFound) + return Zone{}, fmt.Errorf("%q not found in ListZonesResponse: %w", name, ErrNotFound) } // List Zones