From 7f989ae305d6b99fac41779fd22bc85c2fe27bc7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:42:54 +0000 Subject: [PATCH] Renovate: Update github.com/sapcc --- go.mod | 6 +- go.sum | 12 +- .../internal/marshal/marshal.go | 12 +- .../go-api-declarations/limes/metadata.go | 11 + .../limes/resources/commitment.go | 221 ++++++++++++++++++ .../limes/resources/marshal.go | 3 +- .../limes/resources/metadata.go | 8 + .../limes/resources/report_cluster.go | 10 +- .../limes/resources/report_project.go | 21 +- vendor/modules.txt | 6 +- 10 files changed, 276 insertions(+), 34 deletions(-) create mode 100644 vendor/github.com/sapcc/go-api-declarations/limes/resources/commitment.go diff --git a/go.mod b/go.mod index 4832edd..033da01 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.21 require ( github.com/gophercloud/gophercloud v1.7.0 - github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d + github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 github.com/olekukonko/tablewriter v0.0.5 - github.com/sapcc/go-api-declarations v1.8.3 - github.com/sapcc/gophercloud-sapcc v0.0.0-20231004083010-5b75b97bad76 + github.com/sapcc/go-api-declarations v1.9.0 + github.com/sapcc/gophercloud-sapcc v0.0.0-20231012112418-5e87a157f2af github.com/spf13/cobra v1.7.0 ) diff --git a/go.sum b/go.sum index 0c52351..1fc6295 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/gophercloud/gophercloud v1.3.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM= github.com/gophercloud/gophercloud v1.7.0 h1:fyJGKh0LBvIZKLvBWvQdIgkaV5yTM3Jh9EYUh+UNCAs= github.com/gophercloud/gophercloud v1.7.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM= -github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d h1:6Gvua77nKyAiZQpu0N3AsamGu1L6Mlnhp3tAtDcqwvc= -github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d/go.mod h1:VSalo4adEk+3sNkmVJLnhHoOyOYYS8sTWLG4mv5BKto= +github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 h1:sH7xkTfYzxIEgzq1tDHIMKRh1vThOEOGNsettdEeLbE= +github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56/go.mod h1:VSalo4adEk+3sNkmVJLnhHoOyOYYS8sTWLG4mv5BKto= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -15,10 +15,10 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sapcc/go-api-declarations v1.8.3 h1:aGBTX3vjk/QX0ptPyz7DqGY97clhYXkpURZf+z9okV4= -github.com/sapcc/go-api-declarations v1.8.3/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= -github.com/sapcc/gophercloud-sapcc v0.0.0-20231004083010-5b75b97bad76 h1:6Abu/QGXnxPDGYWqqKXfbP7B1HrQv4aL2l8ZYIJ5uKo= -github.com/sapcc/gophercloud-sapcc v0.0.0-20231004083010-5b75b97bad76/go.mod h1:AtfUwXke93MD1C5d6s8juPNkRrpRjl7EYz8elql19Yo= +github.com/sapcc/go-api-declarations v1.9.0 h1:IUCIo9gn6z6FnNY3DX5jaKb0Read2TlkcZQLXOSqCh8= +github.com/sapcc/go-api-declarations v1.9.0/go.mod h1:83R3hTANhuRXt/pXDby37IJetw8l7DG41s33Tp9NXxI= +github.com/sapcc/gophercloud-sapcc v0.0.0-20231012112418-5e87a157f2af h1:6KXV/3H5INO73GQ8uB/y7fDXmQ+KpUn8wVLtxOGxU40= +github.com/sapcc/gophercloud-sapcc v0.0.0-20231012112418-5e87a157f2af/go.mod h1:coJCrQR3KgsHBkOfmNB5Fuxxl7JbHlwxWNbqK1+TzAA= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/vendor/github.com/sapcc/go-api-declarations/internal/marshal/marshal.go b/vendor/github.com/sapcc/go-api-declarations/internal/marshal/marshal.go index 1916fcd..9abbe60 100644 --- a/vendor/github.com/sapcc/go-api-declarations/internal/marshal/marshal.go +++ b/vendor/github.com/sapcc/go-api-declarations/internal/marshal/marshal.go @@ -21,17 +21,17 @@ package marshal import ( "encoding/json" - "sort" + "slices" ) // MapAsList marshals a map type into a flat JSON list, thereby discarding the keys. -func MapAsList[T any](vals map[string]T) ([]byte, error) { +func MapAsList[S ~string, T any](vals map[S]T) ([]byte, error) { //serialize with ordered keys to ensure testcase stability - names := make([]string, 0, len(vals)) + names := make([]S, 0, len(vals)) for name := range vals { names = append(names, name) } - sort.Strings(names) + slices.Sort(names) list := make([]T, len(vals)) for idx, name := range names { list[idx] = vals[name] @@ -41,13 +41,13 @@ func MapAsList[T any](vals map[string]T) ([]byte, error) { // MapFromList unmarshals a flat JSON list into a map, using the provided // predicate to obtain the keys for each item. -func MapFromList[T any](buf []byte, getKey func(T) string) (map[string]T, error) { +func MapFromList[S ~string, T any](buf []byte, getKey func(T) S) (map[S]T, error) { var list []T err := json.Unmarshal(buf, &list) if err != nil { return nil, err } - result := make(map[string]T, len(list)) + result := make(map[S]T, len(list)) for _, item := range list { result[getKey(item)] = item } diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/metadata.go b/vendor/github.com/sapcc/go-api-declarations/limes/metadata.go index d381f38..bddac5f 100644 --- a/vendor/github.com/sapcc/go-api-declarations/limes/metadata.go +++ b/vendor/github.com/sapcc/go-api-declarations/limes/metadata.go @@ -54,3 +54,14 @@ type ServiceInfo struct { //Area is a hint that UIs can use to group similar services. Area string `json:"area"` } + +// AvailabilityZone is the name of an availability zone. +// Some special values are enumerated below. +type AvailabilityZone string + +const ( + // AvailabilityZoneAny marks values that are not bound to a specific AZ. + AvailabilityZoneAny AvailabilityZone = "any" + // AvailabilityZoneUnknown marks values that are bound to an unknown AZ. + AvailabilityZoneUnknown AvailabilityZone = "unknown" +) diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/resources/commitment.go b/vendor/github.com/sapcc/go-api-declarations/limes/resources/commitment.go new file mode 100644 index 0000000..216b2e9 --- /dev/null +++ b/vendor/github.com/sapcc/go-api-declarations/limes/resources/commitment.go @@ -0,0 +1,221 @@ +/****************************************************************************** +* +* Copyright 2023 SAP SE +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +package limesresources + +import ( + "database/sql/driver" + "encoding/json" + "fmt" + "regexp" + "strconv" + "strings" + "time" + + "github.com/sapcc/go-api-declarations/limes" +) + +// Commitment is the API representation of an *existing* commitment as reported by Limes. +type Commitment struct { + ID int64 `json:"id"` + ServiceType string `json:"service_type"` + ResourceName string `json:"resource_name"` + AvailabilityZone limes.AvailabilityZone `json:"availability_zone"` + Amount uint64 `json:"amount"` + Unit limes.Unit `json:"unit"` + Duration CommitmentDuration `json:"duration"` + RequestedAt limes.UnixEncodedTime `json:"requested_at"` + // ConfirmedAt and ExpiresAt are only filled after the commitment was confirmed. + ConfirmedAt *limes.UnixEncodedTime `json:"confirmed_at,omitempty"` + ExpiresAt *limes.UnixEncodedTime `json:"expires_at,omitempty"` + // TransferStatus and TransferToken are only filled while the commitment is marked for transfer. + TransferStatus CommitmentTransferStatus `json:"transfer_status,omitempty"` + TransferToken string `json:"transfer_token,omitempty"` +} + +// CommitmentRequest is the API representation of a *new* commitment as requested by a user. +type CommitmentRequest struct { + ServiceType string `json:"service_type"` + ResourceName string `json:"resource_name"` + AvailabilityZone limes.AvailabilityZone `json:"availability_zone"` + Amount uint64 `json:"amount"` + Duration CommitmentDuration `json:"duration"` +} + +// CommitmentTransferStatus is an enum. +type CommitmentTransferStatus string + +const ( + // CommitmentTransferStatusNone is the default transfer status, + // meaning that the commitment is not marked for transfer. + CommitmentTransferStatusNone CommitmentTransferStatus = "" + + // CommitmentTransferStatusPublic means that the commitment is marked for transfer, + // and is visible as such to all other projects. + CommitmentTransferStatusPublic CommitmentTransferStatus = "public" + + // CommitmentTransferStatusUnlisted means that the commitment is marked for transfer, + // but the receiver needs to know the commitment's transfer token. + CommitmentTransferStatusUnlisted CommitmentTransferStatus = "unlisted" +) + +// CommitmentDuration is the parsed representation of a commitment duration. +// +// The behavior of this type is similar to time.Duration or limesrates.Window for short durations +// (which are commonly used in automated tests for convenience and clarity), +// but also allows large durations with calendar-compatible calculations +// (e.g. "1y" is actually one year and not just 365 days). +type CommitmentDuration struct { + //NOTE: this does not use uint etc. because time.Time.AddDate() wants int + Years int + Months int + Days int + Short time.Duration //represents durations of hours, minutes and seconds +} + +var cdTokenRx = regexp.MustCompile(`^([0-9]*)\s*(second|minute|hour|day|month|year)s?$`) + +// ParseCommitmentDuration parses the string representation of a CommitmentDuration. +// Acceptable inputs include "5 hours" and "1year,2 \t months, 3days". +func ParseCommitmentDuration(input string) (CommitmentDuration, error) { + var result CommitmentDuration + for _, field := range strings.Split(input, ",") { + field = strings.TrimSpace(field) + if field == "" { + continue + } + match := cdTokenRx.FindStringSubmatch(field) + if match == nil { + return CommitmentDuration{}, fmt.Errorf("could not parse CommitmentDuration %q: malformed field %q", input, field) + } + amount, err := strconv.Atoi(match[1]) + if err != nil { + return CommitmentDuration{}, fmt.Errorf("could not parse CommitmentDuration %q: malformed field %q", input, field) + } + switch match[2] { + case "second": + result.Short += time.Duration(amount) * time.Second + case "minute": + result.Short += time.Duration(amount) * time.Minute + case "hour": + result.Short += time.Duration(amount) * time.Hour + case "day": + result.Days += amount + case "month": + result.Months += amount + case "year": + result.Years += amount + } + } + + if result.Years == 0 && result.Months == 0 && result.Days == 0 && result.Short == 0 { + return CommitmentDuration{}, fmt.Errorf("could not parse CommitmentDuration %q: empty duration", input) + } + return result, nil +} + +// String returns the canonical string representation of this duration. +func (d CommitmentDuration) String() string { + var fields []string + format := func(amount int, unit string) { + switch amount { + case 0: + return + case 1: + fields = append(fields, "1 "+unit) + default: + fields = append(fields, fmt.Sprintf("%d %ss", amount, unit)) + } + } + + format(d.Years, "year") + format(d.Months, "month") + format(d.Days, "day") + duration := d.Short + + hours := duration / time.Hour + duration -= hours * time.Hour //nolint:durationcheck // false positive + format(int(hours), "hour") + + minutes := duration / time.Minute + duration -= minutes * time.Minute //nolint:durationcheck // false positive + format(int(minutes), "minute") + + format(int(duration/time.Second), "second") + return strings.Join(fields, ", ") +} + +// AddTo adds this duration to the given time. +func (d CommitmentDuration) AddTo(t time.Time) time.Time { + return t.AddDate(d.Years, d.Months, d.Days).Add(d.Short) +} + +// MarshalJSON implements the json.Marshaler interface. +func (d CommitmentDuration) MarshalJSON() ([]byte, error) { + return json.Marshal(d.String()) +} + +// UnmarshalJSON implements the json.Unmarshaler interface. +func (d *CommitmentDuration) UnmarshalJSON(input []byte) error { + var s string + err := json.Unmarshal(input, &s) + if err != nil { + return err + } + *d, err = ParseCommitmentDuration(s) + return err +} + +// MarshalYAML implements the yaml.Marshaler interface. +func (d CommitmentDuration) MarshalYAML() (any, error) { + return d.String(), nil +} + +// UnmarshalYAML implements the yaml.Unmarshaler interface. +func (d *CommitmentDuration) UnmarshalYAML(unmarshal func(any) error) error { + var input string + err := unmarshal(&input) + if err != nil { + return err + } + *d, err = ParseCommitmentDuration(input) + return err +} + +// Scan implements the sql.Scanner interface. +func (d *CommitmentDuration) Scan(src any) (err error) { + var srcString string + switch src := src.(type) { + case string: + srcString = src + case []byte: + srcString = string(src) + case nil: + srcString = "" + default: + return fmt.Errorf("cannot scan value of type %T into type limesresources.CommitmentDuration", src) + } + + *d, err = ParseCommitmentDuration(srcString) + return err +} + +// Value implements the sql/driver.Valuer interface. +func (d CommitmentDuration) Value() (driver.Value, error) { + return driver.Value(d.String()), nil +} diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/resources/marshal.go b/vendor/github.com/sapcc/go-api-declarations/limes/resources/marshal.go index 574828b..98ee4c9 100644 --- a/vendor/github.com/sapcc/go-api-declarations/limes/resources/marshal.go +++ b/vendor/github.com/sapcc/go-api-declarations/limes/resources/marshal.go @@ -21,6 +21,7 @@ package limesresources import ( "github.com/sapcc/go-api-declarations/internal/marshal" + "github.com/sapcc/go-api-declarations/limes" ) func (r ClusterAvailabilityZoneReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(r) } @@ -32,7 +33,7 @@ func (r ProjectResourceReports) MarshalJSON() ([]byte, error) { return m func (s ProjectServiceReports) MarshalJSON() ([]byte, error) { return marshal.MapAsList(s) } func (r *ClusterAvailabilityZoneReports) UnmarshalJSON(buf []byte) error { - m, err := marshal.MapFromList(buf, func(r *ClusterAvailabilityZoneReport) string { return r.Name }) + m, err := marshal.MapFromList(buf, func(r *ClusterAvailabilityZoneReport) limes.AvailabilityZone { return r.Name }) *r = ClusterAvailabilityZoneReports(m) return err } diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/resources/metadata.go b/vendor/github.com/sapcc/go-api-declarations/limes/resources/metadata.go index 1949ed3..47f6804 100644 --- a/vendor/github.com/sapcc/go-api-declarations/limes/resources/metadata.go +++ b/vendor/github.com/sapcc/go-api-declarations/limes/resources/metadata.go @@ -89,3 +89,11 @@ const ( // projects quota. CentralizedQuotaDistribution QuotaDistributionModel = "centralized" ) + +// CommitmentConfiguration describes how commitments are configured for a given resource. +// +// This appears as a field on resource reports, if the respective resource allows commitments. +type CommitmentConfiguration struct { + // Allowed durations for commitments on this resource. + Durations []CommitmentDuration `json:"durations"` +} diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_cluster.go b/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_cluster.go index 8c8c255..a5da9c6 100644 --- a/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_cluster.go +++ b/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_cluster.go @@ -62,10 +62,10 @@ type ClusterResourceReport struct { // ClusterAvailabilityZoneReport is a substructure of ClusterResourceReport containing // capacity and usage data for a single resource in an availability zone. type ClusterAvailabilityZoneReport struct { - Name string `json:"name"` - Capacity uint64 `json:"capacity"` - RawCapacity uint64 `json:"raw_capacity,omitempty"` - Usage uint64 `json:"usage,omitempty"` + Name limes.AvailabilityZone `json:"name"` + Capacity uint64 `json:"capacity"` + RawCapacity uint64 `json:"raw_capacity,omitempty"` + Usage uint64 `json:"usage,omitempty"` } // ClusterServiceReports provides fast lookup of services by service type, but @@ -78,4 +78,4 @@ type ClusterResourceReports map[string]*ClusterResourceReport // ClusterAvailabilityZoneReports provides fast lookup of availability zones // using a map, but serializes to JSON as a list. -type ClusterAvailabilityZoneReports map[string]*ClusterAvailabilityZoneReport +type ClusterAvailabilityZoneReports map[limes.AvailabilityZone]*ClusterAvailabilityZoneReport diff --git a/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_project.go b/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_project.go index a1a9a5c..c60aae0 100644 --- a/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_project.go +++ b/vendor/github.com/sapcc/go-api-declarations/limes/resources/report_project.go @@ -53,16 +53,17 @@ type ProjectServiceReport struct { type ProjectResourceReport struct { //Several fields are pointers to values to enable precise control over which fields are rendered in output. ResourceInfo - QuotaDistributionModel QuotaDistributionModel `json:"quota_distribution_model,omitempty"` - Quota *uint64 `json:"quota,omitempty"` - DefaultQuota *uint64 `json:"default_quota,omitempty"` - UsableQuota *uint64 `json:"usable_quota,omitempty"` - Usage uint64 `json:"usage"` - BurstUsage uint64 `json:"burst_usage,omitempty"` - PhysicalUsage *uint64 `json:"physical_usage,omitempty"` - BackendQuota *int64 `json:"backend_quota,omitempty"` - Subresources json.RawMessage `json:"subresources,omitempty"` - Scaling *ScalingBehavior `json:"scales_with,omitempty"` + QuotaDistributionModel QuotaDistributionModel `json:"quota_distribution_model,omitempty"` + CommitmentConfig *CommitmentConfiguration `json:"commitment_config,omitempty"` + Quota *uint64 `json:"quota,omitempty"` + DefaultQuota *uint64 `json:"default_quota,omitempty"` + UsableQuota *uint64 `json:"usable_quota,omitempty"` + Usage uint64 `json:"usage"` + BurstUsage uint64 `json:"burst_usage,omitempty"` + PhysicalUsage *uint64 `json:"physical_usage,omitempty"` + BackendQuota *int64 `json:"backend_quota,omitempty"` + Subresources json.RawMessage `json:"subresources,omitempty"` + Scaling *ScalingBehavior `json:"scales_with,omitempty"` //Annotations may contain arbitrary metadata that was configured for this //resource in this scope by Limes' operator. Annotations map[string]any `json:"annotations,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index 5804d15..a4c245c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -12,7 +12,7 @@ github.com/gophercloud/gophercloud/openstack/identity/v3/tokens github.com/gophercloud/gophercloud/openstack/utils github.com/gophercloud/gophercloud/pagination github.com/gophercloud/gophercloud/testhelper -# github.com/gophercloud/utils v0.0.0-20230523080330-de873b9cf00d +# github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56 ## explicit; go 1.15 github.com/gophercloud/utils/client github.com/gophercloud/utils/env @@ -34,14 +34,14 @@ github.com/mitchellh/go-homedir # github.com/olekukonko/tablewriter v0.0.5 ## explicit; go 1.12 github.com/olekukonko/tablewriter -# github.com/sapcc/go-api-declarations v1.8.3 +# github.com/sapcc/go-api-declarations v1.9.0 ## explicit; go 1.21 github.com/sapcc/go-api-declarations/bininfo github.com/sapcc/go-api-declarations/internal/marshal github.com/sapcc/go-api-declarations/limes github.com/sapcc/go-api-declarations/limes/rates github.com/sapcc/go-api-declarations/limes/resources -# github.com/sapcc/gophercloud-sapcc v0.0.0-20231004083010-5b75b97bad76 +# github.com/sapcc/gophercloud-sapcc v0.0.0-20231012112418-5e87a157f2af ## explicit; go 1.21 github.com/sapcc/gophercloud-sapcc/clients github.com/sapcc/gophercloud-sapcc/rates/v1/clusters