From 81ca352e0f57c00b18bea8c87225e0a2d7217f70 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Fri, 22 Mar 2024 00:41:34 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- .stats.yml | 2 +- api.md | 49 ++ magic_network_monitoring/config.go | 566 ++++++++++++++ magic_network_monitoring/config_test.go | 145 ++++ magic_network_monitoring/configfull.go | 113 +++ magic_network_monitoring/configfull_test.go | 41 + magic_network_monitoring/rule.go | 725 ++++++++++++++++++ magic_network_monitoring/rule_test.go | 183 +++++ magic_network_monitoring/ruleadvertisement.go | 137 ++++ .../ruleadvertisement_test.go | 45 ++ zones/dnssetting.go | 399 ++++++++++ zones/dnssetting_test.go | 70 ++ zones/zone.go | 2 + 13 files changed, 2476 insertions(+), 1 deletion(-) create mode 100644 magic_network_monitoring/config_test.go create mode 100644 magic_network_monitoring/configfull_test.go create mode 100644 magic_network_monitoring/rule_test.go create mode 100644 magic_network_monitoring/ruleadvertisement_test.go create mode 100644 zones/dnssetting.go create mode 100644 zones/dnssetting_test.go diff --git a/.stats.yml b/.stats.yml index 1c34ce1f747..81d04672fb2 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 1275 +configured_endpoints: 1290 diff --git a/api.md b/api.md index 9d704228b1b..b6f15a87ac6 100644 --- a/api.md +++ b/api.md @@ -321,6 +321,18 @@ Methods: - client.Zones.ActivationCheck.Trigger(ctx context.Context, body zones.ActivationCheckTriggerParams) (zones.ActivationCheckTriggerResponse, error) +## DNSSettings + +Response Types: + +- zones.DNSSettingEditResponse +- zones.DNSSettingGetResponse + +Methods: + +- client.Zones.DNSSettings.Edit(ctx context.Context, params zones.DNSSettingEditParams) (zones.DNSSettingEditResponse, error) +- client.Zones.DNSSettings.Get(ctx context.Context, query zones.DNSSettingGetParams) (zones.DNSSettingGetResponse, error) + ## Settings Response Types: @@ -3524,12 +3536,49 @@ Methods: ## Configs +Response Types: + +- magic_network_monitoring.MagicVisibilityMNMConfig + +Methods: + +- client.MagicNetworkMonitoring.Configs.New(ctx context.Context, body magic_network_monitoring.ConfigNewParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) +- client.MagicNetworkMonitoring.Configs.Update(ctx context.Context, body magic_network_monitoring.ConfigUpdateParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) +- client.MagicNetworkMonitoring.Configs.Delete(ctx context.Context, body magic_network_monitoring.ConfigDeleteParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) +- client.MagicNetworkMonitoring.Configs.Edit(ctx context.Context, body magic_network_monitoring.ConfigEditParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) +- client.MagicNetworkMonitoring.Configs.Get(ctx context.Context, query magic_network_monitoring.ConfigGetParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) + ### Full +Methods: + +- client.MagicNetworkMonitoring.Configs.Full.Get(ctx context.Context, query magic_network_monitoring.ConfigFullGetParams) (magic_network_monitoring.MagicVisibilityMNMConfig, error) + ## Rules +Response Types: + +- magic_network_monitoring.MagicVisibilityMNMRule + +Methods: + +- client.MagicNetworkMonitoring.Rules.New(ctx context.Context, body magic_network_monitoring.RuleNewParams) (magic_network_monitoring.MagicVisibilityMNMRule, error) +- client.MagicNetworkMonitoring.Rules.Update(ctx context.Context, body magic_network_monitoring.RuleUpdateParams) (magic_network_monitoring.MagicVisibilityMNMRule, error) +- client.MagicNetworkMonitoring.Rules.List(ctx context.Context, query magic_network_monitoring.RuleListParams) ([]magic_network_monitoring.MagicVisibilityMNMRule, error) +- client.MagicNetworkMonitoring.Rules.Delete(ctx context.Context, ruleID interface{}, body magic_network_monitoring.RuleDeleteParams) (magic_network_monitoring.MagicVisibilityMNMRule, error) +- client.MagicNetworkMonitoring.Rules.Edit(ctx context.Context, ruleID interface{}, body magic_network_monitoring.RuleEditParams) (magic_network_monitoring.MagicVisibilityMNMRule, error) +- client.MagicNetworkMonitoring.Rules.Get(ctx context.Context, ruleID interface{}, query magic_network_monitoring.RuleGetParams) (magic_network_monitoring.MagicVisibilityMNMRule, error) + ### Advertisements +Response Types: + +- magic_network_monitoring.MagicVisibilityMNMRuleAdvertisable + +Methods: + +- client.MagicNetworkMonitoring.Rules.Advertisements.Edit(ctx context.Context, ruleID interface{}, body magic_network_monitoring.RuleAdvertisementEditParams) (magic_network_monitoring.MagicVisibilityMNMRuleAdvertisable, error) + # MTLSCertificates Response Types: diff --git a/magic_network_monitoring/config.go b/magic_network_monitoring/config.go index 69504a79195..4549d171b44 100644 --- a/magic_network_monitoring/config.go +++ b/magic_network_monitoring/config.go @@ -3,6 +3,13 @@ package magic_network_monitoring import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" ) @@ -24,3 +31,562 @@ func NewConfigService(opts ...option.RequestOption) (r *ConfigService) { r.Full = NewConfigFullService(opts...) return } + +// Create a new network monitoring configuration. +func (r *ConfigService) New(ctx context.Context, body ConfigNewParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigNewResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Update an existing network monitoring configuration, requires the entire +// configuration to be updated at once. +func (r *ConfigService) Update(ctx context.Context, body ConfigUpdateParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigUpdateResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Delete an existing network monitoring configuration. +func (r *ConfigService) Delete(ctx context.Context, body ConfigDeleteParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigDeleteResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Update fields in an existing network monitoring configuration. +func (r *ConfigService) Edit(ctx context.Context, body ConfigEditParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigEditResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Lists default sampling and router IPs for account. +func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigGetResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config", query.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type MagicVisibilityMNMConfig struct { + // Fallback sampling rate of flow messages being sent in packets per second. This + // should match the packet sampling rate configured on the router. + DefaultSampling float64 `json:"default_sampling,required"` + // The account name. + Name string `json:"name,required"` + RouterIPs []string `json:"router_ips,required"` + JSON magicVisibilityMNMConfigJSON `json:"-"` +} + +// magicVisibilityMNMConfigJSON contains the JSON metadata for the struct +// [MagicVisibilityMNMConfig] +type magicVisibilityMNMConfigJSON struct { + DefaultSampling apijson.Field + Name apijson.Field + RouterIPs apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *MagicVisibilityMNMConfig) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r magicVisibilityMNMConfigJSON) RawJSON() string { + return r.raw +} + +type ConfigNewParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigNewResponseEnvelope struct { + Errors []ConfigNewResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigNewResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigNewResponseEnvelopeSuccess `json:"success,required"` + JSON configNewResponseEnvelopeJSON `json:"-"` +} + +// configNewResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigNewResponseEnvelope] +type configNewResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configNewResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigNewResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configNewResponseEnvelopeErrorsJSON `json:"-"` +} + +// configNewResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [ConfigNewResponseEnvelopeErrors] +type configNewResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigNewResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configNewResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigNewResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configNewResponseEnvelopeMessagesJSON `json:"-"` +} + +// configNewResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [ConfigNewResponseEnvelopeMessages] +type configNewResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigNewResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configNewResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigNewResponseEnvelopeSuccess bool + +const ( + ConfigNewResponseEnvelopeSuccessTrue ConfigNewResponseEnvelopeSuccess = true +) + +func (r ConfigNewResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigNewResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type ConfigUpdateParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigUpdateResponseEnvelope struct { + Errors []ConfigUpdateResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigUpdateResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigUpdateResponseEnvelopeSuccess `json:"success,required"` + JSON configUpdateResponseEnvelopeJSON `json:"-"` +} + +// configUpdateResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigUpdateResponseEnvelope] +type configUpdateResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configUpdateResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigUpdateResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configUpdateResponseEnvelopeErrorsJSON `json:"-"` +} + +// configUpdateResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [ConfigUpdateResponseEnvelopeErrors] +type configUpdateResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigUpdateResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configUpdateResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigUpdateResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configUpdateResponseEnvelopeMessagesJSON `json:"-"` +} + +// configUpdateResponseEnvelopeMessagesJSON contains the JSON metadata for the +// struct [ConfigUpdateResponseEnvelopeMessages] +type configUpdateResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigUpdateResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configUpdateResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigUpdateResponseEnvelopeSuccess bool + +const ( + ConfigUpdateResponseEnvelopeSuccessTrue ConfigUpdateResponseEnvelopeSuccess = true +) + +func (r ConfigUpdateResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigUpdateResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type ConfigDeleteParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigDeleteResponseEnvelope struct { + Errors []ConfigDeleteResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigDeleteResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigDeleteResponseEnvelopeSuccess `json:"success,required"` + JSON configDeleteResponseEnvelopeJSON `json:"-"` +} + +// configDeleteResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigDeleteResponseEnvelope] +type configDeleteResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configDeleteResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigDeleteResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configDeleteResponseEnvelopeErrorsJSON `json:"-"` +} + +// configDeleteResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [ConfigDeleteResponseEnvelopeErrors] +type configDeleteResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigDeleteResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configDeleteResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigDeleteResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configDeleteResponseEnvelopeMessagesJSON `json:"-"` +} + +// configDeleteResponseEnvelopeMessagesJSON contains the JSON metadata for the +// struct [ConfigDeleteResponseEnvelopeMessages] +type configDeleteResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigDeleteResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configDeleteResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigDeleteResponseEnvelopeSuccess bool + +const ( + ConfigDeleteResponseEnvelopeSuccessTrue ConfigDeleteResponseEnvelopeSuccess = true +) + +func (r ConfigDeleteResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigDeleteResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type ConfigEditParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigEditResponseEnvelope struct { + Errors []ConfigEditResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigEditResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigEditResponseEnvelopeSuccess `json:"success,required"` + JSON configEditResponseEnvelopeJSON `json:"-"` +} + +// configEditResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigEditResponseEnvelope] +type configEditResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configEditResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigEditResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configEditResponseEnvelopeErrorsJSON `json:"-"` +} + +// configEditResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [ConfigEditResponseEnvelopeErrors] +type configEditResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigEditResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configEditResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigEditResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configEditResponseEnvelopeMessagesJSON `json:"-"` +} + +// configEditResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [ConfigEditResponseEnvelopeMessages] +type configEditResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigEditResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configEditResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigEditResponseEnvelopeSuccess bool + +const ( + ConfigEditResponseEnvelopeSuccessTrue ConfigEditResponseEnvelopeSuccess = true +) + +func (r ConfigEditResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigEditResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type ConfigGetParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigGetResponseEnvelope struct { + Errors []ConfigGetResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigGetResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigGetResponseEnvelopeSuccess `json:"success,required"` + JSON configGetResponseEnvelopeJSON `json:"-"` +} + +// configGetResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigGetResponseEnvelope] +type configGetResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configGetResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigGetResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configGetResponseEnvelopeErrorsJSON `json:"-"` +} + +// configGetResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [ConfigGetResponseEnvelopeErrors] +type configGetResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configGetResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigGetResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configGetResponseEnvelopeMessagesJSON `json:"-"` +} + +// configGetResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [ConfigGetResponseEnvelopeMessages] +type configGetResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configGetResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigGetResponseEnvelopeSuccess bool + +const ( + ConfigGetResponseEnvelopeSuccessTrue ConfigGetResponseEnvelopeSuccess = true +) + +func (r ConfigGetResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigGetResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/magic_network_monitoring/config_test.go b/magic_network_monitoring/config_test.go new file mode 100644 index 00000000000..c41c6194a9b --- /dev/null +++ b/magic_network_monitoring/config_test.go @@ -0,0 +1,145 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package magic_network_monitoring_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/magic_network_monitoring" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +func TestConfigNew(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.New(context.TODO(), magic_network_monitoring.ConfigNewParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestConfigUpdate(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.Update(context.TODO(), magic_network_monitoring.ConfigUpdateParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestConfigDelete(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.Delete(context.TODO(), magic_network_monitoring.ConfigDeleteParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestConfigEdit(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.Edit(context.TODO(), magic_network_monitoring.ConfigEditParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestConfigGet(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.Get(context.TODO(), magic_network_monitoring.ConfigGetParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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()) + } +} diff --git a/magic_network_monitoring/configfull.go b/magic_network_monitoring/configfull.go index c11af7f76c8..1f57b2f563b 100644 --- a/magic_network_monitoring/configfull.go +++ b/magic_network_monitoring/configfull.go @@ -3,6 +3,13 @@ package magic_network_monitoring import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" ) @@ -22,3 +29,109 @@ func NewConfigFullService(opts ...option.RequestOption) (r *ConfigFullService) { r.Options = opts return } + +// Lists default sampling, router IPs, and rules for account. +func (r *ConfigFullService) Get(ctx context.Context, query ConfigFullGetParams, opts ...option.RequestOption) (res *MagicVisibilityMNMConfig, err error) { + opts = append(r.Options[:], opts...) + var env ConfigFullGetResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/config/full", query.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type ConfigFullGetParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type ConfigFullGetResponseEnvelope struct { + Errors []ConfigFullGetResponseEnvelopeErrors `json:"errors,required"` + Messages []ConfigFullGetResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMConfig `json:"result,required"` + // Whether the API call was successful + Success ConfigFullGetResponseEnvelopeSuccess `json:"success,required"` + JSON configFullGetResponseEnvelopeJSON `json:"-"` +} + +// configFullGetResponseEnvelopeJSON contains the JSON metadata for the struct +// [ConfigFullGetResponseEnvelope] +type configFullGetResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigFullGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configFullGetResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type ConfigFullGetResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configFullGetResponseEnvelopeErrorsJSON `json:"-"` +} + +// configFullGetResponseEnvelopeErrorsJSON contains the JSON metadata for the +// struct [ConfigFullGetResponseEnvelopeErrors] +type configFullGetResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigFullGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configFullGetResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type ConfigFullGetResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON configFullGetResponseEnvelopeMessagesJSON `json:"-"` +} + +// configFullGetResponseEnvelopeMessagesJSON contains the JSON metadata for the +// struct [ConfigFullGetResponseEnvelopeMessages] +type configFullGetResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *ConfigFullGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r configFullGetResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type ConfigFullGetResponseEnvelopeSuccess bool + +const ( + ConfigFullGetResponseEnvelopeSuccessTrue ConfigFullGetResponseEnvelopeSuccess = true +) + +func (r ConfigFullGetResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case ConfigFullGetResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/magic_network_monitoring/configfull_test.go b/magic_network_monitoring/configfull_test.go new file mode 100644 index 00000000000..5bc91aa9f97 --- /dev/null +++ b/magic_network_monitoring/configfull_test.go @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package magic_network_monitoring_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/magic_network_monitoring" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +func TestConfigFullGet(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Configs.Full.Get(context.TODO(), magic_network_monitoring.ConfigFullGetParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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()) + } +} diff --git a/magic_network_monitoring/rule.go b/magic_network_monitoring/rule.go index f37c0d2b518..51c2e17c44a 100644 --- a/magic_network_monitoring/rule.go +++ b/magic_network_monitoring/rule.go @@ -3,6 +3,13 @@ package magic_network_monitoring import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" ) @@ -24,3 +31,721 @@ func NewRuleService(opts ...option.RequestOption) (r *RuleService) { r.Advertisements = NewRuleAdvertisementService(opts...) return } + +// Create network monitoring rules for account. Currently only supports creating a +// single rule per API request. +func (r *RuleService) New(ctx context.Context, body RuleNewParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleNewResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Update network monitoring rules for account. +func (r *RuleService) Update(ctx context.Context, body RuleUpdateParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleUpdateResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules", body.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Lists network monitoring rules for account. +func (r *RuleService) List(ctx context.Context, query RuleListParams, opts ...option.RequestOption) (res *[]MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleListResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules", query.AccountID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Delete a network monitoring rule for account. +func (r *RuleService) Delete(ctx context.Context, ruleID interface{}, body RuleDeleteParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleDeleteResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules/%v", body.AccountID, ruleID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Update a network monitoring rule for account. +func (r *RuleService) Edit(ctx context.Context, ruleID interface{}, body RuleEditParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleEditResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules/%v", body.AccountID, ruleID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// List a single network monitoring rule for account. +func (r *RuleService) Get(ctx context.Context, ruleID interface{}, query RuleGetParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRule, err error) { + opts = append(r.Options[:], opts...) + var env RuleGetResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules/%v", query.AccountID, ruleID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type MagicVisibilityMNMRule struct { + // Toggle on if you would like Cloudflare to automatically advertise the IP + // Prefixes within the rule via Magic Transit when the rule is triggered. Only + // available for users of Magic Transit. + AutomaticAdvertisement bool `json:"automatic_advertisement,required,nullable"` + // The amount of time that the rule threshold must be exceeded to send an alert + // notification. The final value must be equivalent to one of the following 8 + // values ["1m","5m","10m","15m","20m","30m","45m","60m"]. The format is + // AhBmCsDmsEusFns where A, B, C, D, E and F durations are optional; however at + // least one unit must be provided. + Duration string `json:"duration,required"` + // The name of the rule. Must be unique. Supports characters A-Z, a-z, 0-9, + // underscore (\_), dash (-), period (.), and tilde (~). You can’t have a space in + // the rule name. Max 256 characters. + Name string `json:"name,required"` + Prefixes []string `json:"prefixes,required"` + ID interface{} `json:"id"` + // The number of bits per second for the rule. When this value is exceeded for the + // set duration, an alert notification is sent. Minimum of 1 and no maximum. + BandwidthThreshold float64 `json:"bandwidth_threshold"` + // The number of packets per second for the rule. When this value is exceeded for + // the set duration, an alert notification is sent. Minimum of 1 and no maximum. + PacketThreshold float64 `json:"packet_threshold"` + JSON magicVisibilityMNMRuleJSON `json:"-"` +} + +// magicVisibilityMNMRuleJSON contains the JSON metadata for the struct +// [MagicVisibilityMNMRule] +type magicVisibilityMNMRuleJSON struct { + AutomaticAdvertisement apijson.Field + Duration apijson.Field + Name apijson.Field + Prefixes apijson.Field + ID apijson.Field + BandwidthThreshold apijson.Field + PacketThreshold apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *MagicVisibilityMNMRule) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r magicVisibilityMNMRuleJSON) RawJSON() string { + return r.raw +} + +type RuleNewParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleNewResponseEnvelope struct { + Errors []RuleNewResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleNewResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleNewResponseEnvelopeSuccess `json:"success,required"` + JSON ruleNewResponseEnvelopeJSON `json:"-"` +} + +// ruleNewResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleNewResponseEnvelope] +type ruleNewResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleNewResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleNewResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleNewResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleNewResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleNewResponseEnvelopeErrors] +type ruleNewResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleNewResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleNewResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleNewResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleNewResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleNewResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleNewResponseEnvelopeMessages] +type ruleNewResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleNewResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleNewResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleNewResponseEnvelopeSuccess bool + +const ( + RuleNewResponseEnvelopeSuccessTrue RuleNewResponseEnvelopeSuccess = true +) + +func (r RuleNewResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleNewResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type RuleUpdateParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleUpdateResponseEnvelope struct { + Errors []RuleUpdateResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleUpdateResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleUpdateResponseEnvelopeSuccess `json:"success,required"` + JSON ruleUpdateResponseEnvelopeJSON `json:"-"` +} + +// ruleUpdateResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleUpdateResponseEnvelope] +type ruleUpdateResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleUpdateResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleUpdateResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleUpdateResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleUpdateResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleUpdateResponseEnvelopeErrors] +type ruleUpdateResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleUpdateResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleUpdateResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleUpdateResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleUpdateResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleUpdateResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleUpdateResponseEnvelopeMessages] +type ruleUpdateResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleUpdateResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleUpdateResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleUpdateResponseEnvelopeSuccess bool + +const ( + RuleUpdateResponseEnvelopeSuccessTrue RuleUpdateResponseEnvelopeSuccess = true +) + +func (r RuleUpdateResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleUpdateResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type RuleListParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleListResponseEnvelope struct { + Errors []RuleListResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleListResponseEnvelopeMessages `json:"messages,required"` + Result []MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleListResponseEnvelopeSuccess `json:"success,required"` + ResultInfo RuleListResponseEnvelopeResultInfo `json:"result_info"` + JSON ruleListResponseEnvelopeJSON `json:"-"` +} + +// ruleListResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleListResponseEnvelope] +type ruleListResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + ResultInfo apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleListResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleListResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleListResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleListResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleListResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleListResponseEnvelopeErrors] +type ruleListResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleListResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleListResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleListResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleListResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleListResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleListResponseEnvelopeMessages] +type ruleListResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleListResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleListResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleListResponseEnvelopeSuccess bool + +const ( + RuleListResponseEnvelopeSuccessTrue RuleListResponseEnvelopeSuccess = true +) + +func (r RuleListResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleListResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type RuleListResponseEnvelopeResultInfo struct { + // Total number of results for the requested service + Count float64 `json:"count"` + // Current page within paginated list of results + Page float64 `json:"page"` + // Number of results per page of results + PerPage float64 `json:"per_page"` + // Total results available without any search parameters + TotalCount float64 `json:"total_count"` + JSON ruleListResponseEnvelopeResultInfoJSON `json:"-"` +} + +// ruleListResponseEnvelopeResultInfoJSON contains the JSON metadata for the struct +// [RuleListResponseEnvelopeResultInfo] +type ruleListResponseEnvelopeResultInfoJSON struct { + Count apijson.Field + Page apijson.Field + PerPage apijson.Field + TotalCount apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleListResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleListResponseEnvelopeResultInfoJSON) RawJSON() string { + return r.raw +} + +type RuleDeleteParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleDeleteResponseEnvelope struct { + Errors []RuleDeleteResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleDeleteResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleDeleteResponseEnvelopeSuccess `json:"success,required"` + JSON ruleDeleteResponseEnvelopeJSON `json:"-"` +} + +// ruleDeleteResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleDeleteResponseEnvelope] +type ruleDeleteResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleDeleteResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleDeleteResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleDeleteResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleDeleteResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleDeleteResponseEnvelopeErrors] +type ruleDeleteResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleDeleteResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleDeleteResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleDeleteResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleDeleteResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleDeleteResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleDeleteResponseEnvelopeMessages] +type ruleDeleteResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleDeleteResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleDeleteResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleDeleteResponseEnvelopeSuccess bool + +const ( + RuleDeleteResponseEnvelopeSuccessTrue RuleDeleteResponseEnvelopeSuccess = true +) + +func (r RuleDeleteResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleDeleteResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type RuleEditParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleEditResponseEnvelope struct { + Errors []RuleEditResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleEditResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleEditResponseEnvelopeSuccess `json:"success,required"` + JSON ruleEditResponseEnvelopeJSON `json:"-"` +} + +// ruleEditResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleEditResponseEnvelope] +type ruleEditResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleEditResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleEditResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleEditResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleEditResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleEditResponseEnvelopeErrors] +type ruleEditResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleEditResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleEditResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleEditResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleEditResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleEditResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleEditResponseEnvelopeMessages] +type ruleEditResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleEditResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleEditResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleEditResponseEnvelopeSuccess bool + +const ( + RuleEditResponseEnvelopeSuccessTrue RuleEditResponseEnvelopeSuccess = true +) + +func (r RuleEditResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleEditResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type RuleGetParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleGetResponseEnvelope struct { + Errors []RuleGetResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleGetResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRule `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleGetResponseEnvelopeSuccess `json:"success,required"` + JSON ruleGetResponseEnvelopeJSON `json:"-"` +} + +// ruleGetResponseEnvelopeJSON contains the JSON metadata for the struct +// [RuleGetResponseEnvelope] +type ruleGetResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleGetResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleGetResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleGetResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleGetResponseEnvelopeErrorsJSON contains the JSON metadata for the struct +// [RuleGetResponseEnvelopeErrors] +type ruleGetResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleGetResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleGetResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleGetResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleGetResponseEnvelopeMessagesJSON contains the JSON metadata for the struct +// [RuleGetResponseEnvelopeMessages] +type ruleGetResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleGetResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleGetResponseEnvelopeSuccess bool + +const ( + RuleGetResponseEnvelopeSuccessTrue RuleGetResponseEnvelopeSuccess = true +) + +func (r RuleGetResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleGetResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/magic_network_monitoring/rule_test.go b/magic_network_monitoring/rule_test.go new file mode 100644 index 00000000000..1428b7461f1 --- /dev/null +++ b/magic_network_monitoring/rule_test.go @@ -0,0 +1,183 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package magic_network_monitoring_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/magic_network_monitoring" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +func TestRuleNew(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.New(context.TODO(), magic_network_monitoring.RuleNewParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestRuleUpdate(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.Update(context.TODO(), magic_network_monitoring.RuleUpdateParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestRuleList(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.List(context.TODO(), magic_network_monitoring.RuleListParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }) + 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 TestRuleDelete(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.Delete( + context.TODO(), + "2890e6fa406311ed9b5a23f70f6fb8cf", + magic_network_monitoring.RuleDeleteParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }, + ) + 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 TestRuleEdit(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.Edit( + context.TODO(), + "2890e6fa406311ed9b5a23f70f6fb8cf", + magic_network_monitoring.RuleEditParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }, + ) + 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 TestRuleGet(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.Get( + context.TODO(), + "2890e6fa406311ed9b5a23f70f6fb8cf", + magic_network_monitoring.RuleGetParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }, + ) + 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()) + } +} diff --git a/magic_network_monitoring/ruleadvertisement.go b/magic_network_monitoring/ruleadvertisement.go index aa9c7dac3c5..63d919ccc40 100644 --- a/magic_network_monitoring/ruleadvertisement.go +++ b/magic_network_monitoring/ruleadvertisement.go @@ -3,6 +3,13 @@ package magic_network_monitoring import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" ) @@ -23,3 +30,133 @@ func NewRuleAdvertisementService(opts ...option.RequestOption) (r *RuleAdvertise r.Options = opts return } + +// Update advertisement for rule. +func (r *RuleAdvertisementService) Edit(ctx context.Context, ruleID interface{}, body RuleAdvertisementEditParams, opts ...option.RequestOption) (res *MagicVisibilityMNMRuleAdvertisable, err error) { + opts = append(r.Options[:], opts...) + var env RuleAdvertisementEditResponseEnvelope + path := fmt.Sprintf("accounts/%v/mnm/rules/%v/advertisement", body.AccountID, ruleID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type MagicVisibilityMNMRuleAdvertisable struct { + // Toggle on if you would like Cloudflare to automatically advertise the IP + // Prefixes within the rule via Magic Transit when the rule is triggered. Only + // available for users of Magic Transit. + AutomaticAdvertisement bool `json:"automatic_advertisement,required,nullable"` + JSON magicVisibilityMNMRuleAdvertisableJSON `json:"-"` +} + +// magicVisibilityMNMRuleAdvertisableJSON contains the JSON metadata for the struct +// [MagicVisibilityMNMRuleAdvertisable] +type magicVisibilityMNMRuleAdvertisableJSON struct { + AutomaticAdvertisement apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *MagicVisibilityMNMRuleAdvertisable) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r magicVisibilityMNMRuleAdvertisableJSON) RawJSON() string { + return r.raw +} + +type RuleAdvertisementEditParams struct { + AccountID param.Field[interface{}] `path:"account_id,required"` +} + +type RuleAdvertisementEditResponseEnvelope struct { + Errors []RuleAdvertisementEditResponseEnvelopeErrors `json:"errors,required"` + Messages []RuleAdvertisementEditResponseEnvelopeMessages `json:"messages,required"` + Result MagicVisibilityMNMRuleAdvertisable `json:"result,required,nullable"` + // Whether the API call was successful + Success RuleAdvertisementEditResponseEnvelopeSuccess `json:"success,required"` + JSON ruleAdvertisementEditResponseEnvelopeJSON `json:"-"` +} + +// ruleAdvertisementEditResponseEnvelopeJSON contains the JSON metadata for the +// struct [RuleAdvertisementEditResponseEnvelope] +type ruleAdvertisementEditResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleAdvertisementEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleAdvertisementEditResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type RuleAdvertisementEditResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleAdvertisementEditResponseEnvelopeErrorsJSON `json:"-"` +} + +// ruleAdvertisementEditResponseEnvelopeErrorsJSON contains the JSON metadata for +// the struct [RuleAdvertisementEditResponseEnvelopeErrors] +type ruleAdvertisementEditResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleAdvertisementEditResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleAdvertisementEditResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type RuleAdvertisementEditResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON ruleAdvertisementEditResponseEnvelopeMessagesJSON `json:"-"` +} + +// ruleAdvertisementEditResponseEnvelopeMessagesJSON contains the JSON metadata for +// the struct [RuleAdvertisementEditResponseEnvelopeMessages] +type ruleAdvertisementEditResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RuleAdvertisementEditResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r ruleAdvertisementEditResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RuleAdvertisementEditResponseEnvelopeSuccess bool + +const ( + RuleAdvertisementEditResponseEnvelopeSuccessTrue RuleAdvertisementEditResponseEnvelopeSuccess = true +) + +func (r RuleAdvertisementEditResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case RuleAdvertisementEditResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/magic_network_monitoring/ruleadvertisement_test.go b/magic_network_monitoring/ruleadvertisement_test.go new file mode 100644 index 00000000000..53b4533b33b --- /dev/null +++ b/magic_network_monitoring/ruleadvertisement_test.go @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package magic_network_monitoring_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/magic_network_monitoring" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +func TestRuleAdvertisementEdit(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.MagicNetworkMonitoring.Rules.Advertisements.Edit( + context.TODO(), + "2890e6fa406311ed9b5a23f70f6fb8cf", + magic_network_monitoring.RuleAdvertisementEditParams{ + AccountID: cloudflare.F[any]("6f91088a406011ed95aed352566e8d4c"), + }, + ) + 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()) + } +} diff --git a/zones/dnssetting.go b/zones/dnssetting.go new file mode 100644 index 00000000000..c7ffc054214 --- /dev/null +++ b/zones/dnssetting.go @@ -0,0 +1,399 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package zones + +import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +// DNSSettingService contains methods and other services that help with interacting +// with the cloudflare API. Note, unlike clients, this service does not read +// variables from the environment automatically. You should not instantiate this +// service directly, and instead use the [NewDNSSettingService] method instead. +type DNSSettingService struct { + Options []option.RequestOption +} + +// NewDNSSettingService generates a new service that applies the given options to +// each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewDNSSettingService(opts ...option.RequestOption) (r *DNSSettingService) { + r = &DNSSettingService{} + r.Options = opts + return +} + +// Update DNS settings for a zone +func (r *DNSSettingService) Edit(ctx context.Context, params DNSSettingEditParams, opts ...option.RequestOption) (res *DNSSettingEditResponse, err error) { + opts = append(r.Options[:], opts...) + var env DNSSettingEditResponseEnvelope + path := fmt.Sprintf("zones/%s/dns_settings", params.ZoneID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +// Show DNS settings for a zone +func (r *DNSSettingService) Get(ctx context.Context, query DNSSettingGetParams, opts ...option.RequestOption) (res *DNSSettingGetResponse, err error) { + opts = append(r.Options[:], opts...) + var env DNSSettingGetResponseEnvelope + path := fmt.Sprintf("zones/%s/dns_settings", query.ZoneID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type DNSSettingEditResponse struct { + // Settings determining the nameservers through which the zone should be available. + Nameservers DNSSettingEditResponseNameservers `json:"nameservers"` + JSON dnsSettingEditResponseJSON `json:"-"` +} + +// dnsSettingEditResponseJSON contains the JSON metadata for the struct +// [DNSSettingEditResponse] +type dnsSettingEditResponseJSON struct { + Nameservers apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingEditResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingEditResponseJSON) RawJSON() string { + return r.raw +} + +// Settings determining the nameservers through which the zone should be available. +type DNSSettingEditResponseNameservers struct { + // Nameserver type + Type DNSSettingEditResponseNameserversType `json:"type,required"` + JSON dnsSettingEditResponseNameserversJSON `json:"-"` +} + +// dnsSettingEditResponseNameserversJSON contains the JSON metadata for the struct +// [DNSSettingEditResponseNameservers] +type dnsSettingEditResponseNameserversJSON struct { + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingEditResponseNameservers) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingEditResponseNameserversJSON) RawJSON() string { + return r.raw +} + +// Nameserver type +type DNSSettingEditResponseNameserversType string + +const ( + DNSSettingEditResponseNameserversTypeCloudflareStandard DNSSettingEditResponseNameserversType = "cloudflare.standard" + DNSSettingEditResponseNameserversTypeCloudflareFoundationDNS DNSSettingEditResponseNameserversType = "cloudflare.foundation_dns" +) + +func (r DNSSettingEditResponseNameserversType) IsKnown() bool { + switch r { + case DNSSettingEditResponseNameserversTypeCloudflareStandard, DNSSettingEditResponseNameserversTypeCloudflareFoundationDNS: + return true + } + return false +} + +type DNSSettingGetResponse struct { + // Settings determining the nameservers through which the zone should be available. + Nameservers DNSSettingGetResponseNameservers `json:"nameservers"` + JSON dnsSettingGetResponseJSON `json:"-"` +} + +// dnsSettingGetResponseJSON contains the JSON metadata for the struct +// [DNSSettingGetResponse] +type dnsSettingGetResponseJSON struct { + Nameservers apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingGetResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingGetResponseJSON) RawJSON() string { + return r.raw +} + +// Settings determining the nameservers through which the zone should be available. +type DNSSettingGetResponseNameservers struct { + // Nameserver type + Type DNSSettingGetResponseNameserversType `json:"type,required"` + JSON dnsSettingGetResponseNameserversJSON `json:"-"` +} + +// dnsSettingGetResponseNameserversJSON contains the JSON metadata for the struct +// [DNSSettingGetResponseNameservers] +type dnsSettingGetResponseNameserversJSON struct { + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingGetResponseNameservers) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingGetResponseNameserversJSON) RawJSON() string { + return r.raw +} + +// Nameserver type +type DNSSettingGetResponseNameserversType string + +const ( + DNSSettingGetResponseNameserversTypeCloudflareStandard DNSSettingGetResponseNameserversType = "cloudflare.standard" + DNSSettingGetResponseNameserversTypeCloudflareFoundationDNS DNSSettingGetResponseNameserversType = "cloudflare.foundation_dns" +) + +func (r DNSSettingGetResponseNameserversType) IsKnown() bool { + switch r { + case DNSSettingGetResponseNameserversTypeCloudflareStandard, DNSSettingGetResponseNameserversTypeCloudflareFoundationDNS: + return true + } + return false +} + +type DNSSettingEditParams struct { + // Identifier + ZoneID param.Field[string] `path:"zone_id,required"` + // Settings determining the nameservers through which the zone should be available. + Nameservers param.Field[DNSSettingEditParamsNameservers] `json:"nameservers"` +} + +func (r DNSSettingEditParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// Settings determining the nameservers through which the zone should be available. +type DNSSettingEditParamsNameservers struct { + // Nameserver type + Type param.Field[DNSSettingEditParamsNameserversType] `json:"type,required"` +} + +func (r DNSSettingEditParamsNameservers) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +// Nameserver type +type DNSSettingEditParamsNameserversType string + +const ( + DNSSettingEditParamsNameserversTypeCloudflareStandard DNSSettingEditParamsNameserversType = "cloudflare.standard" + DNSSettingEditParamsNameserversTypeCloudflareFoundationDNS DNSSettingEditParamsNameserversType = "cloudflare.foundation_dns" +) + +func (r DNSSettingEditParamsNameserversType) IsKnown() bool { + switch r { + case DNSSettingEditParamsNameserversTypeCloudflareStandard, DNSSettingEditParamsNameserversTypeCloudflareFoundationDNS: + return true + } + return false +} + +type DNSSettingEditResponseEnvelope struct { + Errors []DNSSettingEditResponseEnvelopeErrors `json:"errors,required"` + Messages []DNSSettingEditResponseEnvelopeMessages `json:"messages,required"` + Result DNSSettingEditResponse `json:"result,required"` + // Whether the API call was successful + Success DNSSettingEditResponseEnvelopeSuccess `json:"success,required"` + JSON dnsSettingEditResponseEnvelopeJSON `json:"-"` +} + +// dnsSettingEditResponseEnvelopeJSON contains the JSON metadata for the struct +// [DNSSettingEditResponseEnvelope] +type dnsSettingEditResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingEditResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type DNSSettingEditResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON dnsSettingEditResponseEnvelopeErrorsJSON `json:"-"` +} + +// dnsSettingEditResponseEnvelopeErrorsJSON contains the JSON metadata for the +// struct [DNSSettingEditResponseEnvelopeErrors] +type dnsSettingEditResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingEditResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingEditResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type DNSSettingEditResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON dnsSettingEditResponseEnvelopeMessagesJSON `json:"-"` +} + +// dnsSettingEditResponseEnvelopeMessagesJSON contains the JSON metadata for the +// struct [DNSSettingEditResponseEnvelopeMessages] +type dnsSettingEditResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingEditResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingEditResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type DNSSettingEditResponseEnvelopeSuccess bool + +const ( + DNSSettingEditResponseEnvelopeSuccessTrue DNSSettingEditResponseEnvelopeSuccess = true +) + +func (r DNSSettingEditResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case DNSSettingEditResponseEnvelopeSuccessTrue: + return true + } + return false +} + +type DNSSettingGetParams struct { + // Identifier + ZoneID param.Field[string] `path:"zone_id,required"` +} + +type DNSSettingGetResponseEnvelope struct { + Errors []DNSSettingGetResponseEnvelopeErrors `json:"errors,required"` + Messages []DNSSettingGetResponseEnvelopeMessages `json:"messages,required"` + Result DNSSettingGetResponse `json:"result,required"` + // Whether the API call was successful + Success DNSSettingGetResponseEnvelopeSuccess `json:"success,required"` + JSON dnsSettingGetResponseEnvelopeJSON `json:"-"` +} + +// dnsSettingGetResponseEnvelopeJSON contains the JSON metadata for the struct +// [DNSSettingGetResponseEnvelope] +type dnsSettingGetResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Result apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingGetResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +type DNSSettingGetResponseEnvelopeErrors struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON dnsSettingGetResponseEnvelopeErrorsJSON `json:"-"` +} + +// dnsSettingGetResponseEnvelopeErrorsJSON contains the JSON metadata for the +// struct [DNSSettingGetResponseEnvelopeErrors] +type dnsSettingGetResponseEnvelopeErrorsJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingGetResponseEnvelopeErrorsJSON) RawJSON() string { + return r.raw +} + +type DNSSettingGetResponseEnvelopeMessages struct { + Code int64 `json:"code,required"` + Message string `json:"message,required"` + JSON dnsSettingGetResponseEnvelopeMessagesJSON `json:"-"` +} + +// dnsSettingGetResponseEnvelopeMessagesJSON contains the JSON metadata for the +// struct [DNSSettingGetResponseEnvelopeMessages] +type dnsSettingGetResponseEnvelopeMessagesJSON struct { + Code apijson.Field + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *DNSSettingGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r dnsSettingGetResponseEnvelopeMessagesJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type DNSSettingGetResponseEnvelopeSuccess bool + +const ( + DNSSettingGetResponseEnvelopeSuccessTrue DNSSettingGetResponseEnvelopeSuccess = true +) + +func (r DNSSettingGetResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case DNSSettingGetResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/zones/dnssetting_test.go b/zones/dnssetting_test.go new file mode 100644 index 00000000000..5d0a8b9a939 --- /dev/null +++ b/zones/dnssetting_test.go @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package zones_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/option" + "github.com/cloudflare/cloudflare-go/v2/zones" +) + +func TestDNSSettingEditWithOptionalParams(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.Zones.DNSSettings.Edit(context.TODO(), zones.DNSSettingEditParams{ + ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + Nameservers: cloudflare.F(zones.DNSSettingEditParamsNameservers{ + Type: cloudflare.F(zones.DNSSettingEditParamsNameserversTypeCloudflareStandard), + }), + }) + 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 TestDNSSettingGet(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + 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.Zones.DNSSettings.Get(context.TODO(), zones.DNSSettingGetParams{ + ZoneID: 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()) + } +} diff --git a/zones/zone.go b/zones/zone.go index f849a1076c3..9384ccf148a 100644 --- a/zones/zone.go +++ b/zones/zone.go @@ -24,6 +24,7 @@ import ( type ZoneService struct { Options []option.RequestOption ActivationCheck *ActivationCheckService + DNSSettings *DNSSettingService Settings *SettingService CustomNameservers *CustomNameserverService Holds *HoldService @@ -38,6 +39,7 @@ func NewZoneService(opts ...option.RequestOption) (r *ZoneService) { r = &ZoneService{} r.Options = opts r.ActivationCheck = NewActivationCheckService(opts...) + r.DNSSettings = NewDNSSettingService(opts...) r.Settings = NewSettingService(opts...) r.CustomNameservers = NewCustomNameserverService(opts...) r.Holds = NewHoldService(opts...)