Skip to content

Commit 10cb117

Browse files
QuentinPerezQuentin Perez
authored andcommitted
Add GetQuotas
1 parent e8825d4 commit 10cb117

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/api/api.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ type ScalewayUserdatas struct {
734734
UserData []string `json:"user_data"`
735735
}
736736

737+
type ScalewayQuota map[string]int
738+
739+
// ScalewayGetQuotas represents the response of GET /organizations/{orga_id}/quotas
740+
type ScalewayGetQuotas struct {
741+
Quotas ScalewayQuota `json:"quotas"`
742+
}
743+
737744
// ScalewayUserdata represents []byte
738745
type ScalewayUserdata []byte
739746

@@ -2027,6 +2034,28 @@ func (s *ScalewayAPI) GetIP(ipID string) (*ScalewayGetIP, error) {
20272034
return &ip, nil
20282035
}
20292036

2037+
// GetQuotas returns a ScalewayGetQuotas
2038+
func (s *ScalewayAPI) GetQuotas() (*ScalewayGetQuotas, error) {
2039+
s.EnableAccountAPI()
2040+
defer s.DisableAccountAPI()
2041+
resp, err := s.GetResponse(fmt.Sprintf("organizations/%s/quotas", s.Organization))
2042+
if err != nil {
2043+
return nil, err
2044+
}
2045+
defer resp.Body.Close()
2046+
2047+
body, err := s.handleHTTPError([]int{200}, resp)
2048+
if err != nil {
2049+
return nil, err
2050+
}
2051+
var quotas ScalewayGetQuotas
2052+
2053+
if err = json.Unmarshal(body, &quotas); err != nil {
2054+
return nil, err
2055+
}
2056+
return &quotas, nil
2057+
}
2058+
20302059
// GetBootscriptID returns exactly one bootscript matching or dies
20312060
func (s *ScalewayAPI) GetBootscriptID(needle string) string {
20322061
// Parses optional type prefix, i.e: "bootscript:name" -> "name"

0 commit comments

Comments
 (0)