Skip to content

Commit

Permalink
Merge pull request #47 from G-Core/feature/CDI-468_add_origin_shielding
Browse files Browse the repository at this point in the history
CDI-468: add origin shielding
  • Loading branch information
anton-sharonov authored Feb 1, 2024
2 parents 340eab7 + 409a2c1 commit ae65348
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
27 changes: 17 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gcdn
import (
"github.com/G-Core/gcorelabscdn-go/gcore"
"github.com/G-Core/gcorelabscdn-go/origingroups"
"github.com/G-Core/gcorelabscdn-go/originshielding"
"github.com/G-Core/gcorelabscdn-go/resources"
"github.com/G-Core/gcorelabscdn-go/rules"
"github.com/G-Core/gcorelabscdn-go/sslcerts"
Expand All @@ -18,20 +19,22 @@ type ClientService interface {
var _ ClientService = (*Service)(nil)

type Service struct {
r gcore.Requester
resourcesService resources.ResourceService
rulesService rules.RulesService
originGroupsService origingroups.OriginGroupService
sslCertsService sslcerts.SSLCertService
r gcore.Requester
resourcesService resources.ResourceService
rulesService rules.RulesService
originGroupsService origingroups.OriginGroupService
originShieldingService originshielding.OriginShieldingService
sslCertsService sslcerts.SSLCertService
}

func NewService(r gcore.Requester) *Service {
return &Service{
r: r,
resourcesService: resources.NewService(r),
rulesService: rules.NewService(r),
originGroupsService: origingroups.NewService(r),
sslCertsService: sslcerts.NewService(r),
r: r,
resourcesService: resources.NewService(r),
rulesService: rules.NewService(r),
originGroupsService: origingroups.NewService(r),
originShieldingService: originshielding.NewService(r),
sslCertsService: sslcerts.NewService(r),
}
}

Expand All @@ -47,6 +50,10 @@ func (s *Service) OriginGroups() origingroups.OriginGroupService {
return s.originGroupsService
}

func (s *Service) OriginShielding() originshielding.OriginShieldingService {
return s.originShieldingService
}

func (s *Service) SSLCerts() sslcerts.SSLCertService {
return s.sslCertsService
}
26 changes: 26 additions & 0 deletions originshielding/originshielding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package originshielding

import (
"context"
)

type OriginShieldingService interface {
Update(ctx context.Context, id int64, req *UpdateRequest) (*OriginShieldingData, error)
Get(ctx context.Context, id int64) (*OriginShieldingData, error)
GetLocations(ctx context.Context) (*OriginShieldingLocations, error)
}

type OriginShieldingData struct {
ShieldingPop int `json:"shielding_pop"`
}

type UpdateRequest struct {
ShieldingPop int `json:"shielding_pop"`
}

type OriginShieldingLocations struct {
ID int `json:"id"`
Datacenter string `json:"datacenter"`
Country string `json:"country"`
City string `json:"city"`
}
45 changes: 45 additions & 0 deletions originshielding/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package originshielding

import (
"context"
"fmt"
"github.com/G-Core/gcorelabscdn-go/gcore"
"net/http"
)

var _ OriginShieldingService = (*Service)(nil)

type Service struct {
r gcore.Requester
}

func NewService(r gcore.Requester) *Service {
return &Service{r: r}
}

func (s *Service) Update(ctx context.Context, id int64, req *UpdateRequest) (*OriginShieldingData, error) {
var origin_shielding OriginShieldingData
if err := s.r.Request(ctx, http.MethodPut, fmt.Sprintf("/cdn/resources/%d/shielding_v2", id), req, &origin_shielding); err != nil {
return nil, fmt.Errorf("request: %w", err)
}
return &origin_shielding, nil
}

func (s *Service) Get(ctx context.Context, id int64) (*OriginShieldingData, error) {
var origin_shielding OriginShieldingData
if err := s.r.Request(ctx, http.MethodGet, fmt.Sprintf("/cdn/resources/%d/shielding_v2", id), nil, &origin_shielding); err != nil {
return nil, fmt.Errorf("request: %w", err)
}

return &origin_shielding, nil

}

func (s *Service) GetLocations(ctx context.Context) (*OriginShieldingLocations, error) {
var origin_shielding_locations OriginShieldingLocations
if err := s.r.Request(ctx, http.MethodGet, "/cdn/shieldingpop_v2", nil, &origin_shielding_locations); err != nil {
return nil, fmt.Errorf("request: %w", err)
}

return &origin_shielding_locations, nil
}

0 comments on commit ae65348

Please sign in to comment.