diff --git a/api/vpc/v2/vpc_sdk.go b/api/vpc/v2/vpc_sdk.go index db24f68c9..d19059bc2 100644 --- a/api/vpc/v2/vpc_sdk.go +++ b/api/vpc/v2/vpc_sdk.go @@ -306,23 +306,34 @@ type PrivateNetwork struct { // Route: route. type Route struct { + // ID: route ID. ID string `json:"id"` - CreatedAt *time.Time `json:"created_at"` + // Description: route description. + Description string `json:"description"` + // Tags: tags of the Route. + Tags []string `json:"tags"` + + // VpcID: vPC the Route belongs to. VpcID string `json:"vpc_id"` + // Destination: destination of the Route. Destination scw.IPNet `json:"destination"` + // NexthopResourceID: ID of the nexthop resource. NexthopResourceID *string `json:"nexthop_resource_id"` + // NexthopPrivateNetworkID: ID of the nexthop private network. NexthopPrivateNetworkID *string `json:"nexthop_private_network_id"` - Tags []string `json:"tags"` + // CreatedAt: date the Route was created. + CreatedAt *time.Time `json:"created_at"` - Description string `json:"description"` + // UpdatedAt: date the Route was last modified. + UpdatedAt *time.Time `json:"updated_at"` - // Region: region to target. If none is passed will use default region from the config. + // Region: region of the Route. Region scw.Region `json:"region"` } @@ -416,6 +427,30 @@ type CreatePrivateNetworkRequest struct { VpcID *string `json:"vpc_id,omitempty"` } +// CreateRouteRequest: create route request. +type CreateRouteRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // Description: route description. + Description string `json:"description"` + + // Tags: tags of the Route. + Tags []string `json:"tags"` + + // VpcID: vPC the Route belongs to. + VpcID string `json:"vpc_id"` + + // Destination: destination of the Route. + Destination scw.IPNet `json:"destination"` + + // NexthopResourceID: ID of the nexthop resource. + NexthopResourceID *string `json:"nexthop_resource_id,omitempty"` + + // NexthopPrivateNetworkID: ID of the nexthop private network. + NexthopPrivateNetworkID *string `json:"nexthop_private_network_id,omitempty"` +} + // CreateVPCRequest: create vpc request. type CreateVPCRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -443,6 +478,15 @@ type DeletePrivateNetworkRequest struct { PrivateNetworkID string `json:"-"` } +// DeleteRouteRequest: delete route request. +type DeleteRouteRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // RouteID: route ID. + RouteID string `json:"-"` +} + // DeleteSubnetsRequest: delete subnets request. type DeleteSubnetsRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -495,6 +539,15 @@ type GetPrivateNetworkRequest struct { PrivateNetworkID string `json:"-"` } +// GetRouteRequest: get route request. +type GetRouteRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // RouteID: route ID. + RouteID string `json:"-"` +} + // GetVPCRequest: get vpc request. type GetVPCRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -796,6 +849,30 @@ type UpdatePrivateNetworkRequest struct { Tags *[]string `json:"tags,omitempty"` } +// UpdateRouteRequest: update route request. +type UpdateRouteRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // RouteID: route ID. + RouteID string `json:"-"` + + // Description: route description. + Description *string `json:"description,omitempty"` + + // Tags: tags of the Route. + Tags *[]string `json:"tags,omitempty"` + + // Destination: destination of the Route. + Destination *scw.IPNet `json:"destination,omitempty"` + + // NexthopResourceID: ID of the nexthop resource. + NexthopResourceID *string `json:"nexthop_resource_id,omitempty"` + + // NexthopPrivateNetworkID: ID of the nexthop private network. + NexthopPrivateNetworkID *string `json:"nexthop_private_network_id,omitempty"` +} + // UpdateVPCRequest: update vpc request. type UpdateVPCRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -1451,6 +1528,134 @@ func (s *API) DeleteSubnets(req *DeleteSubnetsRequest, opts ...scw.RequestOption return &resp, nil } +// CreateRoute: Create a new custom Route. +func (s *API) CreateRoute(req *CreateRouteRequest, opts ...scw.RequestOption) (*Route, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/routes", + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Route + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// GetRoute: Retrieve details of an existing Route, specified by its Route ID. +func (s *API) GetRoute(req *GetRouteRequest, opts ...scw.RequestOption) (*Route, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.RouteID) == "" { + return nil, errors.New("field RouteID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "GET", + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/routes/" + fmt.Sprint(req.RouteID) + "", + } + + var resp Route + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// UpdateRoute: Update parameters of the specified Route. +func (s *API) UpdateRoute(req *UpdateRouteRequest, opts ...scw.RequestOption) (*Route, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.RouteID) == "" { + return nil, errors.New("field RouteID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "PATCH", + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/routes/" + fmt.Sprint(req.RouteID) + "", + } + + err = scwReq.SetBody(req) + if err != nil { + return nil, err + } + + var resp Route + + err = s.client.Do(scwReq, &resp, opts...) + if err != nil { + return nil, err + } + return &resp, nil +} + +// DeleteRoute: Delete a Route specified by its Route ID. +func (s *API) DeleteRoute(req *DeleteRouteRequest, opts ...scw.RequestOption) error { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.RouteID) == "" { + return errors.New("field RouteID cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "DELETE", + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/routes/" + fmt.Sprint(req.RouteID) + "", + } + + err = s.client.Do(scwReq, nil, opts...) + if err != nil { + return err + } + return nil +} + type RoutesWithNexthopAPI struct { client *scw.Client }