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

feat(infrastructure_targets): add bulk endpoints #3706

Merged
merged 1 commit into from
Dec 6, 2024
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
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1448
configured_endpoints: 1450
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-0530d6510c5b139af850d24a4f932d5139c8d321a955ffa101b0debafbd75465.yml
3 changes: 3 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4818,6 +4818,7 @@ Response Types:
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetNewResponse">AccessInfrastructureTargetNewResponse</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetUpdateResponse">AccessInfrastructureTargetUpdateResponse</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetListResponse">AccessInfrastructureTargetListResponse</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetBulkUpdateResponse">AccessInfrastructureTargetBulkUpdateResponse</a>
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetGetResponse">AccessInfrastructureTargetGetResponse</a>

Methods:
Expand All @@ -4826,6 +4827,8 @@ Methods:
- <code title="put /accounts/{account_id}/infrastructure/targets/{target_id}">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, targetID <a href="https://pkg.go.dev/builtin#string">string</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetUpdateParams">AccessInfrastructureTargetUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetUpdateResponse">AccessInfrastructureTargetUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /accounts/{account_id}/infrastructure/targets">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetListParams">AccessInfrastructureTargetListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/packages/pagination#V4PagePaginationArray">V4PagePaginationArray</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetListResponse">AccessInfrastructureTargetListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /accounts/{account_id}/infrastructure/targets/{target_id}">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, targetID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetDeleteParams">AccessInfrastructureTargetDeleteParams</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
- <code title="delete /accounts/{account_id}/infrastructure/targets/batch">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.BulkDelete">BulkDelete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetBulkDeleteParams">AccessInfrastructureTargetBulkDeleteParams</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
- <code title="put /accounts/{account_id}/infrastructure/targets/batch">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.BulkUpdate">BulkUpdate</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetBulkUpdateParams">AccessInfrastructureTargetBulkUpdateParams</a>) ([]<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetBulkUpdateResponse">AccessInfrastructureTargetBulkUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /accounts/{account_id}/infrastructure/targets/{target_id}">client.ZeroTrust.Access.Infrastructure.Targets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, targetID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetGetParams">AccessInfrastructureTargetGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust">zero_trust</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/zero_trust#AccessInfrastructureTargetGetResponse">AccessInfrastructureTargetGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

### Applications
Expand Down
205 changes: 205 additions & 0 deletions zero_trust/accessinfrastructuretarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ func (r *AccessInfrastructureTargetService) Delete(ctx context.Context, targetID
return
}

// Removes one or more targets.
func (r *AccessInfrastructureTargetService) BulkDelete(ctx context.Context, body AccessInfrastructureTargetBulkDeleteParams, opts ...option.RequestOption) (err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
if body.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/infrastructure/targets/batch", body.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}

// Adds one or more targets.
func (r *AccessInfrastructureTargetService) BulkUpdate(ctx context.Context, params AccessInfrastructureTargetBulkUpdateParams, opts ...option.RequestOption) (res *[]AccessInfrastructureTargetBulkUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/infrastructure/targets/batch", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &res, opts...)
return
}

// Get target
func (r *AccessInfrastructureTargetService) Get(ctx context.Context, targetID string, query AccessInfrastructureTargetGetParams, opts ...option.RequestOption) (res *AccessInfrastructureTargetGetResponse, err error) {
var env AccessInfrastructureTargetGetResponseEnvelope
Expand Down Expand Up @@ -483,6 +508,120 @@ func (r accessInfrastructureTargetListResponseIpipv6JSON) RawJSON() string {
return r.raw
}

type AccessInfrastructureTargetBulkUpdateResponse struct {
// Target identifier
ID string `json:"id,required" format:"uuid"`
// Date and time at which the target was created
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A non-unique field that refers to a target
Hostname string `json:"hostname,required"`
// The IPv4/IPv6 address that identifies where to reach a target
IP AccessInfrastructureTargetBulkUpdateResponseIP `json:"ip,required"`
// Date and time at which the target was modified
ModifiedAt time.Time `json:"modified_at,required" format:"date-time"`
JSON accessInfrastructureTargetBulkUpdateResponseJSON `json:"-"`
}

// accessInfrastructureTargetBulkUpdateResponseJSON contains the JSON metadata for
// the struct [AccessInfrastructureTargetBulkUpdateResponse]
type accessInfrastructureTargetBulkUpdateResponseJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Hostname apijson.Field
IP apijson.Field
ModifiedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AccessInfrastructureTargetBulkUpdateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r accessInfrastructureTargetBulkUpdateResponseJSON) RawJSON() string {
return r.raw
}

// The IPv4/IPv6 address that identifies where to reach a target
type AccessInfrastructureTargetBulkUpdateResponseIP struct {
// The target's IPv4 address
IPV4 AccessInfrastructureTargetBulkUpdateResponseIPIPV4 `json:"ipv4"`
// The target's IPv6 address
IPV6 AccessInfrastructureTargetBulkUpdateResponseIPIPV6 `json:"ipv6"`
JSON accessInfrastructureTargetBulkUpdateResponseIPJSON `json:"-"`
}

// accessInfrastructureTargetBulkUpdateResponseIPJSON contains the JSON metadata
// for the struct [AccessInfrastructureTargetBulkUpdateResponseIP]
type accessInfrastructureTargetBulkUpdateResponseIPJSON struct {
IPV4 apijson.Field
IPV6 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AccessInfrastructureTargetBulkUpdateResponseIP) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r accessInfrastructureTargetBulkUpdateResponseIPJSON) RawJSON() string {
return r.raw
}

// The target's IPv4 address
type AccessInfrastructureTargetBulkUpdateResponseIPIPV4 struct {
// IP address of the target
IPAddr string `json:"ip_addr"`
// (optional) Private virtual network identifier for the target. If omitted, the
// default virtual network ID will be used.
VirtualNetworkID string `json:"virtual_network_id" format:"uuid"`
JSON accessInfrastructureTargetBulkUpdateResponseIpipv4JSON `json:"-"`
}

// accessInfrastructureTargetBulkUpdateResponseIpipv4JSON contains the JSON
// metadata for the struct [AccessInfrastructureTargetBulkUpdateResponseIPIPV4]
type accessInfrastructureTargetBulkUpdateResponseIpipv4JSON struct {
IPAddr apijson.Field
VirtualNetworkID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AccessInfrastructureTargetBulkUpdateResponseIPIPV4) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r accessInfrastructureTargetBulkUpdateResponseIpipv4JSON) RawJSON() string {
return r.raw
}

// The target's IPv6 address
type AccessInfrastructureTargetBulkUpdateResponseIPIPV6 struct {
// IP address of the target
IPAddr string `json:"ip_addr"`
// (optional) Private virtual network identifier for the target. If omitted, the
// default virtual network ID will be used.
VirtualNetworkID string `json:"virtual_network_id" format:"uuid"`
JSON accessInfrastructureTargetBulkUpdateResponseIpipv6JSON `json:"-"`
}

// accessInfrastructureTargetBulkUpdateResponseIpipv6JSON contains the JSON
// metadata for the struct [AccessInfrastructureTargetBulkUpdateResponseIPIPV6]
type accessInfrastructureTargetBulkUpdateResponseIpipv6JSON struct {
IPAddr apijson.Field
VirtualNetworkID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AccessInfrastructureTargetBulkUpdateResponseIPIPV6) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r accessInfrastructureTargetBulkUpdateResponseIpipv6JSON) RawJSON() string {
return r.raw
}

type AccessInfrastructureTargetGetResponse struct {
// Target identifier
ID string `json:"id,required" format:"uuid"`
Expand Down Expand Up @@ -826,6 +965,72 @@ type AccessInfrastructureTargetDeleteParams struct {
AccountID param.Field[string] `path:"account_id,required"`
}

type AccessInfrastructureTargetBulkDeleteParams struct {
// Account identifier
AccountID param.Field[string] `path:"account_id,required"`
}

type AccessInfrastructureTargetBulkUpdateParams struct {
// Account identifier
AccountID param.Field[string] `path:"account_id,required"`
Body []AccessInfrastructureTargetBulkUpdateParamsBody `json:"body,required"`
}

func (r AccessInfrastructureTargetBulkUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}

type AccessInfrastructureTargetBulkUpdateParamsBody struct {
// A non-unique field that refers to a target. Case insensitive, maximum length of
// 255 characters, supports the use of special characters dash and period, does not
// support spaces, and must start and end with an alphanumeric character.
Hostname param.Field[string] `json:"hostname,required"`
// The IPv4/IPv6 address that identifies where to reach a target
IP param.Field[AccessInfrastructureTargetBulkUpdateParamsBodyIP] `json:"ip,required"`
}

func (r AccessInfrastructureTargetBulkUpdateParamsBody) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The IPv4/IPv6 address that identifies where to reach a target
type AccessInfrastructureTargetBulkUpdateParamsBodyIP struct {
// The target's IPv4 address
IPV4 param.Field[AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV4] `json:"ipv4"`
// The target's IPv6 address
IPV6 param.Field[AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV6] `json:"ipv6"`
}

func (r AccessInfrastructureTargetBulkUpdateParamsBodyIP) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The target's IPv4 address
type AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV4 struct {
// IP address of the target
IPAddr param.Field[string] `json:"ip_addr"`
// (optional) Private virtual network identifier for the target. If omitted, the
// default virtual network ID will be used.
VirtualNetworkID param.Field[string] `json:"virtual_network_id" format:"uuid"`
}

func (r AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV4) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The target's IPv6 address
type AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV6 struct {
// IP address of the target
IPAddr param.Field[string] `json:"ip_addr"`
// (optional) Private virtual network identifier for the target. If omitted, the
// default virtual network ID will be used.
VirtualNetworkID param.Field[string] `json:"virtual_network_id" format:"uuid"`
}

func (r AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV6) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type AccessInfrastructureTargetGetParams struct {
// Account identifier
AccountID param.Field[string] `path:"account_id,required"`
Expand Down
63 changes: 63 additions & 0 deletions zero_trust/accessinfrastructuretarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,69 @@ func TestAccessInfrastructureTargetDelete(t *testing.T) {
}
}

func TestAccessInfrastructureTargetBulkDelete(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := cloudflare.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
err := client.ZeroTrust.Access.Infrastructure.Targets.BulkDelete(context.TODO(), zero_trust.AccessInfrastructureTargetBulkDeleteParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
})
if err != nil {
var apierr *cloudflare.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestAccessInfrastructureTargetBulkUpdate(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := cloudflare.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.ZeroTrust.Access.Infrastructure.Targets.BulkUpdate(context.TODO(), zero_trust.AccessInfrastructureTargetBulkUpdateParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Body: []zero_trust.AccessInfrastructureTargetBulkUpdateParamsBody{{
Hostname: cloudflare.F("infra-access-target"),
IP: cloudflare.F(zero_trust.AccessInfrastructureTargetBulkUpdateParamsBodyIP{
IPV4: cloudflare.F(zero_trust.AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV4{
IPAddr: cloudflare.F("187.26.29.249"),
VirtualNetworkID: cloudflare.F("c77b744e-acc8-428f-9257-6878c046ed55"),
}),
IPV6: cloudflare.F(zero_trust.AccessInfrastructureTargetBulkUpdateParamsBodyIPIPV6{
IPAddr: cloudflare.F("64c0:64e8:f0b4:8dbf:7104:72b0:ec8f:f5e0"),
VirtualNetworkID: cloudflare.F("c77b744e-acc8-428f-9257-6878c046ed55"),
}),
}),
}},
})
if err != nil {
var apierr *cloudflare.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestAccessInfrastructureTargetGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand Down