Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go SDK for Router Firewall Groups #27

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 82 additions & 22 deletions pkg/client/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (r *RouterAPIService) GetAllRouter(
queryParams map[string]string,
) (models.GetAllNetworkRouter, error) {
routerResp := models.GetAllNetworkRouter{}
serverAPI := &api{
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworksPath, consts.NetworkRouterPath),
Expand All @@ -30,7 +30,7 @@ func (r *RouterAPIService) GetAllRouter(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, nil, queryParams)
err := routerAPI.do(ctx, nil, queryParams)

return routerResp, err
}
Expand All @@ -40,7 +40,7 @@ func (r *RouterAPIService) GetSpecificRouter(
routerID int,
) (models.GetNetworkRouter, error) {
routerResp := models.GetNetworkRouter{}
serverAPI := &api{
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s/%s/%d", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworksPath, consts.NetworkRouterPath, routerID),
Expand All @@ -49,7 +49,7 @@ func (r *RouterAPIService) GetSpecificRouter(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, nil, nil)
err := routerAPI.do(ctx, nil, nil)

return routerResp, err
}
Expand All @@ -59,7 +59,7 @@ func (r *RouterAPIService) CreateRouter(
request models.CreateRouterRequest,
) (models.CreateRouterResp, error) {
routerResp := models.CreateRouterResp{}
serverAPI := &api{
routerAPI := &api{
method: "POST",
path: fmt.Sprintf("%s/%s/%s/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworksPath, consts.NetworkRouterPath),
Expand All @@ -68,7 +68,7 @@ func (r *RouterAPIService) CreateRouter(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, request, nil)
err := routerAPI.do(ctx, request, nil)

return routerResp, err
}
Expand All @@ -79,7 +79,7 @@ func (r *RouterAPIService) UpdateRouter(
request models.CreateRouterRequest,
) (models.SuccessOrErrorMessage, error) {
routerResp := models.SuccessOrErrorMessage{}
serverAPI := &api{
routerAPI := &api{
method: "PUT",
path: fmt.Sprintf("%s/%s/%s/%s/%d", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworksPath, consts.NetworkRouterPath, routerID),
Expand All @@ -88,7 +88,7 @@ func (r *RouterAPIService) UpdateRouter(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, request, nil)
err := routerAPI.do(ctx, request, nil)

return routerResp, err
}
Expand All @@ -98,7 +98,7 @@ func (r *RouterAPIService) DeleteRouter(
routerID int,
) (models.SuccessOrErrorMessage, error) {
routerResp := models.SuccessOrErrorMessage{}
serverAPI := &api{
routerAPI := &api{
method: "DELETE",
path: fmt.Sprintf("%s/%s/%s/%s/%d", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworksPath, consts.NetworkRouterPath, routerID),
Expand All @@ -107,7 +107,7 @@ func (r *RouterAPIService) DeleteRouter(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, nil, nil)
err := routerAPI.do(ctx, nil, nil)

return routerResp, err
}
Expand All @@ -117,7 +117,7 @@ func (r *RouterAPIService) GetRouterTypes(
queryParams map[string]string,
) (models.GetNetworlRouterTypes, error) {
routerResp := models.GetNetworlRouterTypes{}
serverAPI := &api{
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath,
consts.NetworkRouterTypePath),
Expand All @@ -126,7 +126,7 @@ func (r *RouterAPIService) GetRouterTypes(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, nil, queryParams)
err := routerAPI.do(ctx, nil, queryParams)

return routerResp, err
}
Expand All @@ -136,7 +136,7 @@ func (r *RouterAPIService) GetNetworkServices(
queryParams map[string]string,
) (models.GetNetworkServicesResp, error) {
routerResp := models.GetNetworkServicesResp{}
serverAPI := &api{
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
consts.NetworkServicePath),
Expand All @@ -145,7 +145,7 @@ func (r *RouterAPIService) GetNetworkServices(
return json.Unmarshal(body, &routerResp)
},
}
err := serverAPI.do(ctx, nil, queryParams)
err := routerAPI.do(ctx, nil, queryParams)

return routerResp, err
}
Expand All @@ -156,7 +156,7 @@ func (r *RouterAPIService) CreateRouterNat(
request models.CreateRouterNatRequest,
) (models.CreateRouterNatResponse, error) {
natResp := models.CreateRouterNatResponse{}
serverAPI := &api{
routerAPI := &api{
method: "POST",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
consts.NetworkRouterPath, routerID, consts.RoutersNatPath),
Expand All @@ -165,7 +165,7 @@ func (r *RouterAPIService) CreateRouterNat(
return json.Unmarshal(body, &natResp)
},
}
err := serverAPI.do(ctx, request, nil)
err := routerAPI.do(ctx, request, nil)

return natResp, err
}
Expand All @@ -175,7 +175,7 @@ func (r *RouterAPIService) GetSpecificRouterNat(
routerID, natID int,
) (models.GetSpecificRouterNatResponse, error) {
natResp := models.GetSpecificRouterNatResponse{}
serverAPI := &api{
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s/%d",
r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
Expand All @@ -185,7 +185,7 @@ func (r *RouterAPIService) GetSpecificRouterNat(
return json.Unmarshal(body, &natResp)
},
}
err := serverAPI.do(ctx, nil, nil)
err := routerAPI.do(ctx, nil, nil)

return natResp, err
}
Expand All @@ -196,7 +196,7 @@ func (r *RouterAPIService) UpdateRouterNat(
req models.CreateRouterNatRequest,
) (models.CreateRouterNatResponse, error) {
natResp := models.CreateRouterNatResponse{}
serverAPI := &api{
routerAPI := &api{
method: "PUT",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s/%d",
r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
Expand All @@ -206,7 +206,7 @@ func (r *RouterAPIService) UpdateRouterNat(
return json.Unmarshal(body, &natResp)
},
}
err := serverAPI.do(ctx, req, nil)
err := routerAPI.do(ctx, req, nil)

return natResp, err
}
Expand All @@ -216,7 +216,7 @@ func (r *RouterAPIService) DeleteRouterNat(
routerID, natID int,
) (models.SuccessOrErrorMessage, error) {
natResp := models.SuccessOrErrorMessage{}
serverAPI := &api{
routerAPI := &api{
method: "DELETE",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s/%d",
r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
Expand All @@ -226,7 +226,67 @@ func (r *RouterAPIService) DeleteRouterNat(
return json.Unmarshal(body, &natResp)
},
}
err := serverAPI.do(ctx, nil, nil)
err := routerAPI.do(ctx, nil, nil)

return natResp, err
}

func (r *RouterAPIService) CreateRouterFirewallRuleGroup(
ctx context.Context,
routerID int,
request models.CreateRouterFirewallRuleGroupRequest,
) (models.CreateRouterFirewallRuleGroupResponse, error) {
firewallGroupResp := models.CreateRouterFirewallRuleGroupResponse{}
routerAPI := &api{
method: "POST",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s", r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
consts.NetworkRouterPath, routerID, consts.RoutersFirewallRuleGroupPath),
client: r.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &firewallGroupResp)
},
}
err := routerAPI.do(ctx, request, nil)

return firewallGroupResp, err
}

func (r *RouterAPIService) GetSpecificRouterFirewallRuleGroup(
ctx context.Context,
routerID, firewallGroupID int,
) (models.GetSpecificRouterFirewallRuleGroupResponse, error) {
firewallGroupResp := models.GetSpecificRouterFirewallRuleGroupResponse{}
routerAPI := &api{
method: "GET",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s/%d",
r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
consts.NetworkRouterPath, routerID, consts.RoutersFirewallRuleGroupPath, firewallGroupID),
client: r.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &firewallGroupResp)
},
}
err := routerAPI.do(ctx, nil, nil)

return firewallGroupResp, err
}

func (r *RouterAPIService) DeleteRouterFirewallRuleGroup(
ctx context.Context,
routerID, firewallGroupID int,
) (models.SuccessOrErrorMessage, error) {
firewallGroupResp := models.SuccessOrErrorMessage{}
routerAPI := &api{
method: "DELETE",
path: fmt.Sprintf("%s/%s/%s/%s/%d/%s/%d",
r.Cfg.Host, consts.VmaasCmpAPIBasePath, consts.NetworksPath,
consts.NetworkRouterPath, routerID, consts.RoutersFirewallRuleGroupPath, firewallGroupID),
client: r.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &firewallGroupResp)
},
}
err := routerAPI.do(ctx, nil, nil)

return firewallGroupResp, err
}
Loading