-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ce2584
commit 1792e4b
Showing
7 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"go.anx.io/go-anxcloud/pkg/api/types" | ||
) | ||
|
||
// EndpointURL returns the URL where to retrieve objects of type ACL and the identifier of the given ACL. | ||
// It implements the api.Object interface on *ACL, making it usable with the generic API client. | ||
func (a *ACL) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
op, err := types.OperationFromContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
u, err := url.Parse("/api/LBaaS/v1/ACL.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if op == types.OperationList { | ||
filters := make(url.Values) | ||
|
||
if a.ParentType != "" { | ||
filters.Add("parent_type", a.ParentType) | ||
} | ||
if a.Backend.Identifier != "" { | ||
filters.Add("backend", a.Backend.Identifier) | ||
} | ||
if a.Frontend.Identifier != "" { | ||
filters.Add("frontend", a.Frontend.Identifier) | ||
} | ||
|
||
query := u.Query() | ||
query.Add("filters", filters.Encode()) | ||
u.RawQuery = query.Encode() | ||
} | ||
|
||
return u, nil | ||
} | ||
|
||
// FilterAPIRequestBody generates the request body for ACLs, replacing linked Objects with just their identifier. | ||
func (a *ACL) FilterAPIRequestBody(ctx context.Context) (interface{}, error) { | ||
return requestBody(ctx, func() interface{} { | ||
return &struct { | ||
commonRequestBody | ||
ACL | ||
Backend string `json:"backend,omitempty"` | ||
Frontend string `json:"frontend,omitempty"` | ||
}{ | ||
ACL: *a, | ||
Backend: a.Backend.Identifier, | ||
Frontend: a.Frontend.Identifier, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v1 | ||
|
||
// anxcloud:object:hooks=RequestBodyHook | ||
|
||
// ACL represents an LBaaS ACL | ||
type ACL struct { | ||
commonMethods | ||
HasState | ||
|
||
CustomerIdentifier string `json:"customer_identifier"` | ||
ResellerIdentifier string `json:"reseller_identifier"` | ||
|
||
Identifier string `json:"identifier" anxcloud:"identifier"` | ||
Name string `json:"name"` | ||
ParentType string `json:"parent_type"` | ||
Criterion string `json:"criterion"` | ||
Value string `json:"value"` | ||
Index int `json:"index"` | ||
AutomationRules []RuleInfo `json:"automation_rules,omitempty"` | ||
|
||
// Only the name and identifier fields are used and returned. | ||
Frontend Frontend `json:"frontend,omitempty"` | ||
Backend Backend `json:"backend,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"go.anx.io/go-anxcloud/pkg/api/types" | ||
) | ||
|
||
// EndpointURL returns the URL where to retrieve objects of type Rule and the identifier of the given Rule. | ||
// It implements the api.Object interface on *Rule, making it usable with the generic API client. | ||
func (r *Rule) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
op, err := types.OperationFromContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
u, err := url.Parse("/api/LBaaS/v1/rule.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if op == types.OperationList { | ||
filters := make(url.Values) | ||
|
||
if r.RuleType != "" { | ||
filters.Add("rule_type", r.RuleType) | ||
} | ||
if r.ParentType != "" { | ||
filters.Add("parent_type", r.ParentType) | ||
} | ||
if r.Frontend.Identifier != "" { | ||
filters.Add("frontend", r.Frontend.Identifier) | ||
} | ||
if r.Backend.Identifier != "" { | ||
filters.Add("backend", r.Backend.Identifier) | ||
} | ||
if r.Condition != "" { | ||
filters.Add("condition", r.Condition) | ||
} | ||
if r.Type != "" { | ||
filters.Add("type", r.Type) | ||
} | ||
if r.Action != "" { | ||
filters.Add("action", r.Action) | ||
} | ||
if r.RedirectionType != "" { | ||
filters.Add("redirection_type", r.RedirectionType) | ||
} | ||
if r.RedirectionCode != "" { | ||
filters.Add("redirection_code", r.RedirectionCode) | ||
} | ||
|
||
query := u.Query() | ||
query.Add("filters", filters.Encode()) | ||
u.RawQuery = query.Encode() | ||
} | ||
|
||
return u, nil | ||
} | ||
|
||
// FilterAPIRequestBody generates the request body for Rules, replacing linked Objects with just their identifier. | ||
func (r *Rule) FilterAPIRequestBody(ctx context.Context) (interface{}, error) { | ||
return requestBody(ctx, func() interface{} { | ||
return &struct { | ||
commonRequestBody | ||
Rule | ||
Backend string `json:"backend,omitempty"` | ||
Frontend string `json:"frontend,omitempty"` | ||
}{ | ||
Rule: *r, | ||
Backend: r.Backend.Identifier, | ||
Frontend: r.Frontend.Identifier, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package v1 | ||
|
||
// anxcloud:object:hooks=RequestBodyHook | ||
|
||
// Rule represents an LBaaS Rule | ||
type Rule struct { | ||
commonMethods | ||
HasState | ||
|
||
CustomerIdentifier string `json:"customer_identifier"` | ||
ResellerIdentifier string `json:"reseller_identifier"` | ||
|
||
Identifier string `json:"identifier" anxcloud:"identifier"` | ||
Name string `json:"name"` | ||
ParentType string `json:"parent_type"` | ||
Index int `json:"index"` | ||
Condition string `json:"condition"` | ||
ConditionTest string `json:"condition_test"` | ||
Type string `json:"type"` | ||
Action string `json:"action"` | ||
RedirectionType string `json:"redirection_type"` | ||
RedirectionValue string `json:"redirection_value"` | ||
RedirectionCode string `json:"redirection_code"` | ||
RuleType string `json:"rule_type"` | ||
|
||
// Only the name and identifier fields are used and returned. | ||
Frontend Frontend `json:"frontend,omitempty"` | ||
Backend Backend `json:"backend,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters