Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad committed Jan 21, 2025
1 parent dfd4d79 commit a17aca3
Showing 1 changed file with 46 additions and 41 deletions.
87 changes: 46 additions & 41 deletions internal/sdk/cloudian/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,51 @@ type QualityOfServiceLimits struct {
OutboundKiBsPerMin *int64
}

// nolint: gocyclo
func (qos *QualityOfService) UnmarshalJSON(raw []byte) error {
var data struct {
QOSLimitList []struct {
Type string `json:"type"`
Value int64 `json:"value"`
} `json:"qosLimitList"`
}

if err := json.Unmarshal(raw, &data); err != nil {
return err
}

for _, item := range data.QOSLimitList {
if item.Value < 0 {
continue
}

v := &item.Value
switch item.Type {
case "STORAGE_QUOTA_KBYTES_LH":
qos.Hard.StorageQuotaKiBs = v
case "STORAGE_QUOTA_KBYTES_LW":
qos.Soft.StorageQuotaKiBs = v
case "STORAGE_QUOTA_COUNT_LH":
qos.Hard.StorageQuotaCount = v
case "STORAGE_QUOTA_COUNT_LW":
qos.Soft.StorageQuotaCount = v
case "REQUEST_RATE_LH":
qos.Hard.RequestsPerMin = v
case "REQUEST_RATE_LW":
qos.Soft.RequestsPerMin = v
case "DATAKBYTES_IN_LH":
qos.Hard.InboundKiBsPerMin = v
case "DATAKBYTES_IN_LW":
qos.Soft.InboundKiBsPerMin = v
case "DATAKBYTES_OUT_LH":
qos.Hard.OutboundKiBsPerMin = v
case "DATAKBYTES_OUT_LW":
qos.Soft.OutboundKiBsPerMin = v
}
}
return nil
}

// CreateQuota sets the QoS limits for a `User`. To change QoS limits, a delete and recreate is necessary.
func (client Client) CreateQuota(ctx context.Context, user User, qos QualityOfService) error {
rawParams := map[string]*int64{
Expand Down Expand Up @@ -84,48 +129,8 @@ func (client Client) GetQuota(ctx context.Context, user User) (*QualityOfService

switch resp.StatusCode() {
case 200:
var data struct {
QOSLimitList []struct {
Type string
Value int64
} `json:"qosLimitList"`
}

if err := json.Unmarshal(resp.Body(), &data); err != nil {
return nil, err
}

qos := QualityOfService{}
for _, item := range data.QOSLimitList {
if item.Value < 0 {
continue
}

v := &item.Value
switch item.Type {
case "STORAGE_QUOTA_KBYTES_LH":
qos.Hard.StorageQuotaKiBs = v
case "STORAGE_QUOTA_KBYTES_LW":
qos.Soft.StorageQuotaKiBs = v
case "STORAGE_QUOTA_COUNT_LH":
qos.Hard.StorageQuotaCount = v
case "STORAGE_QUOTA_COUNT_LW":
qos.Soft.StorageQuotaCount = v
case "REQUEST_RATE_LH":
qos.Hard.RequestsPerMin = v
case "REQUEST_RATE_LW":
qos.Soft.RequestsPerMin = v
case "DATAKBYTES_IN_LH":
qos.Hard.InboundKiBsPerMin = v
case "DATAKBYTES_IN_LW":
qos.Soft.InboundKiBsPerMin = v
case "DATAKBYTES_OUT_LH":
qos.Hard.OutboundKiBsPerMin = v
case "DATAKBYTES_OUT_LW":
qos.Soft.OutboundKiBsPerMin = v
}
}
return &qos, nil
return &qos, qos.UnmarshalJSON(resp.Body())
default:
return nil, fmt.Errorf("SET quota unexpected status: %d", resp.StatusCode())
}
Expand Down

0 comments on commit a17aca3

Please sign in to comment.