Skip to content

Commit

Permalink
feat: add more rule fields
Browse files Browse the repository at this point in the history
  • Loading branch information
si-mm committed May 14, 2024
1 parent 7315e73 commit e6218b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cloud/service_sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s SecurityGroupService) SecurityGroup(ctx context.Context, id int) (*Secur
return &resp, nil
}

// SecurityGroups returns information about all images.
// SecurityGroups returns information about all security groups.
func (s SecurityGroupService) SecurityGroups(ctx context.Context) (*SecurityGroupsResponse, error) {
var resp SecurityGroupsResponse

Expand Down Expand Up @@ -112,6 +112,11 @@ func (s SecurityGroupService) CreateSecurityGroup(ctx context.Context, req Creat
var resp CreateSecurityGroupResponse
p := s.path(SecurityGroupPath)

if req.Template == "" {
tmp := NewTemplate(req)
req.Template = tmp.String()
}

if err := s.Post(ctx, p, req, &resp); err != nil {
return nil, err
}
Expand Down
17 changes: 15 additions & 2 deletions cloud/sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ type SecurityGroupTemplate struct {

// SecurityGroupRule is the API payload based on the legacy xmlrpc backend.
type SecurityGroupRule struct {
Protocol string `json:"protocol" yaml:"protocol"`
RuleType string `json:"rule_type" yaml:"rule_type"`
ICMPType string `json:"icmp_type" yaml:"icmp_type"`
IP string `json:"ip" yaml:"ip"`
NetworkID string `json:"network_id" yaml:"network_id"`
Protocol string `json:"protocol" yaml:"protocol"`
Range string `json:"range" yaml:"range"`
RuleType string `json:"rule_type" yaml:"rule_type"`
Size string `json:"size" yaml:"size"`
}

// ParseTemplate returns a structured subset of the nested key x value pair map.
Expand Down Expand Up @@ -64,6 +69,14 @@ func newSecurityGroupRule(m map[string]any) *SecurityGroupRule {
r.Protocol = v
case "RULE_TYPE":
r.RuleType = v
case "IP":
r.IP = v
case "RANGE":
r.Range = v
case "ICMP_TYPE":
r.ICMPType = v
case "NETWORK_ID":
r.NetworkID = v
}
}
}
Expand Down

0 comments on commit e6218b1

Please sign in to comment.