Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #138 from rackspace/sg-default-rules
Browse files Browse the repository at this point in the history
Attempt default rules API for security groups.
  • Loading branch information
sam-falvo committed Mar 11, 2014
2 parents 3165919 + c61289e commit d4fc90f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions interfaces.go
Expand Up @@ -214,4 +214,16 @@ type CloudServersProvider interface {
// DeleteSecurityGroupById disposes of a security group corresponding to the provided ID number.
// This method works only if the provider supports the os-security-groups extension.
DeleteSecurityGroupById(id int) error

// ListDefaultSGRules lists default security group rules.
// This method only works if the provider supports the os-security-groups-default-rules extension.
ListDefaultSGRules() ([]SGRule, error)

// CreateDefaultSGRule creates a default security group rule.
// This method only works if the provider supports the os-security-groups-default-rules extension.
CreateDefaultSGRule(SGRule) (*SGRule, error)

// GetSGRule obtains information for a specified security group rule.
// This method only works if the provider supports the os-security-groups-default-rules extension.
GetSGRule(string) (*SGRule, error)
}
46 changes: 46 additions & 0 deletions servers.go
Expand Up @@ -486,6 +486,52 @@ func (gsp *genericServersProvider) DeleteSecurityGroupById(id int) error {
return err
}

// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) ListDefaultSGRules() ([]SGRule, error) {
var sgrs []SGRule
err := gsp.context.WithReauth(gsp.access, func() error {
ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint)
return perigee.Get(ep, perigee.Options{
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
Results: &struct{Security_group_default_rules *[]SGRule}{&sgrs},
})
})
return sgrs, err
}

// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) CreateDefaultSGRule(r SGRule) (*SGRule, error) {
var sgr *SGRule
err := gsp.context.WithReauth(gsp.access, func() error {
ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint)
return perigee.Post(ep, perigee.Options{
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
Results: &struct{Security_group_default_rule **SGRule}{&sgr},
ReqBody: struct{Security_group_default_rule SGRule `json:"security_group_default_rule"`}{r},
})
})
return sgr, err
}

// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) GetSGRule(id string) (*SGRule, error) {
var sgr *SGRule
err := gsp.context.WithReauth(gsp.access, func() error {
ep := fmt.Sprintf("%s/os-security-group-default-rules/%s", gsp.endpoint, id)
return perigee.Get(ep, perigee.Options{
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
Results: &struct{Security_group_default_rule **SGRule}{&sgr},
})
})
return sgr, err
}

// SecurityGroup provides a description of a security group, including all its rules.
type SecurityGroup struct {
Description string `json:"description,omitempty"`
Expand Down

0 comments on commit d4fc90f

Please sign in to comment.