Skip to content

Commit

Permalink
Merge pull request #165 from yahoo/quota
Browse files Browse the repository at this point in the history
quota support for domain object #164
  • Loading branch information
havetisyan authored Jul 5, 2017
2 parents d759693 + bb39aa1 commit d4172ec
Show file tree
Hide file tree
Showing 54 changed files with 3,624 additions and 165 deletions.
96 changes: 96 additions & 0 deletions clients/go/zms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2480,3 +2480,99 @@ func (client ZMSClient) DeleteUser(name SimpleName, auditRef string) error {
return errobj
}
}

func (client ZMSClient) GetQuota(name DomainName) (*Quota, error) {
var data *Quota
url := client.URL + "/domain/" + fmt.Sprint(name) + "/quota"
resp, err := client.httpGet(url, nil)
if err != nil {
return data, err
}
contentBytes, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return data, err
}
switch resp.StatusCode {
case 200:
err = json.Unmarshal(contentBytes, &data)
if err != nil {
return data, err
}
return data, nil
default:
var errobj rdl.ResourceError
json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return data, errobj
}
}

func (client ZMSClient) PutQuota(name DomainName, auditRef string, quota *Quota) error {
headers := map[string]string{
"Y-Audit-Ref": auditRef,
}
url := client.URL + "/domain/" + fmt.Sprint(name) + "/quota"
contentBytes, err := json.Marshal(quota)
if err != nil {
return err
}
resp, err := client.httpPut(url, headers, contentBytes)
if err != nil {
return err
}
contentBytes, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return err
}
switch resp.StatusCode {
case 204:
return nil
default:
var errobj rdl.ResourceError
json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return errobj
}
}

func (client ZMSClient) DeleteQuota(name DomainName, auditRef string) error {
headers := map[string]string{
"Y-Audit-Ref": auditRef,
}
url := client.URL + "/domain/" + fmt.Sprint(name) + "/quota"
resp, err := client.httpDelete(url, headers)
if err != nil {
return err
}
contentBytes, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return err
}
switch resp.StatusCode {
case 204:
return nil
default:
var errobj rdl.ResourceError
json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return errobj
}
}
105 changes: 105 additions & 0 deletions clients/go/zms/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4075,3 +4075,108 @@ func (self *UserMeta) UnmarshalJSON(b []byte) error {
func (self *UserMeta) Validate() error {
return nil
}

//
// Quota - The representation for a quota object
//
type Quota struct {

//
// name of the domain object
//
Name DomainName `json:"name"`

//
// number of subdomains allowed (applied at top level domain level)
//
Subdomain int32 `json:"subdomain"`

//
// number of roles allowed
//
Role int32 `json:"role"`

//
// number of members a role may have
//
RoleMember int32 `json:"roleMember"`

//
// number of policies allowed
//
Policy int32 `json:"policy"`

//
// total number of assertions a policy may have
//
Assertion int32 `json:"assertion"`

//
// total number of entity objects
//
Entity int32 `json:"entity"`

//
// number of services allowed
//
Service int32 `json:"service"`

//
// number of hosts allowed per service
//
ServiceHost int32 `json:"serviceHost"`

//
// number of public keys per service
//
PublicKey int32 `json:"publicKey"`

//
// the last modification timestamp of the quota object
//
Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`
}

//
// NewQuota - creates an initialized Quota instance, returns a pointer to it
//
func NewQuota(init ...*Quota) *Quota {
var o *Quota
if len(init) == 1 {
o = init[0]
} else {
o = new(Quota)
}
return o
}

type rawQuota Quota

//
// UnmarshalJSON is defined for proper JSON decoding of a Quota
//
func (self *Quota) UnmarshalJSON(b []byte) error {
var r rawQuota
err := json.Unmarshal(b, &r)
if err == nil {
o := Quota(r)
*self = o
err = self.Validate()
}
return err
}

//
// Validate - checks for missing required fields, etc
//
func (self *Quota) Validate() error {
if self.Name == "" {
return fmt.Errorf("Quota.name is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "DomainName", self.Name)
if !val.Valid {
return fmt.Errorf("Quota.name does not contain a valid DomainName (%v)", val.Error)
}
}
return nil
}
Loading

0 comments on commit d4172ec

Please sign in to comment.