-
Notifications
You must be signed in to change notification settings - Fork 13
/
limits.go
40 lines (35 loc) · 1.24 KB
/
limits.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package model
import (
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/pkg/platform/api"
clientLimits "github.com/ActiveState/cli/pkg/platform/api/mono/mono_client/limits"
"github.com/ActiveState/cli/pkg/platform/api/mono/mono_models"
"github.com/ActiveState/cli/pkg/platform/authentication"
)
// FetchOrganizationLimits returns the limits for an organization
func FetchOrganizationLimits(orgName string, auth *authentication.Auth) (*mono_models.Limits, error) {
params := clientLimits.NewGetOrganizationLimitsParams()
params.SetOrganizationIdentifier(orgName)
authClient, err := auth.Client()
if err != nil {
return nil, errs.Wrap(err, "Could not get auth client")
}
res, err := authClient.Limits.GetOrganizationLimits(params, auth.ClientAuth())
if err != nil {
return nil, processLimitsErrorResponse(err)
}
return res.Payload, nil
}
func processLimitsErrorResponse(err error) error {
switch statusCode := api.ErrorCode(err); statusCode {
case 401:
return locale.NewError("err_api_not_authenticated")
case 403:
return locale.NewError("err_api_forbidden")
case 404:
return locale.NewError("err_api_org_not_found")
default:
return errs.Wrap(err, "Unknown failure")
}
}