diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index 3ad5b8397641..dd41adb93915 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -166,7 +166,7 @@ service/hybrid-compute: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(arc_machine\W+|arc_machine_extension\W+|arc_private_link_scope\W+|hybrid_compute_machine)((.|\n)*)###' service/iot-central: - - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_iotcentral_application((.|\n)*)###' + - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_iotcentral_((.|\n)*)###' service/iot-hub: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_iothub((.|\n)*)###' diff --git a/internal/services/iotcentral/client/client.go b/internal/services/iotcentral/client/client.go index cdd94f5ce19c..c424db661255 100644 --- a/internal/services/iotcentral/client/client.go +++ b/internal/services/iotcentral/client/client.go @@ -4,14 +4,22 @@ package client import ( + "context" "fmt" + "github.com/Azure/go-autorest/autorest" "github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps" + authWrapper "github.com/hashicorp/go-azure-sdk/sdk/auth/autorest" + "github.com/hashicorp/go-azure-sdk/sdk/environments" "github.com/hashicorp/terraform-provider-azurerm/internal/common" + dataplane "github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral" ) type Client struct { - AppsClient *apps.AppsClient + AppsClient *apps.AppsClient + authorizerFunc common.ApiAuthorizerFunc + configureClientFunc func(c *autorest.Client, authorizer autorest.Authorizer) + Endpoint environments.Api } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -19,8 +27,29 @@ func NewClient(o *common.ClientOptions) (*Client, error) { if err != nil { return nil, fmt.Errorf("building Apps Client: %+v", err) } + o.Configure(appsClient.Client, o.Authorizers.ResourceManager) + return &Client{ - AppsClient: appsClient, + AppsClient: appsClient, + authorizerFunc: o.Authorizers.AuthorizerFunc, + configureClientFunc: o.ConfigureClient, + Endpoint: o.Environment.IoTCentral, }, nil } + +func (c *Client) OrganizationsClient(ctx context.Context, subdomain string) (*dataplane.OrganizationsClient, error) { + if !c.Endpoint.Available() { + return nil, fmt.Errorf("unable to build SDK Client since IoTCentral is not available in this Azure Environment") + } + + iotCentralAuth, err := c.authorizerFunc(c.Endpoint) + if err != nil { + return nil, fmt.Errorf("obtaining auth token for %q: %+v", c.Endpoint.Name(), err) + } + + client := dataplane.NewOrganizationsClient(subdomain) + c.configureClientFunc(&client.Client, authWrapper.AutorestAuthorizer(iotCentralAuth)) + + return &client, nil +} diff --git a/internal/services/iotcentral/iotcentral_organization_resource.go b/internal/services/iotcentral/iotcentral_organization_resource.go new file mode 100644 index 000000000000..2689e2bc435a --- /dev/null +++ b/internal/services/iotcentral/iotcentral_organization_resource.go @@ -0,0 +1,261 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package iotcentral + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + dataplane "github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral" +) + +type IotCentralOrganizationResource struct{} + +var ( + _ sdk.ResourceWithUpdate = IotCentralOrganizationResource{} +) + +type IotCentralOrganizationModel struct { + IotCentralApplicationId string `tfschema:"iotcentral_application_id"` + OrganizationId string `tfschema:"organization_id"` + DisplayName string `tfschema:"display_name"` + ParentOrganizationId string `tfschema:"parent_organization_id"` +} + +func (r IotCentralOrganizationResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "iotcentral_application_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: apps.ValidateIotAppID, + }, + "organization_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.OrganizationOrganizationID, + }, + "display_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + "parent_organization_id": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.OrganizationOrganizationID, + }, + } +} + +func (r IotCentralOrganizationResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r IotCentralOrganizationResource) ResourceType() string { + return "azurerm_iotcentral_organization" +} + +func (r IotCentralOrganizationResource) ModelObject() interface{} { + return &IotCentralOrganizationModel{} +} + +func (r IotCentralOrganizationResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return validate.OrganizationID +} + +func (r IotCentralOrganizationResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.IoTCentral + var state IotCentralOrganizationModel + if err := metadata.Decode(&state); err != nil { + return err + } + + appId, err := apps.ParseIotAppID(state.IotCentralApplicationId) + if err != nil { + return err + } + + app, err := client.AppsClient.Get(ctx, *appId) + if err != nil || app.Model == nil { + return fmt.Errorf("checking for the presence of existing %q: %+v", appId, err) + } + + orgClient, err := client.OrganizationsClient(ctx, *app.Model.Properties.Subdomain) + if err != nil { + return fmt.Errorf("creating organization client: %+v", err) + } + + model := dataplane.Organization{ + DisplayName: &state.DisplayName, + } + + if state.ParentOrganizationId != "" { + model.Parent = &state.ParentOrganizationId + } + + org, err := orgClient.Create(ctx, state.OrganizationId, model) + if err != nil { + return fmt.Errorf("creating %s: %+v", state.OrganizationId, err) + } + + orgId := parse.NewOrganizationID(appId.SubscriptionId, appId.ResourceGroupName, appId.IotAppName, *org.ID) + + metadata.SetID(orgId) + return nil + }, + Timeout: 30 * time.Minute, + } +} + +func (r IotCentralOrganizationResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.IoTCentral + id, err := parse.OrganizationID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + appId := apps.NewIotAppID(id.SubscriptionId, id.ResourceGroup, id.IotAppName) + if err != nil { + return err + } + + app, err := client.AppsClient.Get(ctx, appId) + if err != nil || app.Model == nil { + return metadata.MarkAsGone(id) + } + + orgClient, err := client.OrganizationsClient(ctx, *app.Model.Properties.Subdomain) + if err != nil { + return fmt.Errorf("creating organization client: %+v", err) + } + + org, err := orgClient.Get(ctx, id.Name) + if err != nil { + if org.ID == nil || *org.ID == "" { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + state := IotCentralOrganizationModel{ + IotCentralApplicationId: appId.ID(), + OrganizationId: id.Name, + DisplayName: *org.DisplayName, + } + + if org.Parent != nil { + state.ParentOrganizationId = *org.Parent + } + + return metadata.Encode(&state) + }, + Timeout: 5 * time.Minute, + } +} + +func (r IotCentralOrganizationResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.IoTCentral + var state IotCentralOrganizationModel + if err := metadata.Decode(&state); err != nil { + return err + } + + id, err := parse.OrganizationID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + appId := apps.NewIotAppID(id.SubscriptionId, id.ResourceGroup, id.IotAppName) + if err != nil { + return err + } + + app, err := client.AppsClient.Get(ctx, appId) + if err != nil || app.Model == nil { + return metadata.MarkAsGone(id) + } + + orgClient, err := client.OrganizationsClient(ctx, *app.Model.Properties.Subdomain) + if err != nil { + return fmt.Errorf("creating organization client: %+v", err) + } + + existing, err := orgClient.Get(ctx, id.Name) + if err != nil { + if existing.ID == nil || *existing.ID == "" { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if metadata.ResourceData.HasChange("display_name") { + existing.DisplayName = &state.DisplayName + } + + _, err = orgClient.Update(ctx, *existing.ID, existing, "*") + if err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + return nil + }, + Timeout: 30 * time.Minute, + } +} + +func (r IotCentralOrganizationResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.IoTCentral + var state IotCentralOrganizationModel + if err := metadata.Decode(&state); err != nil { + return err + } + + id, err := parse.OrganizationID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + appId := apps.NewIotAppID(id.SubscriptionId, id.ResourceGroup, id.IotAppName) + if err != nil { + return err + } + + app, err := client.AppsClient.Get(ctx, appId) + if err != nil || app.Model == nil { + return metadata.MarkAsGone(id) + } + + orgClient, err := client.OrganizationsClient(ctx, *app.Model.Properties.Subdomain) + if err != nil { + return fmt.Errorf("creating organization client: %+v", err) + } + + _, err = orgClient.Remove(ctx, id.Name) + if err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + Timeout: 30 * time.Minute, + } +} diff --git a/internal/services/iotcentral/iotcentral_organization_resource_test.go b/internal/services/iotcentral/iotcentral_organization_resource_test.go new file mode 100644 index 000000000000..40d238864929 --- /dev/null +++ b/internal/services/iotcentral/iotcentral_organization_resource_test.go @@ -0,0 +1,284 @@ +package iotcentral_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type IoTCentralOrganizationResource struct{} + +func TestAccIoTCentralOrganization_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("organization_id").HasValue("org-test-id"), + check.That(data.ResourceName).Key("display_name").HasValue("Org basic"), + ), + }, + data.ImportStep(), + }) +} + +func TestAccIoTCentralOrganization_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("organization_id").HasValue("org-test-id"), + check.That(data.ResourceName).Key("display_name").HasValue("Org child"), + check.That(data.ResourceName).Key("parent_organization_id").IsNotEmpty(), + ), + }, + data.ImportStep(), + }) +} + +func TestAccIoTCentralOrganization_updateDisplayName(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("display_name").HasValue("Org basic"), + ), + }, + { + Config: r.basicUpdatedDisplayName(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("display_name").HasValue("Org basic updated"), + ), + }, + data.ImportStep(), + }) +} + +func TestAccIoTCentralOrganization_setParent(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsEmpty(), + ), + }, + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsNotEmpty(), + ), + }, + data.ImportStep(), + }) +} + +func TestAccIoTCentralOrganization_updateParent(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsNotEmpty(), + ), + }, + { + Config: r.completeUpdateParent(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsNotEmpty(), + ), + }, + data.ImportStep(), + }) +} + +func TestAccIoTCentralOrganization_unsetParent(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_organization", "test") + r := IoTCentralOrganizationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsNotEmpty(), + ), + }, + { + Config: r.completeUnsetParent(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("parent_organization_id").IsEmpty(), + ), + }, + data.ImportStep(), + }) +} + +func (IoTCentralOrganizationResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.OrganizationID(state.ID) + if err != nil { + return nil, err + } + + appId, err := apps.ParseIotAppID(state.Attributes["iotcentral_application_id"]) + if err != nil { + return nil, err + } + + app, err := clients.IoTCentral.AppsClient.Get(ctx, *appId) + if err != nil || app.Model == nil { + return nil, fmt.Errorf("checking for the presence of existing %q: %+v", appId, err) + } + + orgClient, err := clients.IoTCentral.OrganizationsClient(ctx, *app.Model.Properties.Subdomain) + if err != nil { + return nil, fmt.Errorf("creating organization client: %+v", err) + } + + resp, err := orgClient.Get(ctx, id.Name) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + + return utils.Bool(resp.ID != nil || *resp.ID == ""), nil +} + +func (r IoTCentralOrganizationResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +%s +resource "azurerm_iotcentral_organization" "test" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-id" + display_name = "Org basic" +} +`, r.template(data)) +} + +func (r IoTCentralOrganizationResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +%s +resource "azurerm_iotcentral_organization" "test_parent" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-parent-id" + display_name = "Org parent" +} +resource "azurerm_iotcentral_organization" "test" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-id" + display_name = "Org child" + + parent_organization_id = azurerm_iotcentral_organization.test_parent.organization_id +} +`, r.template(data)) +} + +func (r IoTCentralOrganizationResource) basicUpdatedDisplayName(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +%s +resource "azurerm_iotcentral_organization" "test" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-id" + display_name = "Org basic updated" +} +`, r.template(data)) +} + +func (r IoTCentralOrganizationResource) completeUpdateParent(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +%s +resource "azurerm_iotcentral_organization" "test_parent" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-parent-id" + display_name = "Org parent" +} +resource "azurerm_iotcentral_organization" "test_parent_2" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-parent-2-id" + display_name = "Org parent 2" +} +resource "azurerm_iotcentral_organization" "test" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-id" + display_name = "Org child" + + parent_organization_id = azurerm_iotcentral_organization.test_parent_2.organization_id +} +`, r.template(data)) +} + +func (r IoTCentralOrganizationResource) completeUnsetParent(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +%s +resource "azurerm_iotcentral_organization" "test_parent" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-parent-id" + display_name = "Org parent" +} +resource "azurerm_iotcentral_organization" "test" { + iotcentral_application_id = azurerm_iotcentral_application.test.id + organization_id = "org-test-id" + display_name = "Org child" +} +`, r.template(data)) +} + +func (IoTCentralOrganizationResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} +resource "azurerm_iotcentral_application" "test" { + name = "acctest-iotcentralapp-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sub_domain = "subdomain-%[1]d" + display_name = "some-display-name" + sku = "ST0" +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/internal/services/iotcentral/parse/organization.go b/internal/services/iotcentral/parse/organization.go new file mode 100644 index 000000000000..bdf8290386b1 --- /dev/null +++ b/internal/services/iotcentral/parse/organization.go @@ -0,0 +1,78 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package parse + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +type OrganizationId struct { + SubscriptionId string + ResourceGroup string + IotAppName string + Name string +} + +func NewOrganizationID(subscriptionId, resourceGroup, iotAppName, name string) OrganizationId { + return OrganizationId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + IotAppName: iotAppName, + Name: name, + } +} + +func (id OrganizationId) String() string { + segments := []string{ + fmt.Sprintf("Name %q", id.Name), + fmt.Sprintf("Iot App Name %q", id.IotAppName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Organization", segmentsStr) +} + +func (id OrganizationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.IoTCentral/iotApps/%s/organizations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.IotAppName, id.Name) +} + +// OrganizationID parses a Organization ID into an OrganizationId struct +func OrganizationID(input string) (*OrganizationId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("parsing %q as an Organization ID: %+v", input, err) + } + + resourceId := OrganizationId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + if resourceId.IotAppName, err = id.PopSegment("iotApps"); err != nil { + return nil, err + } + if resourceId.Name, err = id.PopSegment("organizations"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/iotcentral/parse/organization_test.go b/internal/services/iotcentral/parse/organization_test.go new file mode 100644 index 000000000000..4d1e9d36ad4b --- /dev/null +++ b/internal/services/iotcentral/parse/organization_test.go @@ -0,0 +1,131 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package parse + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.Id = OrganizationId{} + +func TestOrganizationIDFormatter(t *testing.T) { + actual := NewOrganizationID("12345678-1234-9876-4563-123456789012", "resGroup1", "application1", "organization1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/organization1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestOrganizationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OrganizationId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing IotAppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/", + Error: true, + }, + + { + // missing value for IotAppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/", + Error: true, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/", + Error: true, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/organization1", + Expected: &OrganizationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + IotAppName: "application1", + Name: "organization1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.IOTCENTRAL/IOTAPPS/APPLICATION1/ORGANIZATIONS/ORGANIZATION1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := OrganizationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.IotAppName != v.Expected.IotAppName { + t.Fatalf("Expected %q but got %q for IotAppName", v.Expected.IotAppName, actual.IotAppName) + } + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/internal/services/iotcentral/registration.go b/internal/services/iotcentral/registration.go index f5ca79094a48..a9aaff612e89 100644 --- a/internal/services/iotcentral/registration.go +++ b/internal/services/iotcentral/registration.go @@ -40,6 +40,7 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ IotCentralApplicationNetworkRuleSetResource{}, + IotCentralOrganizationResource{}, } } diff --git a/internal/services/iotcentral/resourceids.go b/internal/services/iotcentral/resourceids.go new file mode 100644 index 000000000000..da20cc45366b --- /dev/null +++ b/internal/services/iotcentral/resourceids.go @@ -0,0 +1,3 @@ +package iotcentral + +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Organization -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/organization1 diff --git a/internal/services/iotcentral/validate/organization_id.go b/internal/services/iotcentral/validate/organization_id.go new file mode 100644 index 000000000000..bd1f23e0a8a7 --- /dev/null +++ b/internal/services/iotcentral/validate/organization_id.go @@ -0,0 +1,26 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/parse" +) + +func OrganizationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.OrganizationID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/iotcentral/validate/organization_id_test.go b/internal/services/iotcentral/validate/organization_id_test.go new file mode 100644 index 000000000000..8dcdfb9e65f1 --- /dev/null +++ b/internal/services/iotcentral/validate/organization_id_test.go @@ -0,0 +1,91 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestOrganizationID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing IotAppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/", + Valid: false, + }, + + { + // missing value for IotAppName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/", + Valid: false, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/", + Valid: false, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/iotApps/application1/organizations/organization1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.IOTCENTRAL/IOTAPPS/APPLICATION1/ORGANIZATIONS/ORGANIZATION1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := OrganizationID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/iotcentral/validate/organization_organization_id.go b/internal/services/iotcentral/validate/organization_organization_id.go new file mode 100644 index 000000000000..d0fa5c860f1e --- /dev/null +++ b/internal/services/iotcentral/validate/organization_organization_id.go @@ -0,0 +1,51 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func OrganizationOrganizationID(i interface{}, k string) (warnings []string, errors []error) { + id, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %s to be a string", k)) + return warnings, errors + } + + err := validateOrganizationId(id) + if err != nil { + errors = append(errors, err) + return warnings, errors + } + + return warnings, errors +} + +func validateOrganizationId(id string) error { + // Ensure the string follows the desired format. + // Regex pattern: ^(?!-)[a-z0-9-]{1,48}[a-z0-9]$ + // The negative lookahead (?!-) is not supported in Go's standard regexp package + formatPattern := `^[a-z0-9-]{1,48}[a-z0-9]$` + formatRegex, err := regexp.Compile(formatPattern) + if err != nil { + return fmt.Errorf("error compiling format regex: %s error: %+v", formatPattern, err) + } + + if !formatRegex.MatchString(id) { + return fmt.Errorf("iot central organizationId %q is invalid, regex pattern: ^(?!-)[a-z0-9-]{1,48}[a-z0-9]$", id) + } + + // Ensure the string does not start with a hyphen. + // Solves for (?!-) + startHyphenPattern := `^-` + startHyphenRegex, err := regexp.Compile(startHyphenPattern) + if err != nil { + return fmt.Errorf("error compiling start hyphen regex: %s error: %+v", startHyphenPattern, err) + } + + if startHyphenRegex.MatchString(id) { + return fmt.Errorf("iot central organizationId %q is invalid, regex pattern: ^(?!-)[a-z0-9-]{1,48}[a-z0-9]$", id) + } + + return nil +} diff --git a/internal/services/iotcentral/validate/organization_organization_id_test.go b/internal/services/iotcentral/validate/organization_organization_id_test.go new file mode 100644 index 000000000000..aca0b9d53fa8 --- /dev/null +++ b/internal/services/iotcentral/validate/organization_organization_id_test.go @@ -0,0 +1,58 @@ +package validate + +import ( + "testing" +) + +func TestOrganizationOrganizationID(t *testing.T) { + cases := []struct { + Input string + ExpectError bool + }{ + { + Input: "-invalid-start", + ExpectError: true, + }, + { + Input: "invalid--hyphen", + ExpectError: true, + }, + { + Input: "1234567890123456789012345678901234567890123456789", + ExpectError: true, + }, + { + Input: "valid-string1", + ExpectError: false, + }, + { + Input: "validstring2", + ExpectError: false, + }, + { + Input: "v", + ExpectError: false, + }, + { + Input: "1", + ExpectError: true, + }, + } + + for _, tc := range cases { + warnings, err := OrganizationID(tc.Input, "example") + if err != nil { + if !tc.ExpectError { + t.Fatalf("Got error for input %q: %+v", tc.Input, err) + } + + return + } + + if tc.ExpectError && len(warnings) == 0 { + t.Fatalf("Got no errors for input %q but expected some", tc.Input) + } else if !tc.ExpectError && len(warnings) > 0 { + t.Fatalf("Got %d errors for input %q when didn't expect any", len(warnings), tc.Input) + } + } +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/apitokens.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/apitokens.go new file mode 100644 index 000000000000..53d8eea863fb --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/apitokens.go @@ -0,0 +1,379 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" +) + +// APITokensClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type APITokensClient struct { + BaseClient +} + +// NewAPITokensClient creates an instance of the APITokensClient client. +func NewAPITokensClient(subdomain string) APITokensClient { + return APITokensClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// tokenID - unique ID for the API token. +// body - API token body. +func (client APITokensClient) Create(ctx context.Context, tokenID string, body APIToken) (result APIToken, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokensClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreatePreparer(ctx, tokenID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client APITokensClient) CreatePreparer(ctx context.Context, tokenID string, body APIToken) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "tokenId": autorest.Encode("path", tokenID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.Token = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/apiTokens/{tokenId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client APITokensClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client APITokensClient) CreateResponder(resp *http.Response) (result APIToken, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// tokenID - unique ID for the API token. +func (client APITokensClient) Get(ctx context.Context, tokenID string) (result APIToken, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokensClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, tokenID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client APITokensClient) GetPreparer(ctx context.Context, tokenID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "tokenId": autorest.Encode("path", tokenID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/apiTokens/{tokenId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client APITokensClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client APITokensClient) GetResponder(resp *http.Response) (result APIToken, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client APITokensClient) List(ctx context.Context) (result APITokenCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokensClient.List") + defer func() { + sc := -1 + if result.atc.Response.Response != nil { + sc = result.atc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.atc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "List", resp, "Failure sending request") + return + } + + result.atc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "List", resp, "Failure responding to request") + return + } + if result.atc.hasNextLink() && result.atc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client APITokensClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/apiTokens"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client APITokensClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client APITokensClient) ListResponder(resp *http.Response) (result APITokenCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client APITokensClient) listNextResults(ctx context.Context, lastResults APITokenCollection) (result APITokenCollection, err error) { + req, err := lastResults.aPITokenCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client APITokensClient) ListComplete(ctx context.Context) (result APITokenCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokensClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// Remove sends the remove request. +// Parameters: +// tokenID - unique ID for the API token. +func (client APITokensClient) Remove(ctx context.Context, tokenID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokensClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemovePreparer(ctx, tokenID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.APITokensClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client APITokensClient) RemovePreparer(ctx context.Context, tokenID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "tokenId": autorest.Encode("path", tokenID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/apiTokens/{tokenId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client APITokensClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client APITokensClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/client.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/client.go new file mode 100644 index 000000000000..90a135fa3e10 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/client.go @@ -0,0 +1,40 @@ +// Package iotcentral implements the Azure ARM Iotcentral service API version 2022-10-31-preview. +// +// Azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT devices at scale. +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseDomain is the default value for base domain + DefaultBaseDomain = "azureiotcentral.com" +) + +// BaseClient is the base client for Iotcentral. +type BaseClient struct { + autorest.Client + BaseDomain string + Subdomain string +} + +// New creates an instance of the BaseClient client. +func New(subdomain string) BaseClient { + return NewWithoutDefaults(subdomain, DefaultBaseDomain) +} + +// NewWithoutDefaults creates an instance of the BaseClient client. +func NewWithoutDefaults(subdomain string, baseDomain string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseDomain: baseDomain, + Subdomain: subdomain, + } +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/dashboards.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/dashboards.go new file mode 100644 index 000000000000..ae8bea345f2e --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/dashboards.go @@ -0,0 +1,522 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DashboardsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type DashboardsClient struct { + BaseClient +} + +// NewDashboardsClient creates an instance of the DashboardsClient client. +func NewDashboardsClient(subdomain string) DashboardsClient { + return DashboardsClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// dashboardID - unique ID for the dashboard. +// body - dashboard definition. +func (client DashboardsClient) Create(ctx context.Context, dashboardID string, body Dashboard) (result Dashboard, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: dashboardID, + Constraints: []validation.Constraint{{Target: "dashboardID", Name: validation.MaxLength, Rule: 128, Chain: nil}, + {Target: "dashboardID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {Target: "body.Tiles", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Tiles", Name: validation.MaxItems, Rule: 100, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("iotcentral.DashboardsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, dashboardID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DashboardsClient) CreatePreparer(ctx context.Context, dashboardID string, body Dashboard) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "dashboardId": autorest.Encode("path", dashboardID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.Personal = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dashboards/{dashboardId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DashboardsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DashboardsClient) CreateResponder(resp *http.Response) (result Dashboard, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// dashboardID - unique ID for the dashboard. +func (client DashboardsClient) Get(ctx context.Context, dashboardID string) (result Dashboard, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: dashboardID, + Constraints: []validation.Constraint{{Target: "dashboardID", Name: validation.MaxLength, Rule: 128, Chain: nil}, + {Target: "dashboardID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DashboardsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, dashboardID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DashboardsClient) GetPreparer(ctx context.Context, dashboardID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "dashboardId": autorest.Encode("path", dashboardID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dashboards/{dashboardId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DashboardsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DashboardsClient) GetResponder(resp *http.Response) (result Dashboard, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// filter - an expression on the resource type that selects the resources to be returned. +// maxpagesize - the maximum number of resources to return from one response. +// orderby - an expression that specify the order of the returned resources. +func (client DashboardsClient) List(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DashboardCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.List") + defer func() { + sc := -1 + if result.dc.Response.Response != nil { + sc = result.dc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DashboardsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, filter, maxpagesize, orderby) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "List", resp, "Failure sending request") + return + } + + result.dc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "List", resp, "Failure responding to request") + return + } + if result.dc.hasNextLink() && result.dc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DashboardsClient) ListPreparer(ctx context.Context, filter string, maxpagesize *int32, orderby string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["filter"] = autorest.Encode("query", filter) + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + if len(orderby) > 0 { + queryParameters["orderby"] = autorest.Encode("query", orderby) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/dashboards"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DashboardsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DashboardsClient) ListResponder(resp *http.Response) (result DashboardCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DashboardsClient) listNextResults(ctx context.Context, lastResults DashboardCollection) (result DashboardCollection, err error) { + req, err := lastResults.dashboardCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DashboardsClient) ListComplete(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DashboardCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, filter, maxpagesize, orderby) + return +} + +// Remove sends the remove request. +// Parameters: +// dashboardID - unique ID for the dashboard. +func (client DashboardsClient) Remove(ctx context.Context, dashboardID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: dashboardID, + Constraints: []validation.Constraint{{Target: "dashboardID", Name: validation.MaxLength, Rule: 128, Chain: nil}, + {Target: "dashboardID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DashboardsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, dashboardID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DashboardsClient) RemovePreparer(ctx context.Context, dashboardID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "dashboardId": autorest.Encode("path", dashboardID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dashboards/{dashboardId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DashboardsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DashboardsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// dashboardID - unique ID for the dashboard. +// body - dashboard definition. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DashboardsClient) Update(ctx context.Context, dashboardID string, body interface{}, ifMatch string) (result Dashboard, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: dashboardID, + Constraints: []validation.Constraint{{Target: "dashboardID", Name: validation.MaxLength, Rule: 128, Chain: nil}, + {Target: "dashboardID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DashboardsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, dashboardID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DashboardsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DashboardsClient) UpdatePreparer(ctx context.Context, dashboardID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "dashboardId": autorest.Encode("path", dashboardID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/merge-patch+json"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dashboards/{dashboardId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DashboardsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DashboardsClient) UpdateResponder(resp *http.Response) (result Dashboard, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/deploymentmanifests.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/deploymentmanifests.go new file mode 100644 index 000000000000..ed2424f595ad --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/deploymentmanifests.go @@ -0,0 +1,520 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DeploymentManifestsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage +// your IoT devices at scale. +type DeploymentManifestsClient struct { + BaseClient +} + +// NewDeploymentManifestsClient creates an instance of the DeploymentManifestsClient client. +func NewDeploymentManifestsClient(subdomain string) DeploymentManifestsClient { + return DeploymentManifestsClient{New(subdomain)} +} + +// Create create a new deployment manifest. +// Parameters: +// deploymentManifestID - unique ID for the deployment manifest. +// body - deployment manifest body. +func (client DeploymentManifestsClient) Create(ctx context.Context, deploymentManifestID string, body DeploymentManifest) (result DeploymentManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deploymentManifestID, + Constraints: []validation.Constraint{{Target: "deploymentManifestID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deploymentManifestID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {Target: "body.Data", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Organizations", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Organizations", Name: validation.MaxItems, Rule: 1, Chain: nil}, + {Target: "body.Organizations", Name: validation.MinItems, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DeploymentManifestsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, deploymentManifestID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DeploymentManifestsClient) CreatePreparer(ctx context.Context, deploymentManifestID string, body DeploymentManifest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deploymentManifestId": autorest.Encode("path", deploymentManifestID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deploymentManifests/{deploymentManifestId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DeploymentManifestsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DeploymentManifestsClient) CreateResponder(resp *http.Response) (result DeploymentManifest, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get a deployment manifest by ID. +// Parameters: +// deploymentManifestID - unique ID for the deployment manifest. +func (client DeploymentManifestsClient) Get(ctx context.Context, deploymentManifestID string) (result DeploymentManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deploymentManifestID, + Constraints: []validation.Constraint{{Target: "deploymentManifestID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deploymentManifestID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeploymentManifestsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, deploymentManifestID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DeploymentManifestsClient) GetPreparer(ctx context.Context, deploymentManifestID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deploymentManifestId": autorest.Encode("path", deploymentManifestID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deploymentManifests/{deploymentManifestId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DeploymentManifestsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DeploymentManifestsClient) GetResponder(resp *http.Response) (result DeploymentManifest, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List get the list of deployment manifests. +// Parameters: +// maxpagesize - the maximum number of resources to return from one response. +// filter - an expression on the resource type that selects the resources to be returned. +func (client DeploymentManifestsClient) List(ctx context.Context, maxpagesize *int32, filter string) (result DeploymentManifestCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.List") + defer func() { + sc := -1 + if result.dmc.Response.Response != nil { + sc = result.dmc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DeploymentManifestsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, maxpagesize, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dmc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "List", resp, "Failure sending request") + return + } + + result.dmc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "List", resp, "Failure responding to request") + return + } + if result.dmc.hasNextLink() && result.dmc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DeploymentManifestsClient) ListPreparer(ctx context.Context, maxpagesize *int32, filter string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + if len(filter) > 0 { + queryParameters["filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/deploymentManifests"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DeploymentManifestsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DeploymentManifestsClient) ListResponder(resp *http.Response) (result DeploymentManifestCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DeploymentManifestsClient) listNextResults(ctx context.Context, lastResults DeploymentManifestCollection) (result DeploymentManifestCollection, err error) { + req, err := lastResults.deploymentManifestCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DeploymentManifestsClient) ListComplete(ctx context.Context, maxpagesize *int32, filter string) (result DeploymentManifestCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, maxpagesize, filter) + return +} + +// Remove delete a deployment manifest. +// Parameters: +// deploymentManifestID - unique ID for the deployment manifest. +func (client DeploymentManifestsClient) Remove(ctx context.Context, deploymentManifestID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deploymentManifestID, + Constraints: []validation.Constraint{{Target: "deploymentManifestID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deploymentManifestID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeploymentManifestsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, deploymentManifestID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DeploymentManifestsClient) RemovePreparer(ctx context.Context, deploymentManifestID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deploymentManifestId": autorest.Encode("path", deploymentManifestID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deploymentManifests/{deploymentManifestId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DeploymentManifestsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DeploymentManifestsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update update an existing deployment manifest. +// Parameters: +// deploymentManifestID - unique ID for the deployment manifest. +// body - deployment manifest patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DeploymentManifestsClient) Update(ctx context.Context, deploymentManifestID string, body interface{}, ifMatch string) (result DeploymentManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deploymentManifestID, + Constraints: []validation.Constraint{{Target: "deploymentManifestID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deploymentManifestID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9:;]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeploymentManifestsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, deploymentManifestID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeploymentManifestsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DeploymentManifestsClient) UpdatePreparer(ctx context.Context, deploymentManifestID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deploymentManifestId": autorest.Encode("path", deploymentManifestID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/merge-patch+json"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deploymentManifests/{deploymentManifestId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DeploymentManifestsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DeploymentManifestsClient) UpdateResponder(resp *http.Response) (result DeploymentManifest, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/destinations.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/destinations.go new file mode 100644 index 000000000000..bcad4d60b797 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/destinations.go @@ -0,0 +1,591 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DestinationsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type DestinationsClient struct { + BaseClient +} + +// NewDestinationsClient creates an instance of the DestinationsClient client. +func NewDestinationsClient(subdomain string) DestinationsClient { + return DestinationsClient{New(subdomain)} +} + +// Create create or update a definition for where to send data. +// Parameters: +// destinationID - unique ID for the destination. +// body - destination body. +func (client DestinationsClient) Create(ctx context.Context, destinationID string, body BasicDestination) (result DestinationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DestinationsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, destinationID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DestinationsClient) CreatePreparer(ctx context.Context, destinationID string, body BasicDestination) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "destinationId": autorest.Encode("path", destinationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/destinations/{destinationId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DestinationsClient) CreateResponder(resp *http.Response) (result DestinationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// destinationID - unique ID for the destination. +func (client DestinationsClient) Get(ctx context.Context, destinationID string) (result DestinationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, destinationID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DestinationsClient) GetPreparer(ctx context.Context, destinationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "destinationId": autorest.Encode("path", destinationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/destinations/{destinationId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DestinationsClient) GetResponder(resp *http.Response) (result DestinationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client DestinationsClient) List(ctx context.Context) (result DestinationCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.List") + defer func() { + sc := -1 + if result.dc.Response.Response != nil { + sc = result.dc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "List", resp, "Failure sending request") + return + } + + result.dc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "List", resp, "Failure responding to request") + return + } + if result.dc.hasNextLink() && result.dc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DestinationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/dataExport/destinations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DestinationsClient) ListResponder(resp *http.Response) (result DestinationCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DestinationsClient) listNextResults(ctx context.Context, lastResults DestinationCollection) (result DestinationCollection, err error) { + req, err := lastResults.destinationCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DestinationsClient) ListComplete(ctx context.Context) (result DestinationCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// ListExports sends the list exports request. +// Parameters: +// destinationID - unique ID for the destination. +func (client DestinationsClient) ListExports(ctx context.Context, destinationID string) (result ExportCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.ListExports") + defer func() { + sc := -1 + if result.ec.Response.Response != nil { + sc = result.ec.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listExportsNextResults + req, err := client.ListExportsPreparer(ctx, destinationID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "ListExports", nil, "Failure preparing request") + return + } + + resp, err := client.ListExportsSender(req) + if err != nil { + result.ec.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "ListExports", resp, "Failure sending request") + return + } + + result.ec, err = client.ListExportsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "ListExports", resp, "Failure responding to request") + return + } + if result.ec.hasNextLink() && result.ec.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListExportsPreparer prepares the ListExports request. +func (client DestinationsClient) ListExportsPreparer(ctx context.Context, destinationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "destinationId": autorest.Encode("path", destinationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/destinations/{destinationId}/exports", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListExportsSender sends the ListExports request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) ListExportsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListExportsResponder handles the response to the ListExports request. The method always +// closes the http.Response Body. +func (client DestinationsClient) ListExportsResponder(resp *http.Response) (result ExportCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listExportsNextResults retrieves the next set of results, if any. +func (client DestinationsClient) listExportsNextResults(ctx context.Context, lastResults ExportCollection) (result ExportCollection, err error) { + req, err := lastResults.exportCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listExportsNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListExportsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listExportsNextResults", resp, "Failure sending next results request") + } + result, err = client.ListExportsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "listExportsNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListExportsComplete enumerates all values, automatically crossing page boundaries as required. +func (client DestinationsClient) ListExportsComplete(ctx context.Context, destinationID string) (result ExportCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.ListExports") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListExports(ctx, destinationID) + return +} + +// Remove sends the remove request. +// Parameters: +// destinationID - unique ID for the destination. +func (client DestinationsClient) Remove(ctx context.Context, destinationID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemovePreparer(ctx, destinationID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DestinationsClient) RemovePreparer(ctx context.Context, destinationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "destinationId": autorest.Encode("path", destinationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/destinations/{destinationId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DestinationsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update perform an incremental update to a destination. +// Parameters: +// destinationID - unique ID for the destination. +// body - destination patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DestinationsClient) Update(ctx context.Context, destinationID string, body interface{}, ifMatch string) (result DestinationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, destinationID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DestinationsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DestinationsClient) UpdatePreparer(ctx context.Context, destinationID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "destinationId": autorest.Encode("path", destinationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/destinations/{destinationId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DestinationsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DestinationsClient) UpdateResponder(resp *http.Response) (result DestinationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicegroups.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicegroups.go new file mode 100644 index 000000000000..d48681e8e9ca --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicegroups.go @@ -0,0 +1,655 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DeviceGroupsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type DeviceGroupsClient struct { + BaseClient +} + +// NewDeviceGroupsClient creates an instance of the DeviceGroupsClient client. +func NewDeviceGroupsClient(subdomain string) DeviceGroupsClient { + return DeviceGroupsClient{New(subdomain)} +} + +// Create create or update a device group. +// Parameters: +// deviceGroupID - unique ID for the device group. +// body - device group body. +func (client DeviceGroupsClient) Create(ctx context.Context, deviceGroupID string, body DeviceGroup) (result DeviceGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deviceGroupID, + Constraints: []validation.Constraint{{Target: "deviceGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deviceGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Filter", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, deviceGroupID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DeviceGroupsClient) CreatePreparer(ctx context.Context, deviceGroupID string, body DeviceGroup) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceGroupId": autorest.Encode("path", deviceGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceGroups/{deviceGroupId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) CreateResponder(resp *http.Response) (result DeviceGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// deviceGroupID - unique ID for the device group. +func (client DeviceGroupsClient) Get(ctx context.Context, deviceGroupID string) (result DeviceGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deviceGroupID, + Constraints: []validation.Constraint{{Target: "deviceGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deviceGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, deviceGroupID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DeviceGroupsClient) GetPreparer(ctx context.Context, deviceGroupID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceGroupId": autorest.Encode("path", deviceGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceGroups/{deviceGroupId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) GetResponder(resp *http.Response) (result DeviceGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetDevices get the list of devices by device group ID. +// Parameters: +// deviceGroupID - unique ID for the device group. +// maxpagesize - the maximum number of resources to return from one response. +func (client DeviceGroupsClient) GetDevices(ctx context.Context, deviceGroupID string, maxpagesize *int32) (result DeviceGroupDeviceCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.GetDevices") + defer func() { + sc := -1 + if result.dgdc.Response.Response != nil { + sc = result.dgdc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deviceGroupID, + Constraints: []validation.Constraint{{Target: "deviceGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deviceGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}, + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "GetDevices", err.Error()) + } + + result.fn = client.getDevicesNextResults + req, err := client.GetDevicesPreparer(ctx, deviceGroupID, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "GetDevices", nil, "Failure preparing request") + return + } + + resp, err := client.GetDevicesSender(req) + if err != nil { + result.dgdc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "GetDevices", resp, "Failure sending request") + return + } + + result.dgdc, err = client.GetDevicesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "GetDevices", resp, "Failure responding to request") + return + } + if result.dgdc.hasNextLink() && result.dgdc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetDevicesPreparer prepares the GetDevices request. +func (client DeviceGroupsClient) GetDevicesPreparer(ctx context.Context, deviceGroupID string, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceGroupId": autorest.Encode("path", deviceGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceGroups/{deviceGroupId}/devices", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetDevicesSender sends the GetDevices request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) GetDevicesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetDevicesResponder handles the response to the GetDevices request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) GetDevicesResponder(resp *http.Response) (result DeviceGroupDeviceCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getDevicesNextResults retrieves the next set of results, if any. +func (client DeviceGroupsClient) getDevicesNextResults(ctx context.Context, lastResults DeviceGroupDeviceCollection) (result DeviceGroupDeviceCollection, err error) { + req, err := lastResults.deviceGroupDeviceCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "getDevicesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetDevicesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "getDevicesNextResults", resp, "Failure sending next results request") + } + result, err = client.GetDevicesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "getDevicesNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetDevicesComplete enumerates all values, automatically crossing page boundaries as required. +func (client DeviceGroupsClient) GetDevicesComplete(ctx context.Context, deviceGroupID string, maxpagesize *int32) (result DeviceGroupDeviceCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.GetDevices") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetDevices(ctx, deviceGroupID, maxpagesize) + return +} + +// List sends the list request. +// Parameters: +// filter - an expression on the resource type that selects the resources to be returned. +// maxpagesize - the maximum number of resources to return from one response. +// orderby - an expression that specify the order of the returned resources. +func (client DeviceGroupsClient) List(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DeviceGroupCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.List") + defer func() { + sc := -1 + if result.dgc.Response.Response != nil { + sc = result.dgc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, filter, maxpagesize, orderby) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dgc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "List", resp, "Failure sending request") + return + } + + result.dgc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "List", resp, "Failure responding to request") + return + } + if result.dgc.hasNextLink() && result.dgc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DeviceGroupsClient) ListPreparer(ctx context.Context, filter string, maxpagesize *int32, orderby string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["filter"] = autorest.Encode("query", filter) + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + if len(orderby) > 0 { + queryParameters["orderby"] = autorest.Encode("query", orderby) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/deviceGroups"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) ListResponder(resp *http.Response) (result DeviceGroupCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DeviceGroupsClient) listNextResults(ctx context.Context, lastResults DeviceGroupCollection) (result DeviceGroupCollection, err error) { + req, err := lastResults.deviceGroupCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DeviceGroupsClient) ListComplete(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DeviceGroupCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, filter, maxpagesize, orderby) + return +} + +// Remove sends the remove request. +// Parameters: +// deviceGroupID - unique ID for the device group. +func (client DeviceGroupsClient) Remove(ctx context.Context, deviceGroupID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deviceGroupID, + Constraints: []validation.Constraint{{Target: "deviceGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deviceGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, deviceGroupID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DeviceGroupsClient) RemovePreparer(ctx context.Context, deviceGroupID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceGroupId": autorest.Encode("path", deviceGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceGroups/{deviceGroupId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update update an existing device group by ID. +// Parameters: +// deviceGroupID - unique ID for the device group. +// body - device group patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DeviceGroupsClient) Update(ctx context.Context, deviceGroupID string, body interface{}, ifMatch string) (result DeviceGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deviceGroupID, + Constraints: []validation.Constraint{{Target: "deviceGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "deviceGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceGroupsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, deviceGroupID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceGroupsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DeviceGroupsClient) UpdatePreparer(ctx context.Context, deviceGroupID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceGroupId": autorest.Encode("path", deviceGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceGroups/{deviceGroupId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceGroupsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DeviceGroupsClient) UpdateResponder(resp *http.Response) (result DeviceGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devices.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devices.go new file mode 100644 index 000000000000..9bbfe16b8bad --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devices.go @@ -0,0 +1,4016 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DevicesClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type DevicesClient struct { + BaseClient +} + +// NewDevicesClient creates an instance of the DevicesClient client. +func NewDevicesClient(subdomain string) DevicesClient { + return DevicesClient{New(subdomain)} +} + +// ApplyManifest apply a deployment manifest to an edge device. +// Parameters: +// deviceID - unique ID of the device. +// body - deployment Manifest data. +func (client DevicesClient) ApplyManifest(ctx context.Context, deviceID string, body DeploymentManifest) (result DeploymentManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ApplyManifest") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {Target: "body.Data", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Organizations", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Organizations", Name: validation.MaxItems, Rule: 1, Chain: nil}, + {Target: "body.Organizations", Name: validation.MinItems, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ApplyManifest", err.Error()) + } + + req, err := client.ApplyManifestPreparer(ctx, deviceID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ApplyManifest", nil, "Failure preparing request") + return + } + + resp, err := client.ApplyManifestSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ApplyManifest", resp, "Failure sending request") + return + } + + result, err = client.ApplyManifestResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ApplyManifest", resp, "Failure responding to request") + return + } + + return +} + +// ApplyManifestPreparer prepares the ApplyManifest request. +func (client DevicesClient) ApplyManifestPreparer(ctx context.Context, deviceID string, body DeploymentManifest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/applyDeploymentManifest", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ApplyManifestSender sends the ApplyManifest request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ApplyManifestSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ApplyManifestResponder handles the response to the ApplyManifest request. The method always +// closes the http.Response Body. +func (client DevicesClient) ApplyManifestResponder(resp *http.Response) (result DeploymentManifest, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Create create a new device. +// Parameters: +// deviceID - unique ID of the device. +// body - device body. +// expand - the query parameter for including requested entities in response. +func (client DevicesClient) Create(ctx context.Context, deviceID string, body Device, expand string) (result Device, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DeploymentManifest", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.DeploymentManifest.DisplayName", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.DeploymentManifest.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {Target: "body.DeploymentManifest.Data", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.DeploymentManifest.Organizations", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.DeploymentManifest.Organizations", Name: validation.MaxItems, Rule: 1, Chain: nil}, + {Target: "body.DeploymentManifest.Organizations", Name: validation.MinItems, Rule: 1, Chain: nil}, + }}, + }}}}, + {TargetValue: expand, + Constraints: []validation.Constraint{{Target: "expand", Name: validation.Empty, Rule: false, + Chain: []validation.Constraint{{Target: "expand", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "expand", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, deviceID, body, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DevicesClient) CreatePreparer(ctx context.Context, deviceID string, body Device, expand string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["expand"] = autorest.Encode("query", expand) + } + + body.ID = nil + body.Provisioned = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DevicesClient) CreateResponder(resp *http.Response) (result Device, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateAttestation sends the create attestation request. +// Parameters: +// deviceID - unique ID of the device. +// body - individual device attestation body. +func (client DevicesClient) CreateAttestation(ctx context.Context, deviceID string, body BasicAttestation) (result AttestationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.CreateAttestation") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateAttestationPreparer(ctx, deviceID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateAttestation", nil, "Failure preparing request") + return + } + + resp, err := client.CreateAttestationSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateAttestation", resp, "Failure sending request") + return + } + + result, err = client.CreateAttestationResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateAttestation", resp, "Failure responding to request") + return + } + + return +} + +// CreateAttestationPreparer prepares the CreateAttestation request. +func (client DevicesClient) CreateAttestationPreparer(ctx context.Context, deviceID string, body BasicAttestation) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/attestation", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateAttestationSender sends the CreateAttestation request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) CreateAttestationSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateAttestationResponder handles the response to the CreateAttestation request. The method always +// closes the http.Response Body. +func (client DevicesClient) CreateAttestationResponder(resp *http.Response) (result AttestationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateRelationship create a device relationship +// Parameters: +// deviceID - unique ID of the device. +// relationshipID - unique ID of a relationship between devices. +// body - device relationship body. +func (client DevicesClient) CreateRelationship(ctx context.Context, deviceID string, relationshipID string, body DeviceRelationship) (result DeviceRelationship, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.CreateRelationship") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateRelationshipPreparer(ctx, deviceID, relationshipID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateRelationship", nil, "Failure preparing request") + return + } + + resp, err := client.CreateRelationshipSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateRelationship", resp, "Failure sending request") + return + } + + result, err = client.CreateRelationshipResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "CreateRelationship", resp, "Failure responding to request") + return + } + + return +} + +// CreateRelationshipPreparer prepares the CreateRelationship request. +func (client DevicesClient) CreateRelationshipPreparer(ctx context.Context, deviceID string, relationshipID string, body DeviceRelationship) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "relationshipId": autorest.Encode("path", relationshipID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/relationships/{relationshipId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateRelationshipSender sends the CreateRelationship request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) CreateRelationshipSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateRelationshipResponder handles the response to the CreateRelationship request. The method always +// closes the http.Response Body. +func (client DevicesClient) CreateRelationshipResponder(resp *http.Response) (result DeviceRelationship, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get details about an existing device by device ID. +// Parameters: +// deviceID - unique ID of the device. +// expand - the query parameter for including requested entities in response. +func (client DevicesClient) Get(ctx context.Context, deviceID string, expand string) (result Device, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: expand, + Constraints: []validation.Constraint{{Target: "expand", Name: validation.Empty, Rule: false, + Chain: []validation.Constraint{{Target: "expand", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "expand", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, deviceID, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DevicesClient) GetPreparer(ctx context.Context, deviceID string, expand string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetResponder(resp *http.Response) (result Device, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAttestation sends the get attestation request. +// Parameters: +// deviceID - unique ID of the device. +func (client DevicesClient) GetAttestation(ctx context.Context, deviceID string) (result AttestationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetAttestation") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAttestationPreparer(ctx, deviceID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetAttestation", nil, "Failure preparing request") + return + } + + resp, err := client.GetAttestationSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetAttestation", resp, "Failure sending request") + return + } + + result, err = client.GetAttestationResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetAttestation", resp, "Failure responding to request") + return + } + + return +} + +// GetAttestationPreparer prepares the GetAttestation request. +func (client DevicesClient) GetAttestationPreparer(ctx context.Context, deviceID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/attestation", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAttestationSender sends the GetAttestation request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetAttestationSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetAttestationResponder handles the response to the GetAttestation request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetAttestationResponder(resp *http.Response) (result AttestationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetCommandHistory sends the get command history request. +// Parameters: +// deviceID - unique ID of the device. +// commandName - name of this device command. +func (client DevicesClient) GetCommandHistory(ctx context.Context, deviceID string, commandName string) (result DeviceCommandCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetCommandHistory") + defer func() { + sc := -1 + if result.dcc.Response.Response != nil { + sc = result.dcc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.getCommandHistoryNextResults + req, err := client.GetCommandHistoryPreparer(ctx, deviceID, commandName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCommandHistory", nil, "Failure preparing request") + return + } + + resp, err := client.GetCommandHistorySender(req) + if err != nil { + result.dcc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCommandHistory", resp, "Failure sending request") + return + } + + result.dcc, err = client.GetCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCommandHistory", resp, "Failure responding to request") + return + } + if result.dcc.hasNextLink() && result.dcc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetCommandHistoryPreparer prepares the GetCommandHistory request. +func (client DevicesClient) GetCommandHistoryPreparer(ctx context.Context, deviceID string, commandName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/commands/{commandName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetCommandHistorySender sends the GetCommandHistory request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetCommandHistorySender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetCommandHistoryResponder handles the response to the GetCommandHistory request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetCommandHistoryResponder(resp *http.Response) (result DeviceCommandCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getCommandHistoryNextResults retrieves the next set of results, if any. +func (client DevicesClient) getCommandHistoryNextResults(ctx context.Context, lastResults DeviceCommandCollection) (result DeviceCommandCollection, err error) { + req, err := lastResults.deviceCommandCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getCommandHistoryNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetCommandHistorySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getCommandHistoryNextResults", resp, "Failure sending next results request") + } + result, err = client.GetCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getCommandHistoryNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetCommandHistoryComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) GetCommandHistoryComplete(ctx context.Context, deviceID string, commandName string) (result DeviceCommandCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetCommandHistory") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetCommandHistory(ctx, deviceID, commandName) + return +} + +// GetComponentCommandHistory sends the get component command history request. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// commandName - name of this device command. +func (client DevicesClient) GetComponentCommandHistory(ctx context.Context, deviceID string, componentName string, commandName string) (result DeviceCommandCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetComponentCommandHistory") + defer func() { + sc := -1 + if result.dcc.Response.Response != nil { + sc = result.dcc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.getComponentCommandHistoryNextResults + req, err := client.GetComponentCommandHistoryPreparer(ctx, deviceID, componentName, commandName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentCommandHistory", nil, "Failure preparing request") + return + } + + resp, err := client.GetComponentCommandHistorySender(req) + if err != nil { + result.dcc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentCommandHistory", resp, "Failure sending request") + return + } + + result.dcc, err = client.GetComponentCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentCommandHistory", resp, "Failure responding to request") + return + } + if result.dcc.hasNextLink() && result.dcc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetComponentCommandHistoryPreparer prepares the GetComponentCommandHistory request. +func (client DevicesClient) GetComponentCommandHistoryPreparer(ctx context.Context, deviceID string, componentName string, commandName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/commands/{commandName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetComponentCommandHistorySender sends the GetComponentCommandHistory request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetComponentCommandHistorySender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetComponentCommandHistoryResponder handles the response to the GetComponentCommandHistory request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetComponentCommandHistoryResponder(resp *http.Response) (result DeviceCommandCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getComponentCommandHistoryNextResults retrieves the next set of results, if any. +func (client DevicesClient) getComponentCommandHistoryNextResults(ctx context.Context, lastResults DeviceCommandCollection) (result DeviceCommandCollection, err error) { + req, err := lastResults.deviceCommandCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getComponentCommandHistoryNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetComponentCommandHistorySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getComponentCommandHistoryNextResults", resp, "Failure sending next results request") + } + result, err = client.GetComponentCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getComponentCommandHistoryNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetComponentCommandHistoryComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) GetComponentCommandHistoryComplete(ctx context.Context, deviceID string, componentName string, commandName string) (result DeviceCommandCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetComponentCommandHistory") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetComponentCommandHistory(ctx, deviceID, componentName, commandName) + return +} + +// GetComponentProperties sends the get component properties request. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) GetComponentProperties(ctx context.Context, deviceID string, componentName string, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetComponentPropertiesPreparer(ctx, deviceID, componentName, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.GetComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetComponentPropertiesPreparer prepares the GetComponentProperties request. +func (client DevicesClient) GetComponentPropertiesPreparer(ctx context.Context, deviceID string, componentName string, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/properties", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetComponentPropertiesSender sends the GetComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetComponentPropertiesResponder handles the response to the GetComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetComponentTelemetryValue get the last telemetry value from a component. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// telemetryName - name of this device telemetry. +func (client DevicesClient) GetComponentTelemetryValue(ctx context.Context, deviceID string, componentName string, telemetryName string) (result DeviceTelemetry, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetComponentTelemetryValue") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetComponentTelemetryValuePreparer(ctx, deviceID, componentName, telemetryName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentTelemetryValue", nil, "Failure preparing request") + return + } + + resp, err := client.GetComponentTelemetryValueSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentTelemetryValue", resp, "Failure sending request") + return + } + + result, err = client.GetComponentTelemetryValueResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetComponentTelemetryValue", resp, "Failure responding to request") + return + } + + return +} + +// GetComponentTelemetryValuePreparer prepares the GetComponentTelemetryValue request. +func (client DevicesClient) GetComponentTelemetryValuePreparer(ctx context.Context, deviceID string, componentName string, telemetryName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "telemetryName": autorest.Encode("path", telemetryName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/telemetry/{telemetryName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetComponentTelemetryValueSender sends the GetComponentTelemetryValue request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetComponentTelemetryValueSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetComponentTelemetryValueResponder handles the response to the GetComponentTelemetryValue request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetComponentTelemetryValueResponder(resp *http.Response) (result DeviceTelemetry, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetCredentials sends the get credentials request. +// Parameters: +// deviceID - unique ID of the device. +func (client DevicesClient) GetCredentials(ctx context.Context, deviceID string) (result DeviceCredentials, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetCredentials") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetCredentialsPreparer(ctx, deviceID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCredentials", nil, "Failure preparing request") + return + } + + resp, err := client.GetCredentialsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCredentials", resp, "Failure sending request") + return + } + + result, err = client.GetCredentialsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetCredentials", resp, "Failure responding to request") + return + } + + return +} + +// GetCredentialsPreparer prepares the GetCredentials request. +func (client DevicesClient) GetCredentialsPreparer(ctx context.Context, deviceID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/credentials", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetCredentialsSender sends the GetCredentials request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetCredentialsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetCredentialsResponder handles the response to the GetCredentials request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetCredentialsResponder(resp *http.Response) (result DeviceCredentials, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetModuleCommandHistory sends the get module command history request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// commandName - name of this device command. +func (client DevicesClient) GetModuleCommandHistory(ctx context.Context, deviceID string, moduleName string, commandName string) (result DeviceCommandCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleCommandHistory") + defer func() { + sc := -1 + if result.dcc.Response.Response != nil { + sc = result.dcc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.getModuleCommandHistoryNextResults + req, err := client.GetModuleCommandHistoryPreparer(ctx, deviceID, moduleName, commandName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleCommandHistory", nil, "Failure preparing request") + return + } + + resp, err := client.GetModuleCommandHistorySender(req) + if err != nil { + result.dcc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleCommandHistory", resp, "Failure sending request") + return + } + + result.dcc, err = client.GetModuleCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleCommandHistory", resp, "Failure responding to request") + return + } + if result.dcc.hasNextLink() && result.dcc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetModuleCommandHistoryPreparer prepares the GetModuleCommandHistory request. +func (client DevicesClient) GetModuleCommandHistoryPreparer(ctx context.Context, deviceID string, moduleName string, commandName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/commands/{commandName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModuleCommandHistorySender sends the GetModuleCommandHistory request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModuleCommandHistorySender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModuleCommandHistoryResponder handles the response to the GetModuleCommandHistory request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModuleCommandHistoryResponder(resp *http.Response) (result DeviceCommandCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getModuleCommandHistoryNextResults retrieves the next set of results, if any. +func (client DevicesClient) getModuleCommandHistoryNextResults(ctx context.Context, lastResults DeviceCommandCollection) (result DeviceCommandCollection, err error) { + req, err := lastResults.deviceCommandCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleCommandHistoryNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetModuleCommandHistorySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleCommandHistoryNextResults", resp, "Failure sending next results request") + } + result, err = client.GetModuleCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleCommandHistoryNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetModuleCommandHistoryComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) GetModuleCommandHistoryComplete(ctx context.Context, deviceID string, moduleName string, commandName string) (result DeviceCommandCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleCommandHistory") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetModuleCommandHistory(ctx, deviceID, moduleName, commandName) + return +} + +// GetModuleComponentCommandHistory sends the get module component command history request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +// commandName - name of this device command. +func (client DevicesClient) GetModuleComponentCommandHistory(ctx context.Context, deviceID string, moduleName string, componentName string, commandName string) (result DeviceCommandCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleComponentCommandHistory") + defer func() { + sc := -1 + if result.dcc.Response.Response != nil { + sc = result.dcc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.getModuleComponentCommandHistoryNextResults + req, err := client.GetModuleComponentCommandHistoryPreparer(ctx, deviceID, moduleName, componentName, commandName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentCommandHistory", nil, "Failure preparing request") + return + } + + resp, err := client.GetModuleComponentCommandHistorySender(req) + if err != nil { + result.dcc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentCommandHistory", resp, "Failure sending request") + return + } + + result.dcc, err = client.GetModuleComponentCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentCommandHistory", resp, "Failure responding to request") + return + } + if result.dcc.hasNextLink() && result.dcc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetModuleComponentCommandHistoryPreparer prepares the GetModuleComponentCommandHistory request. +func (client DevicesClient) GetModuleComponentCommandHistoryPreparer(ctx context.Context, deviceID string, moduleName string, componentName string, commandName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/commands/{commandName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModuleComponentCommandHistorySender sends the GetModuleComponentCommandHistory request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModuleComponentCommandHistorySender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModuleComponentCommandHistoryResponder handles the response to the GetModuleComponentCommandHistory request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModuleComponentCommandHistoryResponder(resp *http.Response) (result DeviceCommandCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getModuleComponentCommandHistoryNextResults retrieves the next set of results, if any. +func (client DevicesClient) getModuleComponentCommandHistoryNextResults(ctx context.Context, lastResults DeviceCommandCollection) (result DeviceCommandCollection, err error) { + req, err := lastResults.deviceCommandCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleComponentCommandHistoryNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetModuleComponentCommandHistorySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleComponentCommandHistoryNextResults", resp, "Failure sending next results request") + } + result, err = client.GetModuleComponentCommandHistoryResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "getModuleComponentCommandHistoryNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetModuleComponentCommandHistoryComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) GetModuleComponentCommandHistoryComplete(ctx context.Context, deviceID string, moduleName string, componentName string, commandName string) (result DeviceCommandCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleComponentCommandHistory") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetModuleComponentCommandHistory(ctx, deviceID, moduleName, componentName, commandName) + return +} + +// GetModuleComponentProperties sends the get module component properties request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +func (client DevicesClient) GetModuleComponentProperties(ctx context.Context, deviceID string, moduleName string, componentName string) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetModuleComponentPropertiesPreparer(ctx, deviceID, moduleName, componentName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetModuleComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.GetModuleComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetModuleComponentPropertiesPreparer prepares the GetModuleComponentProperties request. +func (client DevicesClient) GetModuleComponentPropertiesPreparer(ctx context.Context, deviceID string, moduleName string, componentName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/properties", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModuleComponentPropertiesSender sends the GetModuleComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModuleComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModuleComponentPropertiesResponder handles the response to the GetModuleComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModuleComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetModuleComponentTelemetryValue get the last telemetry value from a module component. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +// telemetryName - name of this device telemetry. +func (client DevicesClient) GetModuleComponentTelemetryValue(ctx context.Context, deviceID string, moduleName string, componentName string, telemetryName string) (result DeviceTelemetry, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleComponentTelemetryValue") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetModuleComponentTelemetryValuePreparer(ctx, deviceID, moduleName, componentName, telemetryName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentTelemetryValue", nil, "Failure preparing request") + return + } + + resp, err := client.GetModuleComponentTelemetryValueSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentTelemetryValue", resp, "Failure sending request") + return + } + + result, err = client.GetModuleComponentTelemetryValueResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleComponentTelemetryValue", resp, "Failure responding to request") + return + } + + return +} + +// GetModuleComponentTelemetryValuePreparer prepares the GetModuleComponentTelemetryValue request. +func (client DevicesClient) GetModuleComponentTelemetryValuePreparer(ctx context.Context, deviceID string, moduleName string, componentName string, telemetryName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + "telemetryName": autorest.Encode("path", telemetryName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/telemetry/{telemetryName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModuleComponentTelemetryValueSender sends the GetModuleComponentTelemetryValue request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModuleComponentTelemetryValueSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModuleComponentTelemetryValueResponder handles the response to the GetModuleComponentTelemetryValue request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModuleComponentTelemetryValueResponder(resp *http.Response) (result DeviceTelemetry, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetModuleProperties get all property values of a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +func (client DevicesClient) GetModuleProperties(ctx context.Context, deviceID string, moduleName string) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetModulePropertiesPreparer(ctx, deviceID, moduleName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetModulePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleProperties", resp, "Failure sending request") + return + } + + result, err = client.GetModulePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetModulePropertiesPreparer prepares the GetModuleProperties request. +func (client DevicesClient) GetModulePropertiesPreparer(ctx context.Context, deviceID string, moduleName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/properties", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModulePropertiesSender sends the GetModuleProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModulePropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModulePropertiesResponder handles the response to the GetModuleProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModulePropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetModuleTelemetryValue get the last telemetry value from a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// telemetryName - name of this device telemetry. +func (client DevicesClient) GetModuleTelemetryValue(ctx context.Context, deviceID string, moduleName string, telemetryName string) (result DeviceTelemetry, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetModuleTelemetryValue") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetModuleTelemetryValuePreparer(ctx, deviceID, moduleName, telemetryName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleTelemetryValue", nil, "Failure preparing request") + return + } + + resp, err := client.GetModuleTelemetryValueSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleTelemetryValue", resp, "Failure sending request") + return + } + + result, err = client.GetModuleTelemetryValueResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetModuleTelemetryValue", resp, "Failure responding to request") + return + } + + return +} + +// GetModuleTelemetryValuePreparer prepares the GetModuleTelemetryValue request. +func (client DevicesClient) GetModuleTelemetryValuePreparer(ctx context.Context, deviceID string, moduleName string, telemetryName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + "telemetryName": autorest.Encode("path", telemetryName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/telemetry/{telemetryName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetModuleTelemetryValueSender sends the GetModuleTelemetryValue request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetModuleTelemetryValueSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetModuleTelemetryValueResponder handles the response to the GetModuleTelemetryValue request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetModuleTelemetryValueResponder(resp *http.Response) (result DeviceTelemetry, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetProperties get all property values of a device by device ID. +// Parameters: +// deviceID - unique ID of the device. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) GetProperties(ctx context.Context, deviceID string, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPropertiesPreparer(ctx, deviceID, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetProperties", resp, "Failure sending request") + return + } + + result, err = client.GetPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetProperties", resp, "Failure responding to request") + return + } + + return +} + +// GetPropertiesPreparer prepares the GetProperties request. +func (client DevicesClient) GetPropertiesPreparer(ctx context.Context, deviceID string, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/properties", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetPropertiesSender sends the GetProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetPropertiesResponder handles the response to the GetProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetRelationship get device relationship by ID +// Parameters: +// deviceID - unique ID of the device. +// relationshipID - unique ID of a relationship between devices. +func (client DevicesClient) GetRelationship(ctx context.Context, deviceID string, relationshipID string) (result DeviceRelationship, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetRelationship") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetRelationshipPreparer(ctx, deviceID, relationshipID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetRelationship", nil, "Failure preparing request") + return + } + + resp, err := client.GetRelationshipSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetRelationship", resp, "Failure sending request") + return + } + + result, err = client.GetRelationshipResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetRelationship", resp, "Failure responding to request") + return + } + + return +} + +// GetRelationshipPreparer prepares the GetRelationship request. +func (client DevicesClient) GetRelationshipPreparer(ctx context.Context, deviceID string, relationshipID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "relationshipId": autorest.Encode("path", relationshipID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/relationships/{relationshipId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetRelationshipSender sends the GetRelationship request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetRelationshipSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetRelationshipResponder handles the response to the GetRelationship request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetRelationshipResponder(resp *http.Response) (result DeviceRelationship, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetTelemetryValue get the last telemetry value from a device. +// Parameters: +// deviceID - unique ID of the device. +// telemetryName - name of this device telemetry. +func (client DevicesClient) GetTelemetryValue(ctx context.Context, deviceID string, telemetryName string) (result DeviceTelemetry, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.GetTelemetryValue") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetTelemetryValuePreparer(ctx, deviceID, telemetryName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetTelemetryValue", nil, "Failure preparing request") + return + } + + resp, err := client.GetTelemetryValueSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetTelemetryValue", resp, "Failure sending request") + return + } + + result, err = client.GetTelemetryValueResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "GetTelemetryValue", resp, "Failure responding to request") + return + } + + return +} + +// GetTelemetryValuePreparer prepares the GetTelemetryValue request. +func (client DevicesClient) GetTelemetryValuePreparer(ctx context.Context, deviceID string, telemetryName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "telemetryName": autorest.Encode("path", telemetryName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/telemetry/{telemetryName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetTelemetryValueSender sends the GetTelemetryValue request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) GetTelemetryValueSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetTelemetryValueResponder handles the response to the GetTelemetryValue request. The method always +// closes the http.Response Body. +func (client DevicesClient) GetTelemetryValueResponder(resp *http.Response) (result DeviceTelemetry, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// filter - an expression on the resource type that selects the resources to be returned. +// maxpagesize - the maximum number of resources to return from one response. +// orderby - an expression that specify the order of the returned resources. +// expand - the query parameter for including requested entities in response. +func (client DevicesClient) List(ctx context.Context, filter string, maxpagesize *int32, orderby string, expand string) (result DeviceCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.List") + defer func() { + sc := -1 + if result.dc.Response.Response != nil { + sc = result.dc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}, + {TargetValue: expand, + Constraints: []validation.Constraint{{Target: "expand", Name: validation.Empty, Rule: false, + Chain: []validation.Constraint{{Target: "expand", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "expand", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, filter, maxpagesize, orderby, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "List", resp, "Failure sending request") + return + } + + result.dc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "List", resp, "Failure responding to request") + return + } + if result.dc.hasNextLink() && result.dc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DevicesClient) ListPreparer(ctx context.Context, filter string, maxpagesize *int32, orderby string, expand string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["filter"] = autorest.Encode("query", filter) + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + if len(orderby) > 0 { + queryParameters["orderby"] = autorest.Encode("query", orderby) + } + if len(expand) > 0 { + queryParameters["expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/devices"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DevicesClient) ListResponder(resp *http.Response) (result DeviceCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DevicesClient) listNextResults(ctx context.Context, lastResults DeviceCollection) (result DeviceCollection, err error) { + req, err := lastResults.deviceCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) ListComplete(ctx context.Context, filter string, maxpagesize *int32, orderby string, expand string) (result DeviceCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, filter, maxpagesize, orderby, expand) + return +} + +// ListComponents sends the list components request. +// Parameters: +// deviceID - unique ID of the device. +func (client DevicesClient) ListComponents(ctx context.Context, deviceID string) (result Collection, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ListComponents") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListComponentsPreparer(ctx, deviceID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListComponents", nil, "Failure preparing request") + return + } + + resp, err := client.ListComponentsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListComponents", resp, "Failure sending request") + return + } + + result, err = client.ListComponentsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListComponents", resp, "Failure responding to request") + return + } + + return +} + +// ListComponentsPreparer prepares the ListComponents request. +func (client DevicesClient) ListComponentsPreparer(ctx context.Context, deviceID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListComponentsSender sends the ListComponents request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ListComponentsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListComponentsResponder handles the response to the ListComponents request. The method always +// closes the http.Response Body. +func (client DevicesClient) ListComponentsResponder(resp *http.Response) (result Collection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListModuleComponents sends the list module components request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +func (client DevicesClient) ListModuleComponents(ctx context.Context, deviceID string, moduleName string) (result Collection, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ListModuleComponents") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListModuleComponentsPreparer(ctx, deviceID, moduleName) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModuleComponents", nil, "Failure preparing request") + return + } + + resp, err := client.ListModuleComponentsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModuleComponents", resp, "Failure sending request") + return + } + + result, err = client.ListModuleComponentsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModuleComponents", resp, "Failure responding to request") + return + } + + return +} + +// ListModuleComponentsPreparer prepares the ListModuleComponents request. +func (client DevicesClient) ListModuleComponentsPreparer(ctx context.Context, deviceID string, moduleName string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListModuleComponentsSender sends the ListModuleComponents request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ListModuleComponentsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListModuleComponentsResponder handles the response to the ListModuleComponents request. The method always +// closes the http.Response Body. +func (client DevicesClient) ListModuleComponentsResponder(resp *http.Response) (result Collection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListModules sends the list modules request. +// Parameters: +// deviceID - unique ID of the device. +func (client DevicesClient) ListModules(ctx context.Context, deviceID string) (result Collection, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ListModules") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListModulesPreparer(ctx, deviceID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModules", nil, "Failure preparing request") + return + } + + resp, err := client.ListModulesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModules", resp, "Failure sending request") + return + } + + result, err = client.ListModulesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListModules", resp, "Failure responding to request") + return + } + + return +} + +// ListModulesPreparer prepares the ListModules request. +func (client DevicesClient) ListModulesPreparer(ctx context.Context, deviceID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListModulesSender sends the ListModules request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ListModulesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListModulesResponder handles the response to the ListModules request. The method always +// closes the http.Response Body. +func (client DevicesClient) ListModulesResponder(resp *http.Response) (result Collection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListRelationships list all relationships based on device ID +// Parameters: +// deviceID - unique ID of the device. +// maxpagesize - the maximum number of resources to return from one response. +func (client DevicesClient) ListRelationships(ctx context.Context, deviceID string, maxpagesize *int32) (result DeviceRelationshipCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ListRelationships") + defer func() { + sc := -1 + if result.drc.Response.Response != nil { + sc = result.drc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ListRelationships", err.Error()) + } + + result.fn = client.listRelationshipsNextResults + req, err := client.ListRelationshipsPreparer(ctx, deviceID, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListRelationships", nil, "Failure preparing request") + return + } + + resp, err := client.ListRelationshipsSender(req) + if err != nil { + result.drc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListRelationships", resp, "Failure sending request") + return + } + + result.drc, err = client.ListRelationshipsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ListRelationships", resp, "Failure responding to request") + return + } + if result.drc.hasNextLink() && result.drc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListRelationshipsPreparer prepares the ListRelationships request. +func (client DevicesClient) ListRelationshipsPreparer(ctx context.Context, deviceID string, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/relationships", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListRelationshipsSender sends the ListRelationships request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ListRelationshipsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListRelationshipsResponder handles the response to the ListRelationships request. The method always +// closes the http.Response Body. +func (client DevicesClient) ListRelationshipsResponder(resp *http.Response) (result DeviceRelationshipCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listRelationshipsNextResults retrieves the next set of results, if any. +func (client DevicesClient) listRelationshipsNextResults(ctx context.Context, lastResults DeviceRelationshipCollection) (result DeviceRelationshipCollection, err error) { + req, err := lastResults.deviceRelationshipCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listRelationshipsNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListRelationshipsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listRelationshipsNextResults", resp, "Failure sending next results request") + } + result, err = client.ListRelationshipsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "listRelationshipsNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListRelationshipsComplete enumerates all values, automatically crossing page boundaries as required. +func (client DevicesClient) ListRelationshipsComplete(ctx context.Context, deviceID string, maxpagesize *int32) (result DeviceRelationshipCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ListRelationships") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListRelationships(ctx, deviceID, maxpagesize) + return +} + +// Remove delete an existing device by device ID. +// Parameters: +// deviceID - unique ID of the device. +// expand - the query parameter for including requested entities in response. +func (client DevicesClient) Remove(ctx context.Context, deviceID string, expand string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: expand, + Constraints: []validation.Constraint{{Target: "expand", Name: validation.Empty, Rule: false, + Chain: []validation.Constraint{{Target: "expand", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "expand", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, deviceID, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DevicesClient) RemovePreparer(ctx context.Context, deviceID string, expand string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DevicesClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// RemoveAttestation sends the remove attestation request. +// Parameters: +// deviceID - unique ID of the device. +func (client DevicesClient) RemoveAttestation(ctx context.Context, deviceID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RemoveAttestation") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemoveAttestationPreparer(ctx, deviceID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveAttestation", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveAttestationSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveAttestation", resp, "Failure sending request") + return + } + + result, err = client.RemoveAttestationResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveAttestation", resp, "Failure responding to request") + return + } + + return +} + +// RemoveAttestationPreparer prepares the RemoveAttestation request. +func (client DevicesClient) RemoveAttestationPreparer(ctx context.Context, deviceID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/attestation", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveAttestationSender sends the RemoveAttestation request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RemoveAttestationSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveAttestationResponder handles the response to the RemoveAttestation request. The method always +// closes the http.Response Body. +func (client DevicesClient) RemoveAttestationResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// RemoveRelationship delete a device relationship +// Parameters: +// deviceID - unique ID of the device. +// relationshipID - unique ID of a relationship between devices. +func (client DevicesClient) RemoveRelationship(ctx context.Context, deviceID string, relationshipID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RemoveRelationship") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemoveRelationshipPreparer(ctx, deviceID, relationshipID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveRelationship", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveRelationshipSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveRelationship", resp, "Failure sending request") + return + } + + result, err = client.RemoveRelationshipResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RemoveRelationship", resp, "Failure responding to request") + return + } + + return +} + +// RemoveRelationshipPreparer prepares the RemoveRelationship request. +func (client DevicesClient) RemoveRelationshipPreparer(ctx context.Context, deviceID string, relationshipID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "relationshipId": autorest.Encode("path", relationshipID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/relationships/{relationshipId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveRelationshipSender sends the RemoveRelationship request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RemoveRelationshipSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveRelationshipResponder handles the response to the RemoveRelationship request. The method always +// closes the http.Response Body. +func (client DevicesClient) RemoveRelationshipResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// ReplaceComponentProperties sends the replace component properties request. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// body - device properties. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) ReplaceComponentProperties(ctx context.Context, deviceID string, componentName string, body map[string]interface{}, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ReplaceComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ReplaceComponentProperties", err.Error()) + } + + req, err := client.ReplaceComponentPropertiesPreparer(ctx, deviceID, componentName, body, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.ReplaceComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.ReplaceComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// ReplaceComponentPropertiesPreparer prepares the ReplaceComponentProperties request. +func (client DevicesClient) ReplaceComponentPropertiesPreparer(ctx context.Context, deviceID string, componentName string, body map[string]interface{}, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplaceComponentPropertiesSender sends the ReplaceComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ReplaceComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplaceComponentPropertiesResponder handles the response to the ReplaceComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) ReplaceComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ReplaceModuleComponentProperties sends the replace module component properties request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +// body - module properties. +func (client DevicesClient) ReplaceModuleComponentProperties(ctx context.Context, deviceID string, moduleName string, componentName string, body map[string]interface{}) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ReplaceModuleComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ReplaceModuleComponentProperties", err.Error()) + } + + req, err := client.ReplaceModuleComponentPropertiesPreparer(ctx, deviceID, moduleName, componentName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.ReplaceModuleComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.ReplaceModuleComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// ReplaceModuleComponentPropertiesPreparer prepares the ReplaceModuleComponentProperties request. +func (client DevicesClient) ReplaceModuleComponentPropertiesPreparer(ctx context.Context, deviceID string, moduleName string, componentName string, body map[string]interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplaceModuleComponentPropertiesSender sends the ReplaceModuleComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ReplaceModuleComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplaceModuleComponentPropertiesResponder handles the response to the ReplaceModuleComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) ReplaceModuleComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ReplaceModuleProperties replace all property values of a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// body - module properties. +func (client DevicesClient) ReplaceModuleProperties(ctx context.Context, deviceID string, moduleName string, body map[string]interface{}) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ReplaceModuleProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ReplaceModuleProperties", err.Error()) + } + + req, err := client.ReplaceModulePropertiesPreparer(ctx, deviceID, moduleName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleProperties", nil, "Failure preparing request") + return + } + + resp, err := client.ReplaceModulePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleProperties", resp, "Failure sending request") + return + } + + result, err = client.ReplaceModulePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceModuleProperties", resp, "Failure responding to request") + return + } + + return +} + +// ReplaceModulePropertiesPreparer prepares the ReplaceModuleProperties request. +func (client DevicesClient) ReplaceModulePropertiesPreparer(ctx context.Context, deviceID string, moduleName string, body map[string]interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplaceModulePropertiesSender sends the ReplaceModuleProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ReplaceModulePropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplaceModulePropertiesResponder handles the response to the ReplaceModuleProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) ReplaceModulePropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ReplaceProperties replace all property values of a device by device ID. +// Parameters: +// deviceID - unique ID of the device. +// body - device properties. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) ReplaceProperties(ctx context.Context, deviceID string, body map[string]interface{}, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.ReplaceProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "ReplaceProperties", err.Error()) + } + + req, err := client.ReplacePropertiesPreparer(ctx, deviceID, body, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceProperties", nil, "Failure preparing request") + return + } + + resp, err := client.ReplacePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceProperties", resp, "Failure sending request") + return + } + + result, err = client.ReplacePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "ReplaceProperties", resp, "Failure responding to request") + return + } + + return +} + +// ReplacePropertiesPreparer prepares the ReplaceProperties request. +func (client DevicesClient) ReplacePropertiesPreparer(ctx context.Context, deviceID string, body map[string]interface{}, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplacePropertiesSender sends the ReplaceProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) ReplacePropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplacePropertiesResponder handles the response to the ReplaceProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) ReplacePropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RunCommand run a command on a device. +// Parameters: +// deviceID - unique ID of the device. +// commandName - name of this device command. +// body - device command body. +func (client DevicesClient) RunCommand(ctx context.Context, deviceID string, commandName string, body DeviceCommand) (result DeviceCommand, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RunCommand") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ConnectionTimeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, + }}, + {Target: "body.ResponseTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ResponseTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ResponseTimeout", Name: validation.InclusiveMinimum, Rule: int64(5), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "RunCommand", err.Error()) + } + + req, err := client.RunCommandPreparer(ctx, deviceID, commandName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunCommand", nil, "Failure preparing request") + return + } + + resp, err := client.RunCommandSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunCommand", resp, "Failure sending request") + return + } + + result, err = client.RunCommandResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunCommand", resp, "Failure responding to request") + return + } + + return +} + +// RunCommandPreparer prepares the RunCommand request. +func (client DevicesClient) RunCommandPreparer(ctx context.Context, deviceID string, commandName string, body DeviceCommand) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.ResponseCode = nil + body.APIResponse = "" + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/commands/{commandName}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RunCommandSender sends the RunCommand request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RunCommandSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RunCommandResponder handles the response to the RunCommand request. The method always +// closes the http.Response Body. +func (client DevicesClient) RunCommandResponder(resp *http.Response) (result DeviceCommand, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RunComponentCommand run a command on a component. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// commandName - name of this device command. +// body - device command body. +func (client DevicesClient) RunComponentCommand(ctx context.Context, deviceID string, componentName string, commandName string, body DeviceCommand) (result DeviceCommand, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RunComponentCommand") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ConnectionTimeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, + }}, + {Target: "body.ResponseTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ResponseTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ResponseTimeout", Name: validation.InclusiveMinimum, Rule: int64(5), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "RunComponentCommand", err.Error()) + } + + req, err := client.RunComponentCommandPreparer(ctx, deviceID, componentName, commandName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunComponentCommand", nil, "Failure preparing request") + return + } + + resp, err := client.RunComponentCommandSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunComponentCommand", resp, "Failure sending request") + return + } + + result, err = client.RunComponentCommandResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunComponentCommand", resp, "Failure responding to request") + return + } + + return +} + +// RunComponentCommandPreparer prepares the RunComponentCommand request. +func (client DevicesClient) RunComponentCommandPreparer(ctx context.Context, deviceID string, componentName string, commandName string, body DeviceCommand) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.ResponseCode = nil + body.APIResponse = "" + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/commands/{commandName}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RunComponentCommandSender sends the RunComponentCommand request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RunComponentCommandSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RunComponentCommandResponder handles the response to the RunComponentCommand request. The method always +// closes the http.Response Body. +func (client DevicesClient) RunComponentCommandResponder(resp *http.Response) (result DeviceCommand, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RunModuleCommand run a command on a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// commandName - name of this device command. +// body - device command body. +func (client DevicesClient) RunModuleCommand(ctx context.Context, deviceID string, moduleName string, commandName string, body DeviceCommand) (result DeviceCommand, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RunModuleCommand") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ConnectionTimeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, + }}, + {Target: "body.ResponseTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ResponseTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ResponseTimeout", Name: validation.InclusiveMinimum, Rule: int64(5), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "RunModuleCommand", err.Error()) + } + + req, err := client.RunModuleCommandPreparer(ctx, deviceID, moduleName, commandName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleCommand", nil, "Failure preparing request") + return + } + + resp, err := client.RunModuleCommandSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleCommand", resp, "Failure sending request") + return + } + + result, err = client.RunModuleCommandResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleCommand", resp, "Failure responding to request") + return + } + + return +} + +// RunModuleCommandPreparer prepares the RunModuleCommand request. +func (client DevicesClient) RunModuleCommandPreparer(ctx context.Context, deviceID string, moduleName string, commandName string, body DeviceCommand) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.ResponseCode = nil + body.APIResponse = "" + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/commands/{commandName}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RunModuleCommandSender sends the RunModuleCommand request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RunModuleCommandSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RunModuleCommandResponder handles the response to the RunModuleCommand request. The method always +// closes the http.Response Body. +func (client DevicesClient) RunModuleCommandResponder(resp *http.Response) (result DeviceCommand, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RunModuleComponentCommand run a command on a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +// commandName - name of this device command. +// body - device command body. +func (client DevicesClient) RunModuleComponentCommand(ctx context.Context, deviceID string, moduleName string, componentName string, commandName string, body DeviceCommand) (result DeviceCommand, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.RunModuleComponentCommand") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ConnectionTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ConnectionTimeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, + }}, + {Target: "body.ResponseTimeout", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.ResponseTimeout", Name: validation.InclusiveMaximum, Rule: int64(30), Chain: nil}, + {Target: "body.ResponseTimeout", Name: validation.InclusiveMinimum, Rule: int64(5), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "RunModuleComponentCommand", err.Error()) + } + + req, err := client.RunModuleComponentCommandPreparer(ctx, deviceID, moduleName, componentName, commandName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleComponentCommand", nil, "Failure preparing request") + return + } + + resp, err := client.RunModuleComponentCommandSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleComponentCommand", resp, "Failure sending request") + return + } + + result, err = client.RunModuleComponentCommandResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "RunModuleComponentCommand", resp, "Failure responding to request") + return + } + + return +} + +// RunModuleComponentCommandPreparer prepares the RunModuleComponentCommand request. +func (client DevicesClient) RunModuleComponentCommandPreparer(ctx context.Context, deviceID string, moduleName string, componentName string, commandName string, body DeviceCommand) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "commandName": autorest.Encode("path", commandName), + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.ResponseCode = nil + body.APIResponse = "" + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/commands/{commandName}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RunModuleComponentCommandSender sends the RunModuleComponentCommand request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) RunModuleComponentCommandSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RunModuleComponentCommandResponder handles the response to the RunModuleComponentCommand request. The method always +// closes the http.Response Body. +func (client DevicesClient) RunModuleComponentCommandResponder(resp *http.Response) (result DeviceCommand, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update update an existing device by ID. +// Parameters: +// deviceID - unique ID of the device. +// body - device patch body. +// expand - the query parameter for including requested entities in response. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DevicesClient) Update(ctx context.Context, deviceID string, body interface{}, expand string, ifMatch string) (result Device, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: expand, + Constraints: []validation.Constraint{{Target: "expand", Name: validation.Empty, Rule: false, + Chain: []validation.Constraint{{Target: "expand", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "expand", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DevicesClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, deviceID, body, expand, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DevicesClient) UpdatePreparer(ctx context.Context, deviceID string, body interface{}, expand string, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateResponder(resp *http.Response) (result Device, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateAttestation sends the update attestation request. +// Parameters: +// deviceID - unique ID of the device. +// body - individual device attestation patch body. +func (client DevicesClient) UpdateAttestation(ctx context.Context, deviceID string, body interface{}) (result AttestationModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateAttestation") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdateAttestationPreparer(ctx, deviceID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateAttestation", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateAttestationSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateAttestation", resp, "Failure sending request") + return + } + + result, err = client.UpdateAttestationResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateAttestation", resp, "Failure responding to request") + return + } + + return +} + +// UpdateAttestationPreparer prepares the UpdateAttestation request. +func (client DevicesClient) UpdateAttestationPreparer(ctx context.Context, deviceID string, body interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/attestation", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateAttestationSender sends the UpdateAttestation request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateAttestationSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateAttestationResponder handles the response to the UpdateAttestation request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateAttestationResponder(resp *http.Response) (result AttestationModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateComponentProperties sends the update component properties request. +// Parameters: +// deviceID - unique ID of the device. +// componentName - name of the device component. +// body - device properties patch. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) UpdateComponentProperties(ctx context.Context, deviceID string, componentName string, body interface{}, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdateComponentPropertiesPreparer(ctx, deviceID, componentName, body, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.UpdateComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// UpdateComponentPropertiesPreparer prepares the UpdateComponentProperties request. +func (client DevicesClient) UpdateComponentPropertiesPreparer(ctx context.Context, deviceID string, componentName string, body interface{}, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/components/{componentName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateComponentPropertiesSender sends the UpdateComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateComponentPropertiesResponder handles the response to the UpdateComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateModuleComponentProperties sends the update module component properties request. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// componentName - name of the device component. +// body - module properties patch. +func (client DevicesClient) UpdateModuleComponentProperties(ctx context.Context, deviceID string, moduleName string, componentName string, body interface{}) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateModuleComponentProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdateModuleComponentPropertiesPreparer(ctx, deviceID, moduleName, componentName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleComponentProperties", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateModuleComponentPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleComponentProperties", resp, "Failure sending request") + return + } + + result, err = client.UpdateModuleComponentPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleComponentProperties", resp, "Failure responding to request") + return + } + + return +} + +// UpdateModuleComponentPropertiesPreparer prepares the UpdateModuleComponentProperties request. +func (client DevicesClient) UpdateModuleComponentPropertiesPreparer(ctx context.Context, deviceID string, moduleName string, componentName string, body interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "componentName": autorest.Encode("path", componentName), + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/components/{componentName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateModuleComponentPropertiesSender sends the UpdateModuleComponentProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateModuleComponentPropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateModuleComponentPropertiesResponder handles the response to the UpdateModuleComponentProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateModuleComponentPropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateModuleProperties update property values of a module. +// Parameters: +// deviceID - unique ID of the device. +// moduleName - name of the device module. +// body - module properties patch. +func (client DevicesClient) UpdateModuleProperties(ctx context.Context, deviceID string, moduleName string, body interface{}) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateModuleProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdateModulePropertiesPreparer(ctx, deviceID, moduleName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleProperties", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateModulePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleProperties", resp, "Failure sending request") + return + } + + result, err = client.UpdateModulePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateModuleProperties", resp, "Failure responding to request") + return + } + + return +} + +// UpdateModulePropertiesPreparer prepares the UpdateModuleProperties request. +func (client DevicesClient) UpdateModulePropertiesPreparer(ctx context.Context, deviceID string, moduleName string, body interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "moduleName": autorest.Encode("path", moduleName), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/modules/{moduleName}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateModulePropertiesSender sends the UpdateModuleProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateModulePropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateModulePropertiesResponder handles the response to the UpdateModuleProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateModulePropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateProperties update property values of a device by device ID. +// Parameters: +// deviceID - unique ID of the device. +// body - device properties patch. +// unmodeled - the query parameter for supporting unmodeled properties. +func (client DevicesClient) UpdateProperties(ctx context.Context, deviceID string, body interface{}, unmodeled *bool) (result SetSetObject, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateProperties") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePropertiesPreparer(ctx, deviceID, body, unmodeled) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateProperties", nil, "Failure preparing request") + return + } + + resp, err := client.UpdatePropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateProperties", resp, "Failure sending request") + return + } + + result, err = client.UpdatePropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateProperties", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePropertiesPreparer prepares the UpdateProperties request. +func (client DevicesClient) UpdatePropertiesPreparer(ctx context.Context, deviceID string, body interface{}, unmodeled *bool) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if unmodeled != nil { + queryParameters["unmodeled"] = autorest.Encode("query", *unmodeled) + } else { + queryParameters["unmodeled"] = autorest.Encode("query", false) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/properties", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdatePropertiesSender sends the UpdateProperties request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdatePropertiesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdatePropertiesResponder handles the response to the UpdateProperties request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdatePropertiesResponder(resp *http.Response) (result SetSetObject, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// UpdateRelationship update device relationship +// Parameters: +// deviceID - unique ID of the device. +// relationshipID - unique ID of a relationship between devices. +// body - device relationship patch body. +func (client DevicesClient) UpdateRelationship(ctx context.Context, deviceID string, relationshipID string, body interface{}) (result DeviceRelationship, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DevicesClient.UpdateRelationship") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdateRelationshipPreparer(ctx, deviceID, relationshipID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateRelationship", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateRelationshipSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateRelationship", resp, "Failure sending request") + return + } + + result, err = client.UpdateRelationshipResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DevicesClient", "UpdateRelationship", resp, "Failure responding to request") + return + } + + return +} + +// UpdateRelationshipPreparer prepares the UpdateRelationship request. +func (client DevicesClient) UpdateRelationshipPreparer(ctx context.Context, deviceID string, relationshipID string, body interface{}) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceId": autorest.Encode("path", deviceID), + "relationshipId": autorest.Encode("path", relationshipID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/devices/{deviceId}/relationships/{relationshipId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateRelationshipSender sends the UpdateRelationship request. The method will close the +// http.Response Body if it receives an error. +func (client DevicesClient) UpdateRelationshipSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateRelationshipResponder handles the response to the UpdateRelationship request. The method always +// closes the http.Response Body. +func (client DevicesClient) UpdateRelationshipResponder(resp *http.Response) (result DeviceRelationship, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicetemplates.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicetemplates.go new file mode 100644 index 000000000000..8f246c73f25d --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/devicetemplates.go @@ -0,0 +1,503 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// DeviceTemplatesClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your +// IoT devices at scale. +type DeviceTemplatesClient struct { + BaseClient +} + +// NewDeviceTemplatesClient creates an instance of the DeviceTemplatesClient client. +func NewDeviceTemplatesClient(subdomain string) DeviceTemplatesClient { + return DeviceTemplatesClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// deviceTemplateID - unique [Digital Twin Model +// Identifier](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md#digital-twin-model-identifier) +// of the device template. +// body - device template body. +func (client DeviceTemplatesClient) Create(ctx context.Context, deviceTemplateID string, body DeviceTemplate) (result DeviceTemplate, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Type", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.CapabilityModel", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceTemplatesClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, deviceTemplateID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client DeviceTemplatesClient) CreatePreparer(ctx context.Context, deviceTemplateID string, body DeviceTemplate) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceTemplateId": autorest.Encode("path", deviceTemplateID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceTemplates/{deviceTemplateId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceTemplatesClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client DeviceTemplatesClient) CreateResponder(resp *http.Response) (result DeviceTemplate, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// deviceTemplateID - unique [Digital Twin Model +// Identifier](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md#digital-twin-model-identifier) +// of the device template. +func (client DeviceTemplatesClient) Get(ctx context.Context, deviceTemplateID string) (result DeviceTemplate, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, deviceTemplateID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DeviceTemplatesClient) GetPreparer(ctx context.Context, deviceTemplateID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceTemplateId": autorest.Encode("path", deviceTemplateID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceTemplates/{deviceTemplateId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceTemplatesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DeviceTemplatesClient) GetResponder(resp *http.Response) (result DeviceTemplate, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// filter - an expression on the resource type that selects the resources to be returned. +// maxpagesize - the maximum number of resources to return from one response. +// orderby - an expression that specify the order of the returned resources. +func (client DeviceTemplatesClient) List(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DeviceTemplateCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.List") + defer func() { + sc := -1 + if result.dtc.Response.Response != nil { + sc = result.dtc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.DeviceTemplatesClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, filter, maxpagesize, orderby) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dtc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "List", resp, "Failure sending request") + return + } + + result.dtc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "List", resp, "Failure responding to request") + return + } + if result.dtc.hasNextLink() && result.dtc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DeviceTemplatesClient) ListPreparer(ctx context.Context, filter string, maxpagesize *int32, orderby string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["filter"] = autorest.Encode("query", filter) + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + if len(orderby) > 0 { + queryParameters["orderby"] = autorest.Encode("query", orderby) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/deviceTemplates"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceTemplatesClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DeviceTemplatesClient) ListResponder(resp *http.Response) (result DeviceTemplateCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DeviceTemplatesClient) listNextResults(ctx context.Context, lastResults DeviceTemplateCollection) (result DeviceTemplateCollection, err error) { + req, err := lastResults.deviceTemplateCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DeviceTemplatesClient) ListComplete(ctx context.Context, filter string, maxpagesize *int32, orderby string) (result DeviceTemplateCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, filter, maxpagesize, orderby) + return +} + +// Remove delete an existing device template by device ID. +// Parameters: +// deviceTemplateID - unique [Digital Twin Model +// Identifier](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md#digital-twin-model-identifier) +// of the device template. +func (client DeviceTemplatesClient) Remove(ctx context.Context, deviceTemplateID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemovePreparer(ctx, deviceTemplateID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client DeviceTemplatesClient) RemovePreparer(ctx context.Context, deviceTemplateID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceTemplateId": autorest.Encode("path", deviceTemplateID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceTemplates/{deviceTemplateId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceTemplatesClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client DeviceTemplatesClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// deviceTemplateID - unique [Digital Twin Model +// Identifier](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/dtdlv2.md#digital-twin-model-identifier) +// of the device template. +// body - device template patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client DeviceTemplatesClient) Update(ctx context.Context, deviceTemplateID string, body interface{}, ifMatch string) (result DeviceTemplate, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplatesClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, deviceTemplateID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.DeviceTemplatesClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DeviceTemplatesClient) UpdatePreparer(ctx context.Context, deviceTemplateID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "deviceTemplateId": autorest.Encode("path", deviceTemplateID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/deviceTemplates/{deviceTemplateId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DeviceTemplatesClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DeviceTemplatesClient) UpdateResponder(resp *http.Response) (result DeviceTemplate, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enrollmentgroups.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enrollmentgroups.go new file mode 100644 index 000000000000..e63777ca5865 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enrollmentgroups.go @@ -0,0 +1,944 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// EnrollmentGroupsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your +// IoT devices at scale. +type EnrollmentGroupsClient struct { + BaseClient +} + +// NewEnrollmentGroupsClient creates an instance of the EnrollmentGroupsClient client. +func NewEnrollmentGroupsClient(subdomain string) EnrollmentGroupsClient { + return EnrollmentGroupsClient{New(subdomain)} +} + +// Create create an enrollment group. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// body - enrollment group body. +func (client EnrollmentGroupsClient) Create(ctx context.Context, enrollmentGroupID string, body EnrollmentGroup) (result EnrollmentGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, enrollmentGroupID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client EnrollmentGroupsClient) CreatePreparer(ctx context.Context, enrollmentGroupID string, body EnrollmentGroup) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.IDScope = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) CreateResponder(resp *http.Response) (result EnrollmentGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateX509 sets the primary or secondary x509 certificate of an enrollment group. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// entry - entry of certificate only support primary and secondary. +// body - certificate definition. +func (client EnrollmentGroupsClient) CreateX509(ctx context.Context, enrollmentGroupID string, entry CertificateEntry, body SigningX509Certificate) (result SigningX509Certificate, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.CreateX509") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Info", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Info.Sha1Thumbprint", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "CreateX509", err.Error()) + } + + req, err := client.CreateX509Preparer(ctx, enrollmentGroupID, entry, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "CreateX509", nil, "Failure preparing request") + return + } + + resp, err := client.CreateX509Sender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "CreateX509", resp, "Failure sending request") + return + } + + result, err = client.CreateX509Responder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "CreateX509", resp, "Failure responding to request") + return + } + + return +} + +// CreateX509Preparer prepares the CreateX509 request. +func (client EnrollmentGroupsClient) CreateX509Preparer(ctx context.Context, enrollmentGroupID string, entry CertificateEntry, body SigningX509Certificate) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + "entry": autorest.Encode("path", entry), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.Info = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}/certificates/{entry}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateX509Sender sends the CreateX509 request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) CreateX509Sender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateX509Responder handles the response to the CreateX509 request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) CreateX509Responder(resp *http.Response) (result SigningX509Certificate, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GenerateVerificationCodeX509 generate a verification code for the primary or secondary x509 certificate of an +// enrollment group. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// entry - entry of certificate only support primary and secondary. +func (client EnrollmentGroupsClient) GenerateVerificationCodeX509(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (result X509VerificationCode, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.GenerateVerificationCodeX509") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "GenerateVerificationCodeX509", err.Error()) + } + + req, err := client.GenerateVerificationCodeX509Preparer(ctx, enrollmentGroupID, entry) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GenerateVerificationCodeX509", nil, "Failure preparing request") + return + } + + resp, err := client.GenerateVerificationCodeX509Sender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GenerateVerificationCodeX509", resp, "Failure sending request") + return + } + + result, err = client.GenerateVerificationCodeX509Responder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GenerateVerificationCodeX509", resp, "Failure responding to request") + return + } + + return +} + +// GenerateVerificationCodeX509Preparer prepares the GenerateVerificationCodeX509 request. +func (client EnrollmentGroupsClient) GenerateVerificationCodeX509Preparer(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + "entry": autorest.Encode("path", entry), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}/certificates/{entry}/generateVerificationCode", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GenerateVerificationCodeX509Sender sends the GenerateVerificationCodeX509 request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) GenerateVerificationCodeX509Sender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GenerateVerificationCodeX509Responder handles the response to the GenerateVerificationCodeX509 request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) GenerateVerificationCodeX509Responder(resp *http.Response) (result X509VerificationCode, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get details about an enrollment group by ID. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +func (client EnrollmentGroupsClient) Get(ctx context.Context, enrollmentGroupID string) (result EnrollmentGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, enrollmentGroupID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client EnrollmentGroupsClient) GetPreparer(ctx context.Context, enrollmentGroupID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) GetResponder(resp *http.Response) (result EnrollmentGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetX509 get details about the primary or secondary x509 certificate of an enrollment group, if it exists. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// entry - entry of certificate only support primary and secondary. +func (client EnrollmentGroupsClient) GetX509(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (result SigningX509Certificate, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.GetX509") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "GetX509", err.Error()) + } + + req, err := client.GetX509Preparer(ctx, enrollmentGroupID, entry) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GetX509", nil, "Failure preparing request") + return + } + + resp, err := client.GetX509Sender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GetX509", resp, "Failure sending request") + return + } + + result, err = client.GetX509Responder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "GetX509", resp, "Failure responding to request") + return + } + + return +} + +// GetX509Preparer prepares the GetX509 request. +func (client EnrollmentGroupsClient) GetX509Preparer(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + "entry": autorest.Encode("path", entry), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}/certificates/{entry}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetX509Sender sends the GetX509 request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) GetX509Sender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetX509Responder handles the response to the GetX509 request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) GetX509Responder(resp *http.Response) (result SigningX509Certificate, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client EnrollmentGroupsClient) List(ctx context.Context) (result EnrollmentGroupCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.List") + defer func() { + sc := -1 + if result.egc.Response.Response != nil { + sc = result.egc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.egc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "List", resp, "Failure sending request") + return + } + + result.egc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "List", resp, "Failure responding to request") + return + } + if result.egc.hasNextLink() && result.egc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client EnrollmentGroupsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/enrollmentGroups"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) ListResponder(resp *http.Response) (result EnrollmentGroupCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client EnrollmentGroupsClient) listNextResults(ctx context.Context, lastResults EnrollmentGroupCollection) (result EnrollmentGroupCollection, err error) { + req, err := lastResults.enrollmentGroupCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client EnrollmentGroupsClient) ListComplete(ctx context.Context) (result EnrollmentGroupCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// Remove delete an enrollment group by ID. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +func (client EnrollmentGroupsClient) Remove(ctx context.Context, enrollmentGroupID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, enrollmentGroupID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client EnrollmentGroupsClient) RemovePreparer(ctx context.Context, enrollmentGroupID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// RemoveX509 removes the primary or secondary x509 certificate of an enrollment group. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// entry - entry of certificate only support primary and secondary. +func (client EnrollmentGroupsClient) RemoveX509(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.RemoveX509") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "RemoveX509", err.Error()) + } + + req, err := client.RemoveX509Preparer(ctx, enrollmentGroupID, entry) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "RemoveX509", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveX509Sender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "RemoveX509", resp, "Failure sending request") + return + } + + result, err = client.RemoveX509Responder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "RemoveX509", resp, "Failure responding to request") + return + } + + return +} + +// RemoveX509Preparer prepares the RemoveX509 request. +func (client EnrollmentGroupsClient) RemoveX509Preparer(ctx context.Context, enrollmentGroupID string, entry CertificateEntry) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + "entry": autorest.Encode("path", entry), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}/certificates/{entry}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveX509Sender sends the RemoveX509 request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) RemoveX509Sender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveX509Responder handles the response to the RemoveX509 request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) RemoveX509Responder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update update an enrollment group. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// body - enrollment group patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client EnrollmentGroupsClient) Update(ctx context.Context, enrollmentGroupID string, body interface{}, ifMatch string) (result EnrollmentGroup, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, enrollmentGroupID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client EnrollmentGroupsClient) UpdatePreparer(ctx context.Context, enrollmentGroupID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/merge-patch+json"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) UpdateResponder(resp *http.Response) (result EnrollmentGroup, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// VerifyX509 verify the primary or secondary x509 certificate of an enrollment group by providing a certificate with +// the signed verification code. +// Parameters: +// enrollmentGroupID - unique ID of the enrollment group. +// entry - entry of certificate only support primary and secondary. +// body - certificate for the signed verification code. +func (client EnrollmentGroupsClient) VerifyX509(ctx context.Context, enrollmentGroupID string, entry CertificateEntry, body X509VerificationCertificate) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupsClient.VerifyX509") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: enrollmentGroupID, + Constraints: []validation.Constraint{{Target: "enrollmentGroupID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "enrollmentGroupID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Certificate", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.EnrollmentGroupsClient", "VerifyX509", err.Error()) + } + + req, err := client.VerifyX509Preparer(ctx, enrollmentGroupID, entry, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "VerifyX509", nil, "Failure preparing request") + return + } + + resp, err := client.VerifyX509Sender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "VerifyX509", resp, "Failure sending request") + return + } + + result, err = client.VerifyX509Responder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.EnrollmentGroupsClient", "VerifyX509", resp, "Failure responding to request") + return + } + + return +} + +// VerifyX509Preparer prepares the VerifyX509 request. +func (client EnrollmentGroupsClient) VerifyX509Preparer(ctx context.Context, enrollmentGroupID string, entry CertificateEntry, body X509VerificationCertificate) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "enrollmentGroupId": autorest.Encode("path", enrollmentGroupID), + "entry": autorest.Encode("path", entry), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/enrollmentGroups/{enrollmentGroupId}/certificates/{entry}/verify", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// VerifyX509Sender sends the VerifyX509 request. The method will close the +// http.Response Body if it receives an error. +func (client EnrollmentGroupsClient) VerifyX509Sender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// VerifyX509Responder handles the response to the VerifyX509 request. The method always +// closes the http.Response Body. +func (client EnrollmentGroupsClient) VerifyX509Responder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enums.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enums.go new file mode 100644 index 000000000000..b8ad30de69db --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/enums.go @@ -0,0 +1,520 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// CapabilityAggregateType enumerates the values for capability aggregate type. +type CapabilityAggregateType string + +const ( + // CapabilityAggregateTypeAvg Average of the capability data + CapabilityAggregateTypeAvg CapabilityAggregateType = "avg" + // CapabilityAggregateTypeCount Count of the capability data + CapabilityAggregateTypeCount CapabilityAggregateType = "count" + // CapabilityAggregateTypeMax Maximum of the capability data + CapabilityAggregateTypeMax CapabilityAggregateType = "max" + // CapabilityAggregateTypeMin Minimum of the capability data + CapabilityAggregateTypeMin CapabilityAggregateType = "min" + // CapabilityAggregateTypeSum Sum of the capability data + CapabilityAggregateTypeSum CapabilityAggregateType = "sum" +) + +// PossibleCapabilityAggregateTypeValues returns an array of possible values for the CapabilityAggregateType const type. +func PossibleCapabilityAggregateTypeValues() []CapabilityAggregateType { + return []CapabilityAggregateType{CapabilityAggregateTypeAvg, CapabilityAggregateTypeCount, CapabilityAggregateTypeMax, CapabilityAggregateTypeMin, CapabilityAggregateTypeSum} +} + +// CertificateEntry enumerates the values for certificate entry. +type CertificateEntry string + +const ( + // CertificateEntryPrimary The entry of primary certificate + CertificateEntryPrimary CertificateEntry = "primary" + // CertificateEntrySecondary The entry of secondary certificate + CertificateEntrySecondary CertificateEntry = "secondary" +) + +// PossibleCertificateEntryValues returns an array of possible values for the CertificateEntry const type. +func PossibleCertificateEntryValues() []CertificateEntry { + return []CertificateEntry{CertificateEntryPrimary, CertificateEntrySecondary} +} + +// DestinationSource enumerates the values for destination source. +type DestinationSource string + +const ( + // DestinationSourceAudit Destination source from audit logs + DestinationSourceAudit DestinationSource = "audit" + // DestinationSourceDeviceConnectivity Destination source from device connectivity + DestinationSourceDeviceConnectivity DestinationSource = "deviceConnectivity" + // DestinationSourceDeviceLifecycle Destination source from device lifecycle + DestinationSourceDeviceLifecycle DestinationSource = "deviceLifecycle" + // DestinationSourceDeviceTemplateLifecycle Destination source from device template lifecycle + DestinationSourceDeviceTemplateLifecycle DestinationSource = "deviceTemplateLifecycle" + // DestinationSourceProperties Destination source from device properties + DestinationSourceProperties DestinationSource = "properties" + // DestinationSourceTelemetry Destination source from device telemetry + DestinationSourceTelemetry DestinationSource = "telemetry" +) + +// PossibleDestinationSourceValues returns an array of possible values for the DestinationSource const type. +func PossibleDestinationSourceValues() []DestinationSource { + return []DestinationSource{DestinationSourceAudit, DestinationSourceDeviceConnectivity, DestinationSourceDeviceLifecycle, DestinationSourceDeviceTemplateLifecycle, DestinationSourceProperties, DestinationSourceTelemetry} +} + +// DeviceType enumerates the values for device type. +type DeviceType string + +const ( + // DeviceTypeIotEdge The edge device type + DeviceTypeIotEdge DeviceType = "iotEdge" +) + +// PossibleDeviceTypeValues returns an array of possible values for the DeviceType const type. +func PossibleDeviceTypeValues() []DeviceType { + return []DeviceType{DeviceTypeIotEdge} +} + +// EnrollmentGroupType enumerates the values for enrollment group type. +type EnrollmentGroupType string + +const ( + // EnrollmentGroupTypeIoTEdgedevices IoT Edge devices + EnrollmentGroupTypeIoTEdgedevices EnrollmentGroupType = "iotEdge" + // EnrollmentGroupTypeIoTdevices Regular (non-Edge) IoT devices + EnrollmentGroupTypeIoTdevices EnrollmentGroupType = "iot" +) + +// PossibleEnrollmentGroupTypeValues returns an array of possible values for the EnrollmentGroupType const type. +func PossibleEnrollmentGroupTypeValues() []EnrollmentGroupType { + return []EnrollmentGroupType{EnrollmentGroupTypeIoTEdgedevices, EnrollmentGroupTypeIoTdevices} +} + +// FileUploadState enumerates the values for file upload state. +type FileUploadState string + +const ( + // FileUploadStateDeleting ... + FileUploadStateDeleting FileUploadState = "deleting" + // FileUploadStateFailed ... + FileUploadStateFailed FileUploadState = "failed" + // FileUploadStatePending ... + FileUploadStatePending FileUploadState = "pending" + // FileUploadStateSucceeded ... + FileUploadStateSucceeded FileUploadState = "succeeded" + // FileUploadStateUpdating ... + FileUploadStateUpdating FileUploadState = "updating" +) + +// PossibleFileUploadStateValues returns an array of possible values for the FileUploadState const type. +func PossibleFileUploadStateValues() []FileUploadState { + return []FileUploadState{FileUploadStateDeleting, FileUploadStateFailed, FileUploadStatePending, FileUploadStateSucceeded, FileUploadStateUpdating} +} + +// ImageTileTextUnits enumerates the values for image tile text units. +type ImageTileTextUnits string + +const ( + // ImageTileTextUnitsPixels Set the text unit to pixels + ImageTileTextUnitsPixels ImageTileTextUnits = "px" +) + +// PossibleImageTileTextUnitsValues returns an array of possible values for the ImageTileTextUnits const type. +func PossibleImageTileTextUnitsValues() []ImageTileTextUnits { + return []ImageTileTextUnits{ImageTileTextUnitsPixels} +} + +// JobBatchType enumerates the values for job batch type. +type JobBatchType string + +const ( + // JobBatchTypeNumber Job Batching based on number of devices. + JobBatchTypeNumber JobBatchType = "number" + // JobBatchTypePercentage Job Batching based percentage of total applied devices. + JobBatchTypePercentage JobBatchType = "percentage" +) + +// PossibleJobBatchTypeValues returns an array of possible values for the JobBatchType const type. +func PossibleJobBatchTypeValues() []JobBatchType { + return []JobBatchType{JobBatchTypeNumber, JobBatchTypePercentage} +} + +// JobCancellationThresholdType enumerates the values for job cancellation threshold type. +type JobCancellationThresholdType string + +const ( + // JobCancellationThresholdTypeNumber Job cancellation threshold based on specified number of devices. + JobCancellationThresholdTypeNumber JobCancellationThresholdType = "number" + // JobCancellationThresholdTypePercentage Job cancellation threshold based on percentage of total devices. + JobCancellationThresholdTypePercentage JobCancellationThresholdType = "percentage" +) + +// PossibleJobCancellationThresholdTypeValues returns an array of possible values for the JobCancellationThresholdType const type. +func PossibleJobCancellationThresholdTypeValues() []JobCancellationThresholdType { + return []JobCancellationThresholdType{JobCancellationThresholdTypeNumber, JobCancellationThresholdTypePercentage} +} + +// JobRecurrence enumerates the values for job recurrence. +type JobRecurrence string + +const ( + // JobRecurrenceDaily The job will run once daily + JobRecurrenceDaily JobRecurrence = "daily" + // JobRecurrenceMonthly The job will run once every month + JobRecurrenceMonthly JobRecurrence = "monthly" + // JobRecurrenceWeekly The job will run once every week + JobRecurrenceWeekly JobRecurrence = "weekly" +) + +// PossibleJobRecurrenceValues returns an array of possible values for the JobRecurrence const type. +func PossibleJobRecurrenceValues() []JobRecurrence { + return []JobRecurrence{JobRecurrenceDaily, JobRecurrenceMonthly, JobRecurrenceWeekly} +} + +// OAuthRequestType enumerates the values for o auth request type. +type OAuthRequestType string + +const ( + // OAuthRequestTypeAuto Use automatic Content-Type for token request + OAuthRequestTypeAuto OAuthRequestType = "auto" + // OAuthRequestTypeJSON Content-Type as JSON for token request + OAuthRequestTypeJSON OAuthRequestType = "json" + // OAuthRequestTypeURLEncoded Content-Type as UrlEncoded for token request + OAuthRequestTypeURLEncoded OAuthRequestType = "urlencoded" +) + +// PossibleOAuthRequestTypeValues returns an array of possible values for the OAuthRequestType const type. +func PossibleOAuthRequestTypeValues() []OAuthRequestType { + return []OAuthRequestType{OAuthRequestTypeAuto, OAuthRequestTypeJSON, OAuthRequestTypeURLEncoded} +} + +// TileTextSizeUnit enumerates the values for tile text size unit. +type TileTextSizeUnit string + +const ( + // TileTextSizeUnitPoints Set the text unit to points + TileTextSizeUnitPoints TileTextSizeUnit = "pt" +) + +// PossibleTileTextSizeUnitValues returns an array of possible values for the TileTextSizeUnit const type. +func PossibleTileTextSizeUnitValues() []TileTextSizeUnit { + return []TileTextSizeUnit{TileTextSizeUnitPoints} +} + +// TileTimeRangeDuration enumerates the values for tile time range duration. +type TileTimeRangeDuration string + +const ( + // TileTimeRangeDurationOneSpaceDay 1 Day + TileTimeRangeDurationOneSpaceDay TileTimeRangeDuration = "P1D" + // TileTimeRangeDurationOneSpaceHour 1 Hour + TileTimeRangeDurationOneSpaceHour TileTimeRangeDuration = "PT1H" + // TileTimeRangeDurationOneSpaceWeek 1 Week + TileTimeRangeDurationOneSpaceWeek TileTimeRangeDuration = "P1W" + // TileTimeRangeDurationOneTwoSpaceHours 12 Hours + TileTimeRangeDurationOneTwoSpaceHours TileTimeRangeDuration = "PT12H" + // TileTimeRangeDurationThreeZeroSpaceDays 30 Days + TileTimeRangeDurationThreeZeroSpaceDays TileTimeRangeDuration = "P30D" + // TileTimeRangeDurationThreeZeroSpaceMinutes 30 Minutes + TileTimeRangeDurationThreeZeroSpaceMinutes TileTimeRangeDuration = "PT30M" +) + +// PossibleTileTimeRangeDurationValues returns an array of possible values for the TileTimeRangeDuration const type. +func PossibleTileTimeRangeDurationValues() []TileTimeRangeDuration { + return []TileTimeRangeDuration{TileTimeRangeDurationOneSpaceDay, TileTimeRangeDurationOneSpaceHour, TileTimeRangeDurationOneSpaceWeek, TileTimeRangeDurationOneTwoSpaceHours, TileTimeRangeDurationThreeZeroSpaceDays, TileTimeRangeDurationThreeZeroSpaceMinutes} +} + +// TileTimeRangeResolution enumerates the values for tile time range resolution. +type TileTimeRangeResolution string + +const ( + // TileTimeRangeResolutionFiveSpaceMinutes 5 Minutes + TileTimeRangeResolutionFiveSpaceMinutes TileTimeRangeResolution = "PT5M" + // TileTimeRangeResolutionOneSpaceDay 1 Day + TileTimeRangeResolutionOneSpaceDay TileTimeRangeResolution = "P1D" + // TileTimeRangeResolutionOneSpaceHour 1 Hour + TileTimeRangeResolutionOneSpaceHour TileTimeRangeResolution = "PT1H" + // TileTimeRangeResolutionOneSpaceMinute 1 Minute + TileTimeRangeResolutionOneSpaceMinute TileTimeRangeResolution = "PT1M" + // TileTimeRangeResolutionOneSpaceWeek 1 Week + TileTimeRangeResolutionOneSpaceWeek TileTimeRangeResolution = "P1W" + // TileTimeRangeResolutionOneTwoSpaceHours 12 Hours + TileTimeRangeResolutionOneTwoSpaceHours TileTimeRangeResolution = "PT12H" + // TileTimeRangeResolutionOneZeroSpaceMinutes 10 Minutes + TileTimeRangeResolutionOneZeroSpaceMinutes TileTimeRangeResolution = "PT10M" + // TileTimeRangeResolutionThreeZeroSpaceMinutes 30 Minutes + TileTimeRangeResolutionThreeZeroSpaceMinutes TileTimeRangeResolution = "PT30M" +) + +// PossibleTileTimeRangeResolutionValues returns an array of possible values for the TileTimeRangeResolution const type. +func PossibleTileTimeRangeResolutionValues() []TileTimeRangeResolution { + return []TileTimeRangeResolution{TileTimeRangeResolutionFiveSpaceMinutes, TileTimeRangeResolutionOneSpaceDay, TileTimeRangeResolutionOneSpaceHour, TileTimeRangeResolutionOneSpaceMinute, TileTimeRangeResolutionOneSpaceWeek, TileTimeRangeResolutionOneTwoSpaceHours, TileTimeRangeResolutionOneZeroSpaceMinutes, TileTimeRangeResolutionThreeZeroSpaceMinutes} +} + +// Type enumerates the values for type. +type Type string + +const ( + // TypeAttestation ... + TypeAttestation Type = "Attestation" + // TypeSymmetricKey ... + TypeSymmetricKey Type = "symmetricKey" + // TypeTpm ... + TypeTpm Type = "tpm" + // TypeX509 ... + TypeX509 Type = "x509" +) + +// PossibleTypeValues returns an array of possible values for the Type const type. +func PossibleTypeValues() []Type { + return []Type{TypeAttestation, TypeSymmetricKey, TypeTpm, TypeX509} +} + +// TypeBasicBlobStorageV1DestinationAuth enumerates the values for type basic blob storage v1 destination auth. +type TypeBasicBlobStorageV1DestinationAuth string + +const ( + // TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth ... + TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth TypeBasicBlobStorageV1DestinationAuth = "BlobStorageV1DestinationAuth" + // TypeBasicBlobStorageV1DestinationAuthTypeConnectionString ... + TypeBasicBlobStorageV1DestinationAuthTypeConnectionString TypeBasicBlobStorageV1DestinationAuth = "connectionString" + // TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity ... + TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity TypeBasicBlobStorageV1DestinationAuth = "systemAssignedManagedIdentity" +) + +// PossibleTypeBasicBlobStorageV1DestinationAuthValues returns an array of possible values for the TypeBasicBlobStorageV1DestinationAuth const type. +func PossibleTypeBasicBlobStorageV1DestinationAuthValues() []TypeBasicBlobStorageV1DestinationAuth { + return []TypeBasicBlobStorageV1DestinationAuth{TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth, TypeBasicBlobStorageV1DestinationAuthTypeConnectionString, TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity} +} + +// TypeBasicDataExplorerV1DestinationAuth enumerates the values for type basic data explorer v1 destination +// auth. +type TypeBasicDataExplorerV1DestinationAuth string + +const ( + // TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth ... + TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth TypeBasicDataExplorerV1DestinationAuth = "DataExplorerV1DestinationAuth" + // TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal ... + TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal TypeBasicDataExplorerV1DestinationAuth = "servicePrincipal" + // TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity ... + TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity TypeBasicDataExplorerV1DestinationAuth = "systemAssignedManagedIdentity" +) + +// PossibleTypeBasicDataExplorerV1DestinationAuthValues returns an array of possible values for the TypeBasicDataExplorerV1DestinationAuth const type. +func PossibleTypeBasicDataExplorerV1DestinationAuthValues() []TypeBasicDataExplorerV1DestinationAuth { + return []TypeBasicDataExplorerV1DestinationAuth{TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth, TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal, TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity} +} + +// TypeBasicDestination enumerates the values for type basic destination. +type TypeBasicDestination string + +const ( + // TypeBasicDestinationTypeBlobstorageV1 ... + TypeBasicDestinationTypeBlobstorageV1 TypeBasicDestination = "blobstorage@v1" + // TypeBasicDestinationTypeDataexplorerV1 ... + TypeBasicDestinationTypeDataexplorerV1 TypeBasicDestination = "dataexplorer@v1" + // TypeBasicDestinationTypeDestination ... + TypeBasicDestinationTypeDestination TypeBasicDestination = "Destination" + // TypeBasicDestinationTypeEventhubsV1 ... + TypeBasicDestinationTypeEventhubsV1 TypeBasicDestination = "eventhubs@v1" + // TypeBasicDestinationTypeExportDestination ... + TypeBasicDestinationTypeExportDestination TypeBasicDestination = "ExportDestination" + // TypeBasicDestinationTypeServicebusqueueV1 ... + TypeBasicDestinationTypeServicebusqueueV1 TypeBasicDestination = "servicebusqueue@v1" + // TypeBasicDestinationTypeServicebustopicV1 ... + TypeBasicDestinationTypeServicebustopicV1 TypeBasicDestination = "servicebustopic@v1" + // TypeBasicDestinationTypeWebhookV1 ... + TypeBasicDestinationTypeWebhookV1 TypeBasicDestination = "webhook@v1" +) + +// PossibleTypeBasicDestinationValues returns an array of possible values for the TypeBasicDestination const type. +func PossibleTypeBasicDestinationValues() []TypeBasicDestination { + return []TypeBasicDestination{TypeBasicDestinationTypeBlobstorageV1, TypeBasicDestinationTypeDataexplorerV1, TypeBasicDestinationTypeDestination, TypeBasicDestinationTypeEventhubsV1, TypeBasicDestinationTypeExportDestination, TypeBasicDestinationTypeServicebusqueueV1, TypeBasicDestinationTypeServicebustopicV1, TypeBasicDestinationTypeWebhookV1} +} + +// TypeBasicEventHubsV1DestinationAuth enumerates the values for type basic event hubs v1 destination auth. +type TypeBasicEventHubsV1DestinationAuth string + +const ( + // TypeBasicEventHubsV1DestinationAuthTypeConnectionString ... + TypeBasicEventHubsV1DestinationAuthTypeConnectionString TypeBasicEventHubsV1DestinationAuth = "connectionString" + // TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth ... + TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth TypeBasicEventHubsV1DestinationAuth = "EventHubsV1DestinationAuth" + // TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity ... + TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity TypeBasicEventHubsV1DestinationAuth = "systemAssignedManagedIdentity" +) + +// PossibleTypeBasicEventHubsV1DestinationAuthValues returns an array of possible values for the TypeBasicEventHubsV1DestinationAuth const type. +func PossibleTypeBasicEventHubsV1DestinationAuthValues() []TypeBasicEventHubsV1DestinationAuth { + return []TypeBasicEventHubsV1DestinationAuth{TypeBasicEventHubsV1DestinationAuthTypeConnectionString, TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth, TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity} +} + +// TypeBasicGroupAttestation enumerates the values for type basic group attestation. +type TypeBasicGroupAttestation string + +const ( + // TypeBasicGroupAttestationTypeGroupAttestation ... + TypeBasicGroupAttestationTypeGroupAttestation TypeBasicGroupAttestation = "GroupAttestation" + // TypeBasicGroupAttestationTypeSymmetricKey ... + TypeBasicGroupAttestationTypeSymmetricKey TypeBasicGroupAttestation = "symmetricKey" + // TypeBasicGroupAttestationTypeX509 ... + TypeBasicGroupAttestationTypeX509 TypeBasicGroupAttestation = "x509" +) + +// PossibleTypeBasicGroupAttestationValues returns an array of possible values for the TypeBasicGroupAttestation const type. +func PossibleTypeBasicGroupAttestationValues() []TypeBasicGroupAttestation { + return []TypeBasicGroupAttestation{TypeBasicGroupAttestationTypeGroupAttestation, TypeBasicGroupAttestationTypeSymmetricKey, TypeBasicGroupAttestationTypeX509} +} + +// TypeBasicJobData enumerates the values for type basic job data. +type TypeBasicJobData string + +const ( + // TypeBasicJobDataTypeDeviceManifestMigration ... + TypeBasicJobDataTypeDeviceManifestMigration TypeBasicJobData = "deviceManifestMigration" + // TypeBasicJobDataTypeDeviceTemplateMigration ... + TypeBasicJobDataTypeDeviceTemplateMigration TypeBasicJobData = "deviceTemplateMigration" + // TypeBasicJobDataTypeJobData ... + TypeBasicJobDataTypeJobData TypeBasicJobData = "JobData" +) + +// PossibleTypeBasicJobDataValues returns an array of possible values for the TypeBasicJobData const type. +func PossibleTypeBasicJobDataValues() []TypeBasicJobData { + return []TypeBasicJobData{TypeBasicJobDataTypeDeviceManifestMigration, TypeBasicJobDataTypeDeviceTemplateMigration, TypeBasicJobDataTypeJobData} +} + +// TypeBasicJobScheduleEnd enumerates the values for type basic job schedule end. +type TypeBasicJobScheduleEnd string + +const ( + // TypeBasicJobScheduleEndTypeDate ... + TypeBasicJobScheduleEndTypeDate TypeBasicJobScheduleEnd = "date" + // TypeBasicJobScheduleEndTypeJobScheduleEnd ... + TypeBasicJobScheduleEndTypeJobScheduleEnd TypeBasicJobScheduleEnd = "JobScheduleEnd" + // TypeBasicJobScheduleEndTypeOccurrences ... + TypeBasicJobScheduleEndTypeOccurrences TypeBasicJobScheduleEnd = "occurrences" +) + +// PossibleTypeBasicJobScheduleEndValues returns an array of possible values for the TypeBasicJobScheduleEnd const type. +func PossibleTypeBasicJobScheduleEndValues() []TypeBasicJobScheduleEnd { + return []TypeBasicJobScheduleEnd{TypeBasicJobScheduleEndTypeDate, TypeBasicJobScheduleEndTypeJobScheduleEnd, TypeBasicJobScheduleEndTypeOccurrences} +} + +// TypeBasicQueryRangeConfiguration enumerates the values for type basic query range configuration. +type TypeBasicQueryRangeConfiguration string + +const ( + // TypeBasicQueryRangeConfigurationTypeCount ... + TypeBasicQueryRangeConfigurationTypeCount TypeBasicQueryRangeConfiguration = "count" + // TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration ... + TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration TypeBasicQueryRangeConfiguration = "QueryRangeConfiguration" + // TypeBasicQueryRangeConfigurationTypeTime ... + TypeBasicQueryRangeConfigurationTypeTime TypeBasicQueryRangeConfiguration = "time" +) + +// PossibleTypeBasicQueryRangeConfigurationValues returns an array of possible values for the TypeBasicQueryRangeConfiguration const type. +func PossibleTypeBasicQueryRangeConfigurationValues() []TypeBasicQueryRangeConfiguration { + return []TypeBasicQueryRangeConfiguration{TypeBasicQueryRangeConfigurationTypeCount, TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration, TypeBasicQueryRangeConfigurationTypeTime} +} + +// TypeBasicServiceBusQueueV1DestinationAuth enumerates the values for type basic service bus queue v1 +// destination auth. +type TypeBasicServiceBusQueueV1DestinationAuth string + +const ( + // TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString ... + TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString TypeBasicServiceBusQueueV1DestinationAuth = "connectionString" + // TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth ... + TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth TypeBasicServiceBusQueueV1DestinationAuth = "ServiceBusQueueV1DestinationAuth" + // TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity ... + TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity TypeBasicServiceBusQueueV1DestinationAuth = "systemAssignedManagedIdentity" +) + +// PossibleTypeBasicServiceBusQueueV1DestinationAuthValues returns an array of possible values for the TypeBasicServiceBusQueueV1DestinationAuth const type. +func PossibleTypeBasicServiceBusQueueV1DestinationAuthValues() []TypeBasicServiceBusQueueV1DestinationAuth { + return []TypeBasicServiceBusQueueV1DestinationAuth{TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString, TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth, TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity} +} + +// TypeBasicServiceBusTopicV1DestinationAuth enumerates the values for type basic service bus topic v1 +// destination auth. +type TypeBasicServiceBusTopicV1DestinationAuth string + +const ( + // TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString ... + TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString TypeBasicServiceBusTopicV1DestinationAuth = "connectionString" + // TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth ... + TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth TypeBasicServiceBusTopicV1DestinationAuth = "ServiceBusTopicV1DestinationAuth" + // TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity ... + TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity TypeBasicServiceBusTopicV1DestinationAuth = "systemAssignedManagedIdentity" +) + +// PossibleTypeBasicServiceBusTopicV1DestinationAuthValues returns an array of possible values for the TypeBasicServiceBusTopicV1DestinationAuth const type. +func PossibleTypeBasicServiceBusTopicV1DestinationAuthValues() []TypeBasicServiceBusTopicV1DestinationAuth { + return []TypeBasicServiceBusTopicV1DestinationAuth{TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString, TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth, TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity} +} + +// TypeBasicTileConfiguration enumerates the values for type basic tile configuration. +type TypeBasicTileConfiguration string + +const ( + // TypeBasicTileConfigurationTypeCommand ... + TypeBasicTileConfigurationTypeCommand TypeBasicTileConfiguration = "command" + // TypeBasicTileConfigurationTypeDataExplorer ... + TypeBasicTileConfigurationTypeDataExplorer TypeBasicTileConfiguration = "dataExplorer" + // TypeBasicTileConfigurationTypeDeviceCount ... + TypeBasicTileConfigurationTypeDeviceCount TypeBasicTileConfiguration = "deviceCount" + // TypeBasicTileConfigurationTypeExternalContent ... + TypeBasicTileConfigurationTypeExternalContent TypeBasicTileConfiguration = "externalContent" + // TypeBasicTileConfigurationTypeImage ... + TypeBasicTileConfigurationTypeImage TypeBasicTileConfiguration = "image" + // TypeBasicTileConfigurationTypeLabel ... + TypeBasicTileConfigurationTypeLabel TypeBasicTileConfiguration = "label" + // TypeBasicTileConfigurationTypeMarkdown ... + TypeBasicTileConfigurationTypeMarkdown TypeBasicTileConfiguration = "markdown" + // TypeBasicTileConfigurationTypeTileConfiguration ... + TypeBasicTileConfigurationTypeTileConfiguration TypeBasicTileConfiguration = "TileConfiguration" +) + +// PossibleTypeBasicTileConfigurationValues returns an array of possible values for the TypeBasicTileConfiguration const type. +func PossibleTypeBasicTileConfigurationValues() []TypeBasicTileConfiguration { + return []TypeBasicTileConfiguration{TypeBasicTileConfigurationTypeCommand, TypeBasicTileConfigurationTypeDataExplorer, TypeBasicTileConfigurationTypeDeviceCount, TypeBasicTileConfigurationTypeExternalContent, TypeBasicTileConfigurationTypeImage, TypeBasicTileConfigurationTypeLabel, TypeBasicTileConfigurationTypeMarkdown, TypeBasicTileConfigurationTypeTileConfiguration} +} + +// TypeBasicUser enumerates the values for type basic user. +type TypeBasicUser string + +const ( + // TypeBasicUserTypeAdGroup ... + TypeBasicUserTypeAdGroup TypeBasicUser = "adGroup" + // TypeBasicUserTypeEmail ... + TypeBasicUserTypeEmail TypeBasicUser = "email" + // TypeBasicUserTypeServicePrincipal ... + TypeBasicUserTypeServicePrincipal TypeBasicUser = "servicePrincipal" + // TypeBasicUserTypeUser ... + TypeBasicUserTypeUser TypeBasicUser = "User" +) + +// PossibleTypeBasicUserValues returns an array of possible values for the TypeBasicUser const type. +func PossibleTypeBasicUserValues() []TypeBasicUser { + return []TypeBasicUser{TypeBasicUserTypeAdGroup, TypeBasicUserTypeEmail, TypeBasicUserTypeServicePrincipal, TypeBasicUserTypeUser} +} + +// TypeBasicWebhookV1DestinationAuth enumerates the values for type basic webhook v1 destination auth. +type TypeBasicWebhookV1DestinationAuth string + +const ( + // TypeBasicWebhookV1DestinationAuthTypeHeader ... + TypeBasicWebhookV1DestinationAuthTypeHeader TypeBasicWebhookV1DestinationAuth = "header" + // TypeBasicWebhookV1DestinationAuthTypeOauth ... + TypeBasicWebhookV1DestinationAuthTypeOauth TypeBasicWebhookV1DestinationAuth = "oauth" + // TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth ... + TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth TypeBasicWebhookV1DestinationAuth = "WebhookV1DestinationAuth" +) + +// PossibleTypeBasicWebhookV1DestinationAuthValues returns an array of possible values for the TypeBasicWebhookV1DestinationAuth const type. +func PossibleTypeBasicWebhookV1DestinationAuthValues() []TypeBasicWebhookV1DestinationAuth { + return []TypeBasicWebhookV1DestinationAuth{TypeBasicWebhookV1DestinationAuthTypeHeader, TypeBasicWebhookV1DestinationAuthTypeOauth, TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth} +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/exports.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/exports.go new file mode 100644 index 000000000000..afbeb2fd40fb --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/exports.go @@ -0,0 +1,595 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// ExportsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type ExportsClient struct { + BaseClient +} + +// NewExportsClient creates an instance of the ExportsClient client. +func NewExportsClient(subdomain string) ExportsClient { + return ExportsClient{New(subdomain)} +} + +// Create create or update a definition for exporting data. Also used to connect or disconnect an export from +// destinations. +// Parameters: +// exportID - unique ID for the export. +// body - export body. +func (client ExportsClient) Create(ctx context.Context, exportID string, body Export) (result Export, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.DisplayName", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Enabled", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Destinations", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.ExportsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, exportID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client ExportsClient) CreatePreparer(ctx context.Context, exportID string, body Export) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "exportId": autorest.Encode("path", exportID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/exports/{exportId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client ExportsClient) CreateResponder(resp *http.Response) (result Export, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// exportID - unique ID for the export. +func (client ExportsClient) Get(ctx context.Context, exportID string) (result Export, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, exportID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ExportsClient) GetPreparer(ctx context.Context, exportID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "exportId": autorest.Encode("path", exportID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/exports/{exportId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ExportsClient) GetResponder(resp *http.Response) (result Export, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client ExportsClient) List(ctx context.Context) (result ExportCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.List") + defer func() { + sc := -1 + if result.ec.Response.Response != nil { + sc = result.ec.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.ec.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "List", resp, "Failure sending request") + return + } + + result.ec, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "List", resp, "Failure responding to request") + return + } + if result.ec.hasNextLink() && result.ec.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client ExportsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/dataExport/exports"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ExportsClient) ListResponder(resp *http.Response) (result ExportCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client ExportsClient) listNextResults(ctx context.Context, lastResults ExportCollection) (result ExportCollection, err error) { + req, err := lastResults.exportCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client ExportsClient) ListComplete(ctx context.Context) (result ExportCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// ListDestinations sends the list destinations request. +// Parameters: +// exportID - unique ID for the export. +func (client ExportsClient) ListDestinations(ctx context.Context, exportID string) (result DestinationCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.ListDestinations") + defer func() { + sc := -1 + if result.dc.Response.Response != nil { + sc = result.dc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listDestinationsNextResults + req, err := client.ListDestinationsPreparer(ctx, exportID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "ListDestinations", nil, "Failure preparing request") + return + } + + resp, err := client.ListDestinationsSender(req) + if err != nil { + result.dc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "ListDestinations", resp, "Failure sending request") + return + } + + result.dc, err = client.ListDestinationsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "ListDestinations", resp, "Failure responding to request") + return + } + if result.dc.hasNextLink() && result.dc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListDestinationsPreparer prepares the ListDestinations request. +func (client ExportsClient) ListDestinationsPreparer(ctx context.Context, exportID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "exportId": autorest.Encode("path", exportID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/exports/{exportId}/destinations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListDestinationsSender sends the ListDestinations request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) ListDestinationsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListDestinationsResponder handles the response to the ListDestinations request. The method always +// closes the http.Response Body. +func (client ExportsClient) ListDestinationsResponder(resp *http.Response) (result DestinationCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listDestinationsNextResults retrieves the next set of results, if any. +func (client ExportsClient) listDestinationsNextResults(ctx context.Context, lastResults DestinationCollection) (result DestinationCollection, err error) { + req, err := lastResults.destinationCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listDestinationsNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListDestinationsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listDestinationsNextResults", resp, "Failure sending next results request") + } + result, err = client.ListDestinationsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "listDestinationsNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListDestinationsComplete enumerates all values, automatically crossing page boundaries as required. +func (client ExportsClient) ListDestinationsComplete(ctx context.Context, exportID string) (result DestinationCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.ListDestinations") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListDestinations(ctx, exportID) + return +} + +// Remove sends the remove request. +// Parameters: +// exportID - unique ID for the export. +func (client ExportsClient) Remove(ctx context.Context, exportID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemovePreparer(ctx, exportID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client ExportsClient) RemovePreparer(ctx context.Context, exportID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "exportId": autorest.Encode("path", exportID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/exports/{exportId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client ExportsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update perform an incremental update to an export. +// Parameters: +// exportID - unique ID for the export. +// body - export patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client ExportsClient) Update(ctx context.Context, exportID string, body interface{}, ifMatch string) (result Export, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, exportID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ExportsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client ExportsClient) UpdatePreparer(ctx context.Context, exportID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "exportId": autorest.Encode("path", exportID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/dataExport/exports/{exportId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client ExportsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client ExportsClient) UpdateResponder(resp *http.Response) (result Export, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/fileuploads.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/fileuploads.go new file mode 100644 index 000000000000..690b88d691b3 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/fileuploads.go @@ -0,0 +1,337 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// FileUploadsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type FileUploadsClient struct { + BaseClient +} + +// NewFileUploadsClient creates an instance of the FileUploadsClient client. +func NewFileUploadsClient(subdomain string) FileUploadsClient { + return FileUploadsClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// body - file upload storage account configuration body. +func (client FileUploadsClient) Create(ctx context.Context, body FileUpload) (result FileUpload, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/FileUploadsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ConnectionString", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Container", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.FileUploadsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client FileUploadsClient) CreatePreparer(ctx context.Context, body FileUpload) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.State = "" + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/fileUploads"), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client FileUploadsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client FileUploadsClient) CreateResponder(resp *http.Response) (result FileUpload, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +func (client FileUploadsClient) Get(ctx context.Context) (result FileUpload, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/FileUploadsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client FileUploadsClient) GetPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/fileUploads"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client FileUploadsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client FileUploadsClient) GetResponder(resp *http.Response) (result FileUpload, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Remove sends the remove request. +func (client FileUploadsClient) Remove(ctx context.Context) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/FileUploadsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RemovePreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client FileUploadsClient) RemovePreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/fileUploads"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client FileUploadsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client FileUploadsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// body - file upload storage account configuration body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client FileUploadsClient) Update(ctx context.Context, body interface{}, ifMatch string) (result FileUpload, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/FileUploadsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.FileUploadsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client FileUploadsClient) UpdatePreparer(ctx context.Context, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/fileUploads"), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client FileUploadsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client FileUploadsClient) UpdateResponder(resp *http.Response) (result FileUpload, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/jobs.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/jobs.go new file mode 100644 index 000000000000..9c3417679373 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/jobs.go @@ -0,0 +1,728 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// JobsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT devices +// at scale. +type JobsClient struct { + BaseClient +} + +// NewJobsClient creates an instance of the JobsClient client. +func NewJobsClient(subdomain string) JobsClient { + return JobsClient{New(subdomain)} +} + +// Create create and execute a new job via its job definition. +// Parameters: +// jobID - unique ID of the job. +// body - job definition. +func (client JobsClient) Create(ctx context.Context, jobID string, body Job) (result Job, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Group", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Batch", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Batch.Value", Name: validation.Null, Rule: true, Chain: nil}}}, + {Target: "body.CancellationThreshold", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.CancellationThreshold.Value", Name: validation.Null, Rule: true, Chain: nil}}}, + {Target: "body.Data", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.Data", Name: validation.MinItems, Rule: 1, Chain: nil}}}, + {Target: "body.Organizations", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Organizations", Name: validation.MaxItems, Rule: 1, Chain: nil}, + {Target: "body.Organizations", Name: validation.MinItems, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, jobID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client JobsClient) CreatePreparer(ctx context.Context, jobID string, body Job) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.Start = nil + body.End = nil + body.Progress = nil + body.Status = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client JobsClient) CreateResponder(resp *http.Response) (result Job, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get details about a running or completed job by job ID. +// Parameters: +// jobID - unique ID of the job. +func (client JobsClient) Get(ctx context.Context, jobID string) (result Job, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, jobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client JobsClient) GetPreparer(ctx context.Context, jobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client JobsClient) GetResponder(resp *http.Response) (result Job, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetDevices get the list of individual device statuses by job ID. +// Parameters: +// jobID - unique ID of the job. +func (client JobsClient) GetDevices(ctx context.Context, jobID string) (result JobDeviceStatusCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.GetDevices") + defer func() { + sc := -1 + if result.jdsc.Response.Response != nil { + sc = result.jdsc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "GetDevices", err.Error()) + } + + result.fn = client.getDevicesNextResults + req, err := client.GetDevicesPreparer(ctx, jobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "GetDevices", nil, "Failure preparing request") + return + } + + resp, err := client.GetDevicesSender(req) + if err != nil { + result.jdsc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "GetDevices", resp, "Failure sending request") + return + } + + result.jdsc, err = client.GetDevicesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "GetDevices", resp, "Failure responding to request") + return + } + if result.jdsc.hasNextLink() && result.jdsc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// GetDevicesPreparer prepares the GetDevices request. +func (client JobsClient) GetDevicesPreparer(ctx context.Context, jobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}/devices", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetDevicesSender sends the GetDevices request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) GetDevicesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetDevicesResponder handles the response to the GetDevices request. The method always +// closes the http.Response Body. +func (client JobsClient) GetDevicesResponder(resp *http.Response) (result JobDeviceStatusCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// getDevicesNextResults retrieves the next set of results, if any. +func (client JobsClient) getDevicesNextResults(ctx context.Context, lastResults JobDeviceStatusCollection) (result JobDeviceStatusCollection, err error) { + req, err := lastResults.jobDeviceStatusCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.JobsClient", "getDevicesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetDevicesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.JobsClient", "getDevicesNextResults", resp, "Failure sending next results request") + } + result, err = client.GetDevicesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "getDevicesNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetDevicesComplete enumerates all values, automatically crossing page boundaries as required. +func (client JobsClient) GetDevicesComplete(ctx context.Context, jobID string) (result JobDeviceStatusCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.GetDevices") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetDevices(ctx, jobID) + return +} + +// List sends the list request. +// Parameters: +// maxpagesize - the maximum number of resources to return from one response. +func (client JobsClient) List(ctx context.Context, maxpagesize *int32) (result JobCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List") + defer func() { + sc := -1 + if result.jc.Response.Response != nil { + sc = result.jc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.jc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "List", resp, "Failure sending request") + return + } + + result.jc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "List", resp, "Failure responding to request") + return + } + if result.jc.hasNextLink() && result.jc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client JobsClient) ListPreparer(ctx context.Context, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/jobs"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client JobsClient) ListResponder(resp *http.Response) (result JobCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client JobsClient) listNextResults(ctx context.Context, lastResults JobCollection) (result JobCollection, err error) { + req, err := lastResults.jobCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.JobsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.JobsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client JobsClient) ListComplete(ctx context.Context, maxpagesize *int32) (result JobCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, maxpagesize) + return +} + +// Rerun execute a rerun of an existing job on all failed devices. +// Parameters: +// jobID - unique ID of the job. +// rerunID - unique ID of the job rerun. +func (client JobsClient) Rerun(ctx context.Context, jobID string, rerunID string) (result Job, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Rerun") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "Rerun", err.Error()) + } + + req, err := client.RerunPreparer(ctx, jobID, rerunID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Rerun", nil, "Failure preparing request") + return + } + + resp, err := client.RerunSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Rerun", resp, "Failure sending request") + return + } + + result, err = client.RerunResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Rerun", resp, "Failure responding to request") + return + } + + return +} + +// RerunPreparer prepares the Rerun request. +func (client JobsClient) RerunPreparer(ctx context.Context, jobID string, rerunID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + "rerunId": autorest.Encode("path", rerunID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}/rerun/{rerunId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RerunSender sends the Rerun request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) RerunSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RerunResponder handles the response to the Rerun request. The method always +// closes the http.Response Body. +func (client JobsClient) RerunResponder(resp *http.Response) (result Job, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Resume resume execution of an existing stopped job. +// Parameters: +// jobID - unique ID of the job. +func (client JobsClient) Resume(ctx context.Context, jobID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Resume") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "Resume", err.Error()) + } + + req, err := client.ResumePreparer(ctx, jobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Resume", nil, "Failure preparing request") + return + } + + resp, err := client.ResumeSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Resume", resp, "Failure sending request") + return + } + + result, err = client.ResumeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Resume", resp, "Failure responding to request") + return + } + + return +} + +// ResumePreparer prepares the Resume request. +func (client JobsClient) ResumePreparer(ctx context.Context, jobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}/resume", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ResumeSender sends the Resume request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) ResumeSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ResumeResponder handles the response to the Resume request. The method always +// closes the http.Response Body. +func (client JobsClient) ResumeResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Stop stop execution of a job that is currently running. +// Parameters: +// jobID - unique ID of the job. +func (client JobsClient) Stop(ctx context.Context, jobID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Stop") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: jobID, + Constraints: []validation.Constraint{{Target: "jobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "jobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.JobsClient", "Stop", err.Error()) + } + + req, err := client.StopPreparer(ctx, jobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Stop", nil, "Failure preparing request") + return + } + + resp, err := client.StopSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Stop", resp, "Failure sending request") + return + } + + result, err = client.StopResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.JobsClient", "Stop", resp, "Failure responding to request") + return + } + + return +} + +// StopPreparer prepares the Stop request. +func (client JobsClient) StopPreparer(ctx context.Context, jobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "jobId": autorest.Encode("path", jobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/jobs/{jobId}/stop", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// StopSender sends the Stop request. The method will close the +// http.Response Body if it receives an error. +func (client JobsClient) StopSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// StopResponder handles the response to the Stop request. The method always +// closes the http.Response Body. +func (client JobsClient) StopResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/models.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/models.go new file mode 100644 index 000000000000..07b95c99bec8 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/models.go @@ -0,0 +1,8925 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" +) + +// The package's fully qualified name. +const fqdn = "home/runner/work/kermit/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral" + +// ADGroupUser the active directory group user definition. +type ADGroupUser struct { + // TenantID - The AAD tenant ID of the AD Group. + TenantID *string `json:"tenantId,omitempty"` + // ObjectID - The AAD object ID of the AD Group. + ObjectID *string `json:"objectId,omitempty"` + // ID - READ-ONLY; Unique ID of the user. + ID *string `json:"id,omitempty"` + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` + // Type - Possible values include: 'TypeBasicUserTypeUser', 'TypeBasicUserTypeAdGroup', 'TypeBasicUserTypeEmail', 'TypeBasicUserTypeServicePrincipal' + Type TypeBasicUser `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ADGroupUser. +func (agu ADGroupUser) MarshalJSON() ([]byte, error) { + agu.Type = TypeBasicUserTypeAdGroup + objectMap := make(map[string]interface{}) + if agu.TenantID != nil { + objectMap["tenantId"] = agu.TenantID + } + if agu.ObjectID != nil { + objectMap["objectId"] = agu.ObjectID + } + if agu.Type != "" { + objectMap["type"] = agu.Type + } + if agu.Roles != nil { + objectMap["roles"] = agu.Roles + } + return json.Marshal(objectMap) +} + +// AsADGroupUser is the BasicUser implementation for ADGroupUser. +func (agu ADGroupUser) AsADGroupUser() (*ADGroupUser, bool) { + return &agu, true +} + +// AsEmailUser is the BasicUser implementation for ADGroupUser. +func (agu ADGroupUser) AsEmailUser() (*EmailUser, bool) { + return nil, false +} + +// AsServicePrincipalUser is the BasicUser implementation for ADGroupUser. +func (agu ADGroupUser) AsServicePrincipalUser() (*ServicePrincipalUser, bool) { + return nil, false +} + +// AsUser is the BasicUser implementation for ADGroupUser. +func (agu ADGroupUser) AsUser() (*User, bool) { + return nil, false +} + +// AsBasicUser is the BasicUser implementation for ADGroupUser. +func (agu ADGroupUser) AsBasicUser() (BasicUser, bool) { + return &agu, true +} + +// APIToken the access token definition. +type APIToken struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the API token. + ID *string `json:"id,omitempty"` + // Token - READ-ONLY; Value of the API token. + Token *string `json:"token,omitempty"` + // Expiry - String-formatted date representing the time when the token expires. + Expiry *date.Time `json:"expiry,omitempty"` + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` +} + +// MarshalJSON is the custom marshaler for APIToken. +func (at APIToken) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if at.Expiry != nil { + objectMap["expiry"] = at.Expiry + } + if at.Roles != nil { + objectMap["roles"] = at.Roles + } + return json.Marshal(objectMap) +} + +// APITokenCollection the paged results of API tokens. +type APITokenCollection struct { + autorest.Response `json:"-"` + // Value - The collection of API tokens. + Value *[]APIToken `json:"value,omitempty"` + // NextLink - URL to get the next page of API tokens. + NextLink *string `json:"nextLink,omitempty"` +} + +// APITokenCollectionIterator provides access to a complete listing of APIToken values. +type APITokenCollectionIterator struct { + i int + page APITokenCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *APITokenCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokenCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *APITokenCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter APITokenCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter APITokenCollectionIterator) Response() APITokenCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter APITokenCollectionIterator) Value() APIToken { + if !iter.page.NotDone() { + return APIToken{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the APITokenCollectionIterator type. +func NewAPITokenCollectionIterator(page APITokenCollectionPage) APITokenCollectionIterator { + return APITokenCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (atc APITokenCollection) IsEmpty() bool { + return atc.Value == nil || len(*atc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (atc APITokenCollection) hasNextLink() bool { + return atc.NextLink != nil && len(*atc.NextLink) != 0 +} + +// aPITokenCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (atc APITokenCollection) aPITokenCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !atc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(atc.NextLink))) +} + +// APITokenCollectionPage contains a page of APIToken values. +type APITokenCollectionPage struct { + fn func(context.Context, APITokenCollection) (APITokenCollection, error) + atc APITokenCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *APITokenCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/APITokenCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.atc) + if err != nil { + return err + } + page.atc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *APITokenCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page APITokenCollectionPage) NotDone() bool { + return !page.atc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page APITokenCollectionPage) Response() APITokenCollection { + return page.atc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page APITokenCollectionPage) Values() []APIToken { + if page.atc.IsEmpty() { + return nil + } + return *page.atc.Value +} + +// Creates a new instance of the APITokenCollectionPage type. +func NewAPITokenCollectionPage(cur APITokenCollection, getNextPage func(context.Context, APITokenCollection) (APITokenCollection, error)) APITokenCollectionPage { + return APITokenCollectionPage{ + fn: getNextPage, + atc: cur, + } +} + +// BasicAttestation the attestation definition. +type BasicAttestation interface { + AsSymmetricKeyAttestation() (*SymmetricKeyAttestation, bool) + AsTpmAttestation() (*TpmAttestation, bool) + AsX509Attestation() (*X509Attestation, bool) + AsAttestation() (*Attestation, bool) +} + +// Attestation the attestation definition. +type Attestation struct { + autorest.Response `json:"-"` + // Type - Possible values include: 'TypeAttestation', 'TypeSymmetricKey', 'TypeTpm', 'TypeX509' + Type Type `json:"type,omitempty"` +} + +func unmarshalBasicAttestation(body []byte) (BasicAttestation, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeSymmetricKey): + var ska SymmetricKeyAttestation + err := json.Unmarshal(body, &ska) + return ska, err + case string(TypeTpm): + var ta TpmAttestation + err := json.Unmarshal(body, &ta) + return ta, err + case string(TypeX509): + var xa X509Attestation + err := json.Unmarshal(body, &xa) + return xa, err + default: + var a Attestation + err := json.Unmarshal(body, &a) + return a, err + } +} +func unmarshalBasicAttestationArray(body []byte) ([]BasicAttestation, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + aArray := make([]BasicAttestation, len(rawMessages)) + + for index, rawMessage := range rawMessages { + a, err := unmarshalBasicAttestation(*rawMessage) + if err != nil { + return nil, err + } + aArray[index] = a + } + return aArray, nil +} + +// MarshalJSON is the custom marshaler for Attestation. +func (a Attestation) MarshalJSON() ([]byte, error) { + a.Type = TypeAttestation + objectMap := make(map[string]interface{}) + if a.Type != "" { + objectMap["type"] = a.Type + } + return json.Marshal(objectMap) +} + +// AsSymmetricKeyAttestation is the BasicAttestation implementation for Attestation. +func (a Attestation) AsSymmetricKeyAttestation() (*SymmetricKeyAttestation, bool) { + return nil, false +} + +// AsTpmAttestation is the BasicAttestation implementation for Attestation. +func (a Attestation) AsTpmAttestation() (*TpmAttestation, bool) { + return nil, false +} + +// AsX509Attestation is the BasicAttestation implementation for Attestation. +func (a Attestation) AsX509Attestation() (*X509Attestation, bool) { + return nil, false +} + +// AsAttestation is the BasicAttestation implementation for Attestation. +func (a Attestation) AsAttestation() (*Attestation, bool) { + return &a, true +} + +// AsBasicAttestation is the BasicAttestation implementation for Attestation. +func (a Attestation) AsBasicAttestation() (BasicAttestation, bool) { + return &a, true +} + +// AttestationModel ... +type AttestationModel struct { + autorest.Response `json:"-"` + Value BasicAttestation `json:"value,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for AttestationModel struct. +func (am *AttestationModel) UnmarshalJSON(body []byte) error { + a, err := unmarshalBasicAttestation(body) + if err != nil { + return err + } + am.Value = a + + return nil +} + +// BarChartConfiguration configuration specifying options for a bar chart tile. +type BarChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // Format - The format configuration of the bar chart + Format *ChartFormatConfiguration `json:"format,omitempty"` + // QueryRange - The query range configuration of the bar chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` +} + +// BlobStorageV1Destination the blob storage destination definition. +type BlobStorageV1Destination struct { + Authorization BasicBlobStorageV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) MarshalJSON() ([]byte, error) { + bsvd.Type = TypeBasicDestinationTypeBlobstorageV1 + objectMap := make(map[string]interface{}) + objectMap["authorization"] = bsvd.Authorization + if bsvd.DisplayName != nil { + objectMap["displayName"] = bsvd.DisplayName + } + if bsvd.Type != "" { + objectMap["type"] = bsvd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return &bsvd, true +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for BlobStorageV1Destination. +func (bsvd BlobStorageV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &bsvd, true +} + +// UnmarshalJSON is the custom unmarshaler for BlobStorageV1Destination struct. +func (bsvd *BlobStorageV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "authorization": + if v != nil { + authorization, err := unmarshalBasicBlobStorageV1DestinationAuth(*v) + if err != nil { + return err + } + bsvd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + bsvd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + bsvd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + bsvd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + bsvd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + bsvd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + bsvd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicBlobStorageV1DestinationAuth the authentication definition for blob storage destination. +type BasicBlobStorageV1DestinationAuth interface { + AsBlobStorageV1DestinationConnectionStringAuth() (*BlobStorageV1DestinationConnectionStringAuth, bool) + AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth() (*BlobStorageV1DestinationSystemAssignedManagedIdentityAuth, bool) + AsBlobStorageV1DestinationAuth() (*BlobStorageV1DestinationAuth, bool) +} + +// BlobStorageV1DestinationAuth the authentication definition for blob storage destination. +type BlobStorageV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth', 'TypeBasicBlobStorageV1DestinationAuthTypeConnectionString', 'TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicBlobStorageV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicBlobStorageV1DestinationAuth(body []byte) (BasicBlobStorageV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicBlobStorageV1DestinationAuthTypeConnectionString): + var bsvdcsa BlobStorageV1DestinationConnectionStringAuth + err := json.Unmarshal(body, &bsvdcsa) + return bsvdcsa, err + case string(TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity): + var bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth + err := json.Unmarshal(body, &bsvdsamia) + return bsvdsamia, err + default: + var bsvda BlobStorageV1DestinationAuth + err := json.Unmarshal(body, &bsvda) + return bsvda, err + } +} +func unmarshalBasicBlobStorageV1DestinationAuthArray(body []byte) ([]BasicBlobStorageV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + bsvdaArray := make([]BasicBlobStorageV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + bsvda, err := unmarshalBasicBlobStorageV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + bsvdaArray[index] = bsvda + } + return bsvdaArray, nil +} + +// MarshalJSON is the custom marshaler for BlobStorageV1DestinationAuth. +func (bsvda BlobStorageV1DestinationAuth) MarshalJSON() ([]byte, error) { + bsvda.Type = TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth + objectMap := make(map[string]interface{}) + if bsvda.Type != "" { + objectMap["type"] = bsvda.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1DestinationConnectionStringAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationAuth. +func (bsvda BlobStorageV1DestinationAuth) AsBlobStorageV1DestinationConnectionStringAuth() (*BlobStorageV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationAuth. +func (bsvda BlobStorageV1DestinationAuth) AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth() (*BlobStorageV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationAuth. +func (bsvda BlobStorageV1DestinationAuth) AsBlobStorageV1DestinationAuth() (*BlobStorageV1DestinationAuth, bool) { + return &bsvda, true +} + +// AsBasicBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationAuth. +func (bsvda BlobStorageV1DestinationAuth) AsBasicBlobStorageV1DestinationAuth() (BasicBlobStorageV1DestinationAuth, bool) { + return &bsvda, true +} + +// BlobStorageV1DestinationConnectionStringAuth the authentication definition with connection string for +// blob storage destination. +type BlobStorageV1DestinationConnectionStringAuth struct { + // ConnectionString - The connection string for accessing the blob storage account. + ConnectionString *string `json:"connectionString,omitempty"` + // ContainerName - Name of the container where data should be written in the storage account. + ContainerName *string `json:"containerName,omitempty"` + // Type - Possible values include: 'TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth', 'TypeBasicBlobStorageV1DestinationAuthTypeConnectionString', 'TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicBlobStorageV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for BlobStorageV1DestinationConnectionStringAuth. +func (bsvdcsa BlobStorageV1DestinationConnectionStringAuth) MarshalJSON() ([]byte, error) { + bsvdcsa.Type = TypeBasicBlobStorageV1DestinationAuthTypeConnectionString + objectMap := make(map[string]interface{}) + if bsvdcsa.ConnectionString != nil { + objectMap["connectionString"] = bsvdcsa.ConnectionString + } + if bsvdcsa.ContainerName != nil { + objectMap["containerName"] = bsvdcsa.ContainerName + } + if bsvdcsa.Type != "" { + objectMap["type"] = bsvdcsa.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1DestinationConnectionStringAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationConnectionStringAuth. +func (bsvdcsa BlobStorageV1DestinationConnectionStringAuth) AsBlobStorageV1DestinationConnectionStringAuth() (*BlobStorageV1DestinationConnectionStringAuth, bool) { + return &bsvdcsa, true +} + +// AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationConnectionStringAuth. +func (bsvdcsa BlobStorageV1DestinationConnectionStringAuth) AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth() (*BlobStorageV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationConnectionStringAuth. +func (bsvdcsa BlobStorageV1DestinationConnectionStringAuth) AsBlobStorageV1DestinationAuth() (*BlobStorageV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationConnectionStringAuth. +func (bsvdcsa BlobStorageV1DestinationConnectionStringAuth) AsBasicBlobStorageV1DestinationAuth() (BasicBlobStorageV1DestinationAuth, bool) { + return &bsvdcsa, true +} + +// BlobStorageV1DestinationSystemAssignedManagedIdentityAuth the authentication definition with system +// assigned managed identity for blob storage destination. +type BlobStorageV1DestinationSystemAssignedManagedIdentityAuth struct { + // EndpointURI - The storage account's blob service endpoint URL. + EndpointURI *string `json:"endpointUri,omitempty"` + // ContainerName - Name of the container where data should be written in the storage account. + ContainerName *string `json:"containerName,omitempty"` + // Type - Possible values include: 'TypeBasicBlobStorageV1DestinationAuthTypeBlobStorageV1DestinationAuth', 'TypeBasicBlobStorageV1DestinationAuthTypeConnectionString', 'TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicBlobStorageV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for BlobStorageV1DestinationSystemAssignedManagedIdentityAuth. +func (bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth) MarshalJSON() ([]byte, error) { + bsvdsamia.Type = TypeBasicBlobStorageV1DestinationAuthTypeSystemAssignedManagedIdentity + objectMap := make(map[string]interface{}) + if bsvdsamia.EndpointURI != nil { + objectMap["endpointUri"] = bsvdsamia.EndpointURI + } + if bsvdsamia.ContainerName != nil { + objectMap["containerName"] = bsvdsamia.ContainerName + } + if bsvdsamia.Type != "" { + objectMap["type"] = bsvdsamia.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1DestinationConnectionStringAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationSystemAssignedManagedIdentityAuth. +func (bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth) AsBlobStorageV1DestinationConnectionStringAuth() (*BlobStorageV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationSystemAssignedManagedIdentityAuth. +func (bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth) AsBlobStorageV1DestinationSystemAssignedManagedIdentityAuth() (*BlobStorageV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return &bsvdsamia, true +} + +// AsBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationSystemAssignedManagedIdentityAuth. +func (bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth) AsBlobStorageV1DestinationAuth() (*BlobStorageV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicBlobStorageV1DestinationAuth is the BasicBlobStorageV1DestinationAuth implementation for BlobStorageV1DestinationSystemAssignedManagedIdentityAuth. +func (bsvdsamia BlobStorageV1DestinationSystemAssignedManagedIdentityAuth) AsBasicBlobStorageV1DestinationAuth() (BasicBlobStorageV1DestinationAuth, bool) { + return &bsvdsamia, true +} + +// CapabilityJobData the capability job data definition. +type CapabilityJobData struct { + // Target - The device template which defines the target capability for the job. + Target *string `json:"target,omitempty"` + // Path - The path to the target capability within the device template. + Path *string `json:"path,omitempty"` + // Value - The value used to update the target capability, if any. + Value interface{} `json:"value,omitempty"` +} + +// ChartFormatConfiguration configuration specifying formatting options for a chart tile. +type ChartFormatConfiguration struct { + // XAxisEnabled - Whether to display the x-axis + XAxisEnabled *bool `json:"xAxisEnabled,omitempty"` + // YAxisEnabled - Whether to display the y-axis + YAxisEnabled *bool `json:"yAxisEnabled,omitempty"` + // LegendEnabled - Whether to display the legend + LegendEnabled *bool `json:"legendEnabled,omitempty"` +} + +// CloudPropertyJobData the cloud property job data. +type CloudPropertyJobData struct { + // Type - Type of the job data. + Type *string `json:"type,omitempty"` + // Target - The device template which defines the target capability for the job. + Target *string `json:"target,omitempty"` + // Path - The path to the target capability within the device template. + Path *string `json:"path,omitempty"` + // Value - The value used to update the target capability, if any. + Value interface{} `json:"value,omitempty"` +} + +// Collection the collection of entities. +type Collection struct { + autorest.Response `json:"-"` + // Value - The collection of entities. + Value *[]interface{} `json:"value,omitempty"` + // NextLink - URL to get the next page of entities. + NextLink *string `json:"nextLink,omitempty"` +} + +// CommandJobData the command job data definition. +type CommandJobData struct { + // Type - Type of the job data. + Type *string `json:"type,omitempty"` + // Target - The device template which defines the target capability for the job. + Target *string `json:"target,omitempty"` + // Path - The path to the target capability within the device template. + Path *string `json:"path,omitempty"` + // Value - The value used to update the target capability, if any. + Value interface{} `json:"value,omitempty"` +} + +// CommandTileConfiguration configuration specifying options for a command tile +type CommandTileConfiguration struct { + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Command - The command to reference in the tile + Command *string `json:"command,omitempty"` + // Device - The device to reference in the tile + Device interface{} `json:"device,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for CommandTileConfiguration. +func (ctc CommandTileConfiguration) MarshalJSON() ([]byte, error) { + ctc.Type = TypeBasicTileConfigurationTypeCommand + objectMap := make(map[string]interface{}) + if ctc.Group != nil { + objectMap["group"] = ctc.Group + } + if ctc.Command != nil { + objectMap["command"] = ctc.Command + } + if ctc.Device != nil { + objectMap["device"] = ctc.Device + } + if ctc.Type != "" { + objectMap["type"] = ctc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return &ctc, true +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for CommandTileConfiguration. +func (ctc CommandTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &ctc, true +} + +// CountQueryRangeConfiguration configuration specifying the number of data points to query for a tile. +type CountQueryRangeConfiguration struct { + // Count - The maximum number of data points to query for. + Count *int32 `json:"count,omitempty"` + // Type - Possible values include: 'TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration', 'TypeBasicQueryRangeConfigurationTypeTime', 'TypeBasicQueryRangeConfigurationTypeCount' + Type TypeBasicQueryRangeConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for CountQueryRangeConfiguration. +func (cqrc CountQueryRangeConfiguration) MarshalJSON() ([]byte, error) { + cqrc.Type = TypeBasicQueryRangeConfigurationTypeCount + objectMap := make(map[string]interface{}) + if cqrc.Count != nil { + objectMap["count"] = cqrc.Count + } + if cqrc.Type != "" { + objectMap["type"] = cqrc.Type + } + return json.Marshal(objectMap) +} + +// AsTimeQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for CountQueryRangeConfiguration. +func (cqrc CountQueryRangeConfiguration) AsTimeQueryRangeConfiguration() (*TimeQueryRangeConfiguration, bool) { + return nil, false +} + +// AsCountQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for CountQueryRangeConfiguration. +func (cqrc CountQueryRangeConfiguration) AsCountQueryRangeConfiguration() (*CountQueryRangeConfiguration, bool) { + return &cqrc, true +} + +// AsQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for CountQueryRangeConfiguration. +func (cqrc CountQueryRangeConfiguration) AsQueryRangeConfiguration() (*QueryRangeConfiguration, bool) { + return nil, false +} + +// AsBasicQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for CountQueryRangeConfiguration. +func (cqrc CountQueryRangeConfiguration) AsBasicQueryRangeConfiguration() (BasicQueryRangeConfiguration, bool) { + return &cqrc, true +} + +// Dashboard ... +type Dashboard struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the dashboard. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the dashboard. + DisplayName *string `json:"displayName,omitempty"` + // Tiles - The tiles displayed by the dashboard. + Tiles *[]Tile `json:"tiles,omitempty"` + // Personal - READ-ONLY; Whether the dashboard is personal and can only be viewed by the current user. + Personal *bool `json:"personal,omitempty"` + // Favorite - Whether the dashboard is favorited or not + Favorite *bool `json:"favorite,omitempty"` + // Etag - Etag to prevent conflict when updating the dashboard. + Etag *string `json:"etag,omitempty"` + // Organizations - The organization the dashboard belongs to. If not present, the dashboard is root-level or personal. only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` +} + +// MarshalJSON is the custom marshaler for Dashboard. +func (d Dashboard) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if d.DisplayName != nil { + objectMap["displayName"] = d.DisplayName + } + if d.Tiles != nil { + objectMap["tiles"] = d.Tiles + } + if d.Favorite != nil { + objectMap["favorite"] = d.Favorite + } + if d.Etag != nil { + objectMap["etag"] = d.Etag + } + if d.Organizations != nil { + objectMap["organizations"] = d.Organizations + } + return json.Marshal(objectMap) +} + +// DashboardCollection the paged results of dashboards. +type DashboardCollection struct { + autorest.Response `json:"-"` + // Value - The collection of dashboards. + Value *[]Dashboard `json:"value,omitempty"` + // NextLink - URL to get the next page of dashboards. + NextLink *string `json:"nextLink,omitempty"` +} + +// DashboardCollectionIterator provides access to a complete listing of Dashboard values. +type DashboardCollectionIterator struct { + i int + page DashboardCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DashboardCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DashboardCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DashboardCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DashboardCollectionIterator) Response() DashboardCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DashboardCollectionIterator) Value() Dashboard { + if !iter.page.NotDone() { + return Dashboard{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DashboardCollectionIterator type. +func NewDashboardCollectionIterator(page DashboardCollectionPage) DashboardCollectionIterator { + return DashboardCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dc DashboardCollection) IsEmpty() bool { + return dc.Value == nil || len(*dc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dc DashboardCollection) hasNextLink() bool { + return dc.NextLink != nil && len(*dc.NextLink) != 0 +} + +// dashboardCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dc DashboardCollection) dashboardCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dc.NextLink))) +} + +// DashboardCollectionPage contains a page of Dashboard values. +type DashboardCollectionPage struct { + fn func(context.Context, DashboardCollection) (DashboardCollection, error) + dc DashboardCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DashboardCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DashboardCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dc) + if err != nil { + return err + } + page.dc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DashboardCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DashboardCollectionPage) NotDone() bool { + return !page.dc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DashboardCollectionPage) Response() DashboardCollection { + return page.dc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DashboardCollectionPage) Values() []Dashboard { + if page.dc.IsEmpty() { + return nil + } + return *page.dc.Value +} + +// Creates a new instance of the DashboardCollectionPage type. +func NewDashboardCollectionPage(cur DashboardCollection, getNextPage func(context.Context, DashboardCollection) (DashboardCollection, error)) DashboardCollectionPage { + return DashboardCollectionPage{ + fn: getNextPage, + dc: cur, + } +} + +// DataExplorerTileConfiguration configuration specifying options for an image tile +type DataExplorerTileConfiguration struct { + // QueryRange - The query range configuration of the chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Query - The id of the Data Explorer query to show in the tile + Query *string `json:"query,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) MarshalJSON() ([]byte, error) { + detc.Type = TypeBasicTileConfigurationTypeDataExplorer + objectMap := make(map[string]interface{}) + if detc.QueryRange != nil { + objectMap["queryRange"] = detc.QueryRange + } + if detc.Query != nil { + objectMap["query"] = detc.Query + } + if detc.Type != "" { + objectMap["type"] = detc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return &detc, true +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for DataExplorerTileConfiguration. +func (detc DataExplorerTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &detc, true +} + +// DataExplorerV1Destination the azure data explorer destination definition. +type DataExplorerV1Destination struct { + // ClusterURL - The resource URI of the Data Explorer instance. + ClusterURL *string `json:"clusterUrl,omitempty"` + // Database - Name Data Explorer database where data should be written. + Database *string `json:"database,omitempty"` + // Table - The table within the Data Explorer database that will receive the data. + Table *string `json:"table,omitempty"` + Authorization BasicDataExplorerV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) MarshalJSON() ([]byte, error) { + devd.Type = TypeBasicDestinationTypeDataexplorerV1 + objectMap := make(map[string]interface{}) + if devd.ClusterURL != nil { + objectMap["clusterUrl"] = devd.ClusterURL + } + if devd.Database != nil { + objectMap["database"] = devd.Database + } + if devd.Table != nil { + objectMap["table"] = devd.Table + } + objectMap["authorization"] = devd.Authorization + if devd.DisplayName != nil { + objectMap["displayName"] = devd.DisplayName + } + if devd.Type != "" { + objectMap["type"] = devd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return &devd, true +} + +// AsEventHubsV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for DataExplorerV1Destination. +func (devd DataExplorerV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &devd, true +} + +// UnmarshalJSON is the custom unmarshaler for DataExplorerV1Destination struct. +func (devd *DataExplorerV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "clusterUrl": + if v != nil { + var clusterURL string + err = json.Unmarshal(*v, &clusterURL) + if err != nil { + return err + } + devd.ClusterURL = &clusterURL + } + case "database": + if v != nil { + var databaseVar string + err = json.Unmarshal(*v, &databaseVar) + if err != nil { + return err + } + devd.Database = &databaseVar + } + case "table": + if v != nil { + var table string + err = json.Unmarshal(*v, &table) + if err != nil { + return err + } + devd.Table = &table + } + case "authorization": + if v != nil { + authorization, err := unmarshalBasicDataExplorerV1DestinationAuth(*v) + if err != nil { + return err + } + devd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + devd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + devd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + devd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + devd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + devd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + devd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicDataExplorerV1DestinationAuth the authentication definition for azure data explorer destination. +type BasicDataExplorerV1DestinationAuth interface { + AsDataExplorerV1DestinationServicePrincipalAuth() (*DataExplorerV1DestinationServicePrincipalAuth, bool) + AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth() (*DataExplorerV1DestinationSystemAssignedManagedIdentityAuth, bool) + AsDataExplorerV1DestinationAuth() (*DataExplorerV1DestinationAuth, bool) +} + +// DataExplorerV1DestinationAuth the authentication definition for azure data explorer destination. +type DataExplorerV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth', 'TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal', 'TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicDataExplorerV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicDataExplorerV1DestinationAuth(body []byte) (BasicDataExplorerV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal): + var devdspa DataExplorerV1DestinationServicePrincipalAuth + err := json.Unmarshal(body, &devdspa) + return devdspa, err + case string(TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity): + var devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth + err := json.Unmarshal(body, &devdsamia) + return devdsamia, err + default: + var devda DataExplorerV1DestinationAuth + err := json.Unmarshal(body, &devda) + return devda, err + } +} +func unmarshalBasicDataExplorerV1DestinationAuthArray(body []byte) ([]BasicDataExplorerV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + devdaArray := make([]BasicDataExplorerV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + devda, err := unmarshalBasicDataExplorerV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + devdaArray[index] = devda + } + return devdaArray, nil +} + +// MarshalJSON is the custom marshaler for DataExplorerV1DestinationAuth. +func (devda DataExplorerV1DestinationAuth) MarshalJSON() ([]byte, error) { + devda.Type = TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth + objectMap := make(map[string]interface{}) + if devda.Type != "" { + objectMap["type"] = devda.Type + } + return json.Marshal(objectMap) +} + +// AsDataExplorerV1DestinationServicePrincipalAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationAuth. +func (devda DataExplorerV1DestinationAuth) AsDataExplorerV1DestinationServicePrincipalAuth() (*DataExplorerV1DestinationServicePrincipalAuth, bool) { + return nil, false +} + +// AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationAuth. +func (devda DataExplorerV1DestinationAuth) AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth() (*DataExplorerV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationAuth. +func (devda DataExplorerV1DestinationAuth) AsDataExplorerV1DestinationAuth() (*DataExplorerV1DestinationAuth, bool) { + return &devda, true +} + +// AsBasicDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationAuth. +func (devda DataExplorerV1DestinationAuth) AsBasicDataExplorerV1DestinationAuth() (BasicDataExplorerV1DestinationAuth, bool) { + return &devda, true +} + +// DataExplorerV1DestinationServicePrincipalAuth the authentication definition with service principal for +// azure data explorer destination. +type DataExplorerV1DestinationServicePrincipalAuth struct { + // ClientID - Service Principal client ID. + ClientID *string `json:"clientId,omitempty"` + // TenantID - Service Principal tenant ID. + TenantID *string `json:"tenantId,omitempty"` + // ClientSecret - Service Principal client secret. + ClientSecret *string `json:"clientSecret,omitempty"` + // Type - Possible values include: 'TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth', 'TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal', 'TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicDataExplorerV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExplorerV1DestinationServicePrincipalAuth. +func (devdspa DataExplorerV1DestinationServicePrincipalAuth) MarshalJSON() ([]byte, error) { + devdspa.Type = TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal + objectMap := make(map[string]interface{}) + if devdspa.ClientID != nil { + objectMap["clientId"] = devdspa.ClientID + } + if devdspa.TenantID != nil { + objectMap["tenantId"] = devdspa.TenantID + } + if devdspa.ClientSecret != nil { + objectMap["clientSecret"] = devdspa.ClientSecret + } + if devdspa.Type != "" { + objectMap["type"] = devdspa.Type + } + return json.Marshal(objectMap) +} + +// AsDataExplorerV1DestinationServicePrincipalAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationServicePrincipalAuth. +func (devdspa DataExplorerV1DestinationServicePrincipalAuth) AsDataExplorerV1DestinationServicePrincipalAuth() (*DataExplorerV1DestinationServicePrincipalAuth, bool) { + return &devdspa, true +} + +// AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationServicePrincipalAuth. +func (devdspa DataExplorerV1DestinationServicePrincipalAuth) AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth() (*DataExplorerV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationServicePrincipalAuth. +func (devdspa DataExplorerV1DestinationServicePrincipalAuth) AsDataExplorerV1DestinationAuth() (*DataExplorerV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationServicePrincipalAuth. +func (devdspa DataExplorerV1DestinationServicePrincipalAuth) AsBasicDataExplorerV1DestinationAuth() (BasicDataExplorerV1DestinationAuth, bool) { + return &devdspa, true +} + +// DataExplorerV1DestinationSystemAssignedManagedIdentityAuth the authentication definition with system +// assigned managed identity for azure data explorer destination. +type DataExplorerV1DestinationSystemAssignedManagedIdentityAuth struct { + // Type - Possible values include: 'TypeBasicDataExplorerV1DestinationAuthTypeDataExplorerV1DestinationAuth', 'TypeBasicDataExplorerV1DestinationAuthTypeServicePrincipal', 'TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicDataExplorerV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExplorerV1DestinationSystemAssignedManagedIdentityAuth. +func (devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth) MarshalJSON() ([]byte, error) { + devdsamia.Type = TypeBasicDataExplorerV1DestinationAuthTypeSystemAssignedManagedIdentity + objectMap := make(map[string]interface{}) + if devdsamia.Type != "" { + objectMap["type"] = devdsamia.Type + } + return json.Marshal(objectMap) +} + +// AsDataExplorerV1DestinationServicePrincipalAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationSystemAssignedManagedIdentityAuth. +func (devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth) AsDataExplorerV1DestinationServicePrincipalAuth() (*DataExplorerV1DestinationServicePrincipalAuth, bool) { + return nil, false +} + +// AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationSystemAssignedManagedIdentityAuth. +func (devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth) AsDataExplorerV1DestinationSystemAssignedManagedIdentityAuth() (*DataExplorerV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return &devdsamia, true +} + +// AsDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationSystemAssignedManagedIdentityAuth. +func (devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth) AsDataExplorerV1DestinationAuth() (*DataExplorerV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicDataExplorerV1DestinationAuth is the BasicDataExplorerV1DestinationAuth implementation for DataExplorerV1DestinationSystemAssignedManagedIdentityAuth. +func (devdsamia DataExplorerV1DestinationSystemAssignedManagedIdentityAuth) AsBasicDataExplorerV1DestinationAuth() (BasicDataExplorerV1DestinationAuth, bool) { + return &devdsamia, true +} + +// DataExportError the data export error definition. +type DataExportError struct { + // Code - READ-ONLY; The code for the error that occurred. + Code *string `json:"code,omitempty"` + // Message - READ-ONLY; The description of the error that occurred. + Message *string `json:"message,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExportError. +func (dee DataExportError) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// DataExportStatus the data export status definition. +type DataExportStatus struct { + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for DataExportStatus. +func (desVar DataExportStatus) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// DateJobScheduleEnd the date based end definition of job schedule. +type DateJobScheduleEnd struct { + // Date - The date when to end the scheduled job. + Date *date.Date `json:"date,omitempty"` + // Type - Possible values include: 'TypeBasicJobScheduleEndTypeJobScheduleEnd', 'TypeBasicJobScheduleEndTypeDate', 'TypeBasicJobScheduleEndTypeOccurrences' + Type TypeBasicJobScheduleEnd `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DateJobScheduleEnd. +func (djse DateJobScheduleEnd) MarshalJSON() ([]byte, error) { + djse.Type = TypeBasicJobScheduleEndTypeDate + objectMap := make(map[string]interface{}) + if djse.Date != nil { + objectMap["date"] = djse.Date + } + if djse.Type != "" { + objectMap["type"] = djse.Type + } + return json.Marshal(objectMap) +} + +// AsDateJobScheduleEnd is the BasicJobScheduleEnd implementation for DateJobScheduleEnd. +func (djse DateJobScheduleEnd) AsDateJobScheduleEnd() (*DateJobScheduleEnd, bool) { + return &djse, true +} + +// AsOccurrencesJobScheduleEnd is the BasicJobScheduleEnd implementation for DateJobScheduleEnd. +func (djse DateJobScheduleEnd) AsOccurrencesJobScheduleEnd() (*OccurrencesJobScheduleEnd, bool) { + return nil, false +} + +// AsJobScheduleEnd is the BasicJobScheduleEnd implementation for DateJobScheduleEnd. +func (djse DateJobScheduleEnd) AsJobScheduleEnd() (*JobScheduleEnd, bool) { + return nil, false +} + +// AsBasicJobScheduleEnd is the BasicJobScheduleEnd implementation for DateJobScheduleEnd. +func (djse DateJobScheduleEnd) AsBasicJobScheduleEnd() (BasicJobScheduleEnd, bool) { + return &djse, true +} + +// DeploymentManifest the deployment manifest used for edge devices. +type DeploymentManifest struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the deployment manifest. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the deployment manifest. + DisplayName *string `json:"displayName,omitempty"` + // Data - Content of the the deployment manifest. + Data interface{} `json:"data,omitempty"` + // Etag - Etag to prevent conflict when updating the deployment manifest. + Etag *string `json:"etag,omitempty"` + // Organizations - The organization that deployment manifest belongs to. If not present, the deployment manifest is root-level or personal. Only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeploymentManifest. +func (dm DeploymentManifest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dm.DisplayName != nil { + objectMap["displayName"] = dm.DisplayName + } + if dm.Data != nil { + objectMap["data"] = dm.Data + } + if dm.Etag != nil { + objectMap["etag"] = dm.Etag + } + if dm.Organizations != nil { + objectMap["organizations"] = dm.Organizations + } + return json.Marshal(objectMap) +} + +// DeploymentManifestCollection the paged results of deployment manifests. +type DeploymentManifestCollection struct { + autorest.Response `json:"-"` + // Value - The collection of deployment manifests. + Value *[]DeploymentManifest `json:"value,omitempty"` + // NextLink - URL to get the next page of deployment manifests. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeploymentManifestCollectionIterator provides access to a complete listing of DeploymentManifest values. +type DeploymentManifestCollectionIterator struct { + i int + page DeploymentManifestCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeploymentManifestCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeploymentManifestCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeploymentManifestCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeploymentManifestCollectionIterator) Response() DeploymentManifestCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeploymentManifestCollectionIterator) Value() DeploymentManifest { + if !iter.page.NotDone() { + return DeploymentManifest{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeploymentManifestCollectionIterator type. +func NewDeploymentManifestCollectionIterator(page DeploymentManifestCollectionPage) DeploymentManifestCollectionIterator { + return DeploymentManifestCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dmc DeploymentManifestCollection) IsEmpty() bool { + return dmc.Value == nil || len(*dmc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dmc DeploymentManifestCollection) hasNextLink() bool { + return dmc.NextLink != nil && len(*dmc.NextLink) != 0 +} + +// deploymentManifestCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dmc DeploymentManifestCollection) deploymentManifestCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dmc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dmc.NextLink))) +} + +// DeploymentManifestCollectionPage contains a page of DeploymentManifest values. +type DeploymentManifestCollectionPage struct { + fn func(context.Context, DeploymentManifestCollection) (DeploymentManifestCollection, error) + dmc DeploymentManifestCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeploymentManifestCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeploymentManifestCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dmc) + if err != nil { + return err + } + page.dmc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeploymentManifestCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeploymentManifestCollectionPage) NotDone() bool { + return !page.dmc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeploymentManifestCollectionPage) Response() DeploymentManifestCollection { + return page.dmc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeploymentManifestCollectionPage) Values() []DeploymentManifest { + if page.dmc.IsEmpty() { + return nil + } + return *page.dmc.Value +} + +// Creates a new instance of the DeploymentManifestCollectionPage type. +func NewDeploymentManifestCollectionPage(cur DeploymentManifestCollection, getNextPage func(context.Context, DeploymentManifestCollection) (DeploymentManifestCollection, error)) DeploymentManifestCollectionPage { + return DeploymentManifestCollectionPage{ + fn: getNextPage, + dmc: cur, + } +} + +// BasicDestination the destination definition. +type BasicDestination interface { + AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) + AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) + AsEventHubsV1Destination() (*EventHubsV1Destination, bool) + AsExportDestination() (*ExportDestination, bool) + AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) + AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) + AsWebhookV1Destination() (*WebhookV1Destination, bool) + AsDestination() (*Destination, bool) +} + +// Destination the destination definition. +type Destination struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +func unmarshalBasicDestination(body []byte) (BasicDestination, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicDestinationTypeBlobstorageV1): + var bsvd BlobStorageV1Destination + err := json.Unmarshal(body, &bsvd) + return bsvd, err + case string(TypeBasicDestinationTypeDataexplorerV1): + var devd DataExplorerV1Destination + err := json.Unmarshal(body, &devd) + return devd, err + case string(TypeBasicDestinationTypeEventhubsV1): + var ehvd EventHubsV1Destination + err := json.Unmarshal(body, &ehvd) + return ehvd, err + case string(TypeBasicDestinationTypeExportDestination): + var ed ExportDestination + err := json.Unmarshal(body, &ed) + return ed, err + case string(TypeBasicDestinationTypeServicebusqueueV1): + var sbqvd ServiceBusQueueV1Destination + err := json.Unmarshal(body, &sbqvd) + return sbqvd, err + case string(TypeBasicDestinationTypeServicebustopicV1): + var sbtvd ServiceBusTopicV1Destination + err := json.Unmarshal(body, &sbtvd) + return sbtvd, err + case string(TypeBasicDestinationTypeWebhookV1): + var wvd WebhookV1Destination + err := json.Unmarshal(body, &wvd) + return wvd, err + default: + var d Destination + err := json.Unmarshal(body, &d) + return d, err + } +} +func unmarshalBasicDestinationArray(body []byte) ([]BasicDestination, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + dArray := make([]BasicDestination, len(rawMessages)) + + for index, rawMessage := range rawMessages { + d, err := unmarshalBasicDestination(*rawMessage) + if err != nil { + return nil, err + } + dArray[index] = d + } + return dArray, nil +} + +// MarshalJSON is the custom marshaler for Destination. +func (d Destination) MarshalJSON() ([]byte, error) { + d.Type = TypeBasicDestinationTypeDestination + objectMap := make(map[string]interface{}) + if d.DisplayName != nil { + objectMap["displayName"] = d.DisplayName + } + if d.Type != "" { + objectMap["type"] = d.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for Destination. +func (d Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for Destination. +func (d Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for Destination. +func (d Destination) AsDestination() (*Destination, bool) { + return &d, true +} + +// AsBasicDestination is the BasicDestination implementation for Destination. +func (d Destination) AsBasicDestination() (BasicDestination, bool) { + return &d, true +} + +// DestinationCollection the paged results of destinations. +type DestinationCollection struct { + autorest.Response `json:"-"` + // Value - The collection of destinations. + Value *[]BasicDestination `json:"value,omitempty"` + // NextLink - URL to get the next page of destinations. + NextLink *string `json:"nextLink,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for DestinationCollection struct. +func (dc *DestinationCollection) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "value": + if v != nil { + value, err := unmarshalBasicDestinationArray(*v) + if err != nil { + return err + } + dc.Value = &value + } + case "nextLink": + if v != nil { + var nextLink string + err = json.Unmarshal(*v, &nextLink) + if err != nil { + return err + } + dc.NextLink = &nextLink + } + } + } + + return nil +} + +// DestinationCollectionIterator provides access to a complete listing of Destination values. +type DestinationCollectionIterator struct { + i int + page DestinationCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DestinationCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DestinationCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DestinationCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DestinationCollectionIterator) Response() DestinationCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DestinationCollectionIterator) Value() BasicDestination { + if !iter.page.NotDone() { + return Destination{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DestinationCollectionIterator type. +func NewDestinationCollectionIterator(page DestinationCollectionPage) DestinationCollectionIterator { + return DestinationCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dc DestinationCollection) IsEmpty() bool { + return dc.Value == nil || len(*dc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dc DestinationCollection) hasNextLink() bool { + return dc.NextLink != nil && len(*dc.NextLink) != 0 +} + +// destinationCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dc DestinationCollection) destinationCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dc.NextLink))) +} + +// DestinationCollectionPage contains a page of BasicDestination values. +type DestinationCollectionPage struct { + fn func(context.Context, DestinationCollection) (DestinationCollection, error) + dc DestinationCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DestinationCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DestinationCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dc) + if err != nil { + return err + } + page.dc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DestinationCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DestinationCollectionPage) NotDone() bool { + return !page.dc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DestinationCollectionPage) Response() DestinationCollection { + return page.dc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DestinationCollectionPage) Values() []BasicDestination { + if page.dc.IsEmpty() { + return nil + } + return *page.dc.Value +} + +// Creates a new instance of the DestinationCollectionPage type. +func NewDestinationCollectionPage(cur DestinationCollection, getNextPage func(context.Context, DestinationCollection) (DestinationCollection, error)) DestinationCollectionPage { + return DestinationCollectionPage{ + fn: getNextPage, + dc: cur, + } +} + +// DestinationExport the destination export definition. +type DestinationExport struct { + // Transform - Query for transforming the message structure to a particular output. + Transform *string `json:"transform,omitempty"` + // ID - READ-ONLY; Unique ID of the export. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the export. + DisplayName *string `json:"displayName,omitempty"` + // Enabled - Toggle to start/stop an export from sending data. + Enabled *bool `json:"enabled,omitempty"` + // Source - The type of data to export. Possible values include: 'DestinationSourceTelemetry', 'DestinationSourceProperties', 'DestinationSourceDeviceLifecycle', 'DestinationSourceDeviceTemplateLifecycle', 'DestinationSourceDeviceConnectivity', 'DestinationSourceAudit' + Source DestinationSource `json:"source,omitempty"` + // Filter - Query defining which events from the source should be exported. + Filter *string `json:"filter,omitempty"` + // Enrichments - Additional pieces of information to include with each sent message. Data is represented as a set of key/value pairs, where the key is the name of the enrichment that will appear in the output message and the value identifies the data to send. + Enrichments map[string]*Enrichment `json:"enrichments"` + // Destinations - The list of destinations to which the export should send data. + Destinations *[]DestinationReference `json:"destinations,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for DestinationExport. +func (de DestinationExport) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if de.Transform != nil { + objectMap["transform"] = de.Transform + } + if de.DisplayName != nil { + objectMap["displayName"] = de.DisplayName + } + if de.Enabled != nil { + objectMap["enabled"] = de.Enabled + } + if de.Source != "" { + objectMap["source"] = de.Source + } + if de.Filter != nil { + objectMap["filter"] = de.Filter + } + if de.Enrichments != nil { + objectMap["enrichments"] = de.Enrichments + } + if de.Destinations != nil { + objectMap["destinations"] = de.Destinations + } + return json.Marshal(objectMap) +} + +// DestinationModel ... +type DestinationModel struct { + autorest.Response `json:"-"` + Value BasicDestination `json:"value,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for DestinationModel struct. +func (dm *DestinationModel) UnmarshalJSON(body []byte) error { + d, err := unmarshalBasicDestination(body) + if err != nil { + return err + } + dm.Value = d + + return nil +} + +// DestinationReference the destination reference definition. +type DestinationReference struct { + // ID - The ID of the destination where data should be sent. + ID *string `json:"id,omitempty"` + // Transform - Query for transforming the message structure to a particular output. + Transform *string `json:"transform,omitempty"` +} + +// Device the device definition. +type Device struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the device. + ID *string `json:"id,omitempty"` + // Etag - ETag used to prevent conflict in device updates. + Etag *string `json:"etag,omitempty"` + // DisplayName - Display name of the device. + DisplayName *string `json:"displayName,omitempty"` + // Template - The device template definition for the device. + Template *string `json:"template,omitempty"` + // Enabled - Whether the device connection to IoT Central has been enabled. + Enabled *bool `json:"enabled,omitempty"` + // Provisioned - READ-ONLY; Whether resources have been allocated for the device. + Provisioned *bool `json:"provisioned,omitempty"` + // Simulated - Whether the device is simulated. + Simulated *bool `json:"simulated,omitempty"` + // Organizations - List of organization IDs that the device is a part of, only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` + // Type - The type of the device. + Type *[]DeviceType `json:"type,omitempty"` + // DeploymentManifest - The deployment manifest assigned to the device. + DeploymentManifest *DeploymentManifest `json:"deploymentManifest,omitempty"` +} + +// MarshalJSON is the custom marshaler for Device. +func (d Device) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if d.Etag != nil { + objectMap["etag"] = d.Etag + } + if d.DisplayName != nil { + objectMap["displayName"] = d.DisplayName + } + if d.Template != nil { + objectMap["template"] = d.Template + } + if d.Enabled != nil { + objectMap["enabled"] = d.Enabled + } + if d.Simulated != nil { + objectMap["simulated"] = d.Simulated + } + if d.Organizations != nil { + objectMap["organizations"] = d.Organizations + } + if d.Type != nil { + objectMap["type"] = d.Type + } + if d.DeploymentManifest != nil { + objectMap["deploymentManifest"] = d.DeploymentManifest + } + return json.Marshal(objectMap) +} + +// DeviceCollection the paged results of devices. +type DeviceCollection struct { + autorest.Response `json:"-"` + // Value - The collection of devices. + Value *[]Device `json:"value,omitempty"` + // NextLink - URL to get the next page of devices. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceCollectionIterator provides access to a complete listing of Device values. +type DeviceCollectionIterator struct { + i int + page DeviceCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceCollectionIterator) Response() DeviceCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceCollectionIterator) Value() Device { + if !iter.page.NotDone() { + return Device{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceCollectionIterator type. +func NewDeviceCollectionIterator(page DeviceCollectionPage) DeviceCollectionIterator { + return DeviceCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dc DeviceCollection) IsEmpty() bool { + return dc.Value == nil || len(*dc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dc DeviceCollection) hasNextLink() bool { + return dc.NextLink != nil && len(*dc.NextLink) != 0 +} + +// deviceCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dc DeviceCollection) deviceCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dc.NextLink))) +} + +// DeviceCollectionPage contains a page of Device values. +type DeviceCollectionPage struct { + fn func(context.Context, DeviceCollection) (DeviceCollection, error) + dc DeviceCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dc) + if err != nil { + return err + } + page.dc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceCollectionPage) NotDone() bool { + return !page.dc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceCollectionPage) Response() DeviceCollection { + return page.dc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceCollectionPage) Values() []Device { + if page.dc.IsEmpty() { + return nil + } + return *page.dc.Value +} + +// Creates a new instance of the DeviceCollectionPage type. +func NewDeviceCollectionPage(cur DeviceCollection, getNextPage func(context.Context, DeviceCollection) (DeviceCollection, error)) DeviceCollectionPage { + return DeviceCollectionPage{ + fn: getNextPage, + dc: cur, + } +} + +// DeviceCommand the device command definition. +type DeviceCommand struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; The request ID of the device command execution. + ID *string `json:"id,omitempty"` + // ConnectionTimeout - Connection timeout in seconds to wait for a disconnected device to come online. Defaults to 0 seconds. + ConnectionTimeout *int32 `json:"connectionTimeout,omitempty"` + // ResponseTimeout - Response timeout in seconds to wait for a command completion on a device. Defaults to 30 seconds. + ResponseTimeout *int32 `json:"responseTimeout,omitempty"` + // Request - The payload for the device command, support any primitive types or object. + Request interface{} `json:"request,omitempty"` + // ResponseCode - READ-ONLY; The status code of the device command response. + ResponseCode *int32 `json:"responseCode,omitempty"` + // APIResponse - READ-ONLY; The payload of the device command response, support any primitive types or object. + APIResponse interface{} `json:"apiResponse,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceCommand. +func (dc DeviceCommand) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dc.ConnectionTimeout != nil { + objectMap["connectionTimeout"] = dc.ConnectionTimeout + } + if dc.ResponseTimeout != nil { + objectMap["responseTimeout"] = dc.ResponseTimeout + } + if dc.Request != nil { + objectMap["request"] = dc.Request + } + return json.Marshal(objectMap) +} + +// DeviceCommandCollection the paged results of device command executions. +type DeviceCommandCollection struct { + autorest.Response `json:"-"` + // Value - The collection of device command executions. + Value *[]DeviceCommand `json:"value,omitempty"` + // NextLink - URL to get the next page of device command executions. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceCommandCollectionIterator provides access to a complete listing of DeviceCommand values. +type DeviceCommandCollectionIterator struct { + i int + page DeviceCommandCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceCommandCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceCommandCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceCommandCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceCommandCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceCommandCollectionIterator) Response() DeviceCommandCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceCommandCollectionIterator) Value() DeviceCommand { + if !iter.page.NotDone() { + return DeviceCommand{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceCommandCollectionIterator type. +func NewDeviceCommandCollectionIterator(page DeviceCommandCollectionPage) DeviceCommandCollectionIterator { + return DeviceCommandCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dcc DeviceCommandCollection) IsEmpty() bool { + return dcc.Value == nil || len(*dcc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dcc DeviceCommandCollection) hasNextLink() bool { + return dcc.NextLink != nil && len(*dcc.NextLink) != 0 +} + +// deviceCommandCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dcc DeviceCommandCollection) deviceCommandCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dcc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dcc.NextLink))) +} + +// DeviceCommandCollectionPage contains a page of DeviceCommand values. +type DeviceCommandCollectionPage struct { + fn func(context.Context, DeviceCommandCollection) (DeviceCommandCollection, error) + dcc DeviceCommandCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceCommandCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceCommandCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dcc) + if err != nil { + return err + } + page.dcc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceCommandCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceCommandCollectionPage) NotDone() bool { + return !page.dcc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceCommandCollectionPage) Response() DeviceCommandCollection { + return page.dcc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceCommandCollectionPage) Values() []DeviceCommand { + if page.dcc.IsEmpty() { + return nil + } + return *page.dcc.Value +} + +// Creates a new instance of the DeviceCommandCollectionPage type. +func NewDeviceCommandCollectionPage(cur DeviceCommandCollection, getNextPage func(context.Context, DeviceCommandCollection) (DeviceCommandCollection, error)) DeviceCommandCollectionPage { + return DeviceCommandCollectionPage{ + fn: getNextPage, + dcc: cur, + } +} + +// DeviceCountTileConfiguration configuration specifying options for a device count tile. +type DeviceCountTileConfiguration struct { + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Format - The format configuration of the device count tile + Format *TextFormatConfiguration `json:"format,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) MarshalJSON() ([]byte, error) { + dctc.Type = TypeBasicTileConfigurationTypeDeviceCount + objectMap := make(map[string]interface{}) + if dctc.Group != nil { + objectMap["group"] = dctc.Group + } + if dctc.Format != nil { + objectMap["format"] = dctc.Format + } + if dctc.Type != "" { + objectMap["type"] = dctc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return &dctc, true +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for DeviceCountTileConfiguration. +func (dctc DeviceCountTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &dctc, true +} + +// DeviceCredentials the device credentials definition. +type DeviceCredentials struct { + autorest.Response `json:"-"` + // IDScope - ID scope for connecting to the IoT Central application. + IDScope *string `json:"idScope,omitempty"` + // SymmetricKey - The symmetric key credentials for the device. + SymmetricKey *SymmetricKey `json:"symmetricKey,omitempty"` + // X509 - The X.509 credential information for the device. + X509 *X509 `json:"x509,omitempty"` + // Tpm - The TPM credentials for the device. + Tpm *Tpm `json:"tpm,omitempty"` +} + +// DeviceGroup the device group definition. +type DeviceGroup struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the device group. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the device group. + DisplayName *string `json:"displayName,omitempty"` + // Filter - Query defining which devices should be in this group, [Query Language Reference](https://aka.ms/iotcquery). + Filter *string `json:"filter,omitempty"` + // Description - Short summary of device group. + Description *string `json:"description,omitempty"` + // Etag - ETag used to prevent conflict in device group updates. + Etag *string `json:"etag,omitempty"` + // Organizations - List of organization IDs of the device group, only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceGroup. +func (dg DeviceGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dg.DisplayName != nil { + objectMap["displayName"] = dg.DisplayName + } + if dg.Filter != nil { + objectMap["filter"] = dg.Filter + } + if dg.Description != nil { + objectMap["description"] = dg.Description + } + if dg.Etag != nil { + objectMap["etag"] = dg.Etag + } + if dg.Organizations != nil { + objectMap["organizations"] = dg.Organizations + } + return json.Marshal(objectMap) +} + +// DeviceGroupCollection the paged results of device groups. +type DeviceGroupCollection struct { + autorest.Response `json:"-"` + // Value - The collection of device groups. + Value *[]DeviceGroup `json:"value,omitempty"` + // NextLink - URL to get the next page of device groups. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceGroupCollectionIterator provides access to a complete listing of DeviceGroup values. +type DeviceGroupCollectionIterator struct { + i int + page DeviceGroupCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceGroupCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceGroupCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceGroupCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceGroupCollectionIterator) Response() DeviceGroupCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceGroupCollectionIterator) Value() DeviceGroup { + if !iter.page.NotDone() { + return DeviceGroup{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceGroupCollectionIterator type. +func NewDeviceGroupCollectionIterator(page DeviceGroupCollectionPage) DeviceGroupCollectionIterator { + return DeviceGroupCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dgc DeviceGroupCollection) IsEmpty() bool { + return dgc.Value == nil || len(*dgc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dgc DeviceGroupCollection) hasNextLink() bool { + return dgc.NextLink != nil && len(*dgc.NextLink) != 0 +} + +// deviceGroupCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dgc DeviceGroupCollection) deviceGroupCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dgc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dgc.NextLink))) +} + +// DeviceGroupCollectionPage contains a page of DeviceGroup values. +type DeviceGroupCollectionPage struct { + fn func(context.Context, DeviceGroupCollection) (DeviceGroupCollection, error) + dgc DeviceGroupCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceGroupCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dgc) + if err != nil { + return err + } + page.dgc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceGroupCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceGroupCollectionPage) NotDone() bool { + return !page.dgc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceGroupCollectionPage) Response() DeviceGroupCollection { + return page.dgc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceGroupCollectionPage) Values() []DeviceGroup { + if page.dgc.IsEmpty() { + return nil + } + return *page.dgc.Value +} + +// Creates a new instance of the DeviceGroupCollectionPage type. +func NewDeviceGroupCollectionPage(cur DeviceGroupCollection, getNextPage func(context.Context, DeviceGroupCollection) (DeviceGroupCollection, error)) DeviceGroupCollectionPage { + return DeviceGroupCollectionPage{ + fn: getNextPage, + dgc: cur, + } +} + +// DeviceGroupDeviceCollection the paged results of devices belonging to the device group. +type DeviceGroupDeviceCollection struct { + autorest.Response `json:"-"` + // Value - The collection of devices belonging to the device group. + Value *[]Device `json:"value,omitempty"` + // NextLink - URL to get the next page of devices in the group. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceGroupDeviceCollectionIterator provides access to a complete listing of Device values. +type DeviceGroupDeviceCollectionIterator struct { + i int + page DeviceGroupDeviceCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceGroupDeviceCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupDeviceCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceGroupDeviceCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceGroupDeviceCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceGroupDeviceCollectionIterator) Response() DeviceGroupDeviceCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceGroupDeviceCollectionIterator) Value() Device { + if !iter.page.NotDone() { + return Device{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceGroupDeviceCollectionIterator type. +func NewDeviceGroupDeviceCollectionIterator(page DeviceGroupDeviceCollectionPage) DeviceGroupDeviceCollectionIterator { + return DeviceGroupDeviceCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dgdc DeviceGroupDeviceCollection) IsEmpty() bool { + return dgdc.Value == nil || len(*dgdc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dgdc DeviceGroupDeviceCollection) hasNextLink() bool { + return dgdc.NextLink != nil && len(*dgdc.NextLink) != 0 +} + +// deviceGroupDeviceCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dgdc DeviceGroupDeviceCollection) deviceGroupDeviceCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dgdc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dgdc.NextLink))) +} + +// DeviceGroupDeviceCollectionPage contains a page of Device values. +type DeviceGroupDeviceCollectionPage struct { + fn func(context.Context, DeviceGroupDeviceCollection) (DeviceGroupDeviceCollection, error) + dgdc DeviceGroupDeviceCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceGroupDeviceCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceGroupDeviceCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dgdc) + if err != nil { + return err + } + page.dgdc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceGroupDeviceCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceGroupDeviceCollectionPage) NotDone() bool { + return !page.dgdc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceGroupDeviceCollectionPage) Response() DeviceGroupDeviceCollection { + return page.dgdc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceGroupDeviceCollectionPage) Values() []Device { + if page.dgdc.IsEmpty() { + return nil + } + return *page.dgdc.Value +} + +// Creates a new instance of the DeviceGroupDeviceCollectionPage type. +func NewDeviceGroupDeviceCollectionPage(cur DeviceGroupDeviceCollection, getNextPage func(context.Context, DeviceGroupDeviceCollection) (DeviceGroupDeviceCollection, error)) DeviceGroupDeviceCollectionPage { + return DeviceGroupDeviceCollectionPage{ + fn: getNextPage, + dgdc: cur, + } +} + +// DeviceManifestMigrationJobData the edge device manifest migration job definition. +type DeviceManifestMigrationJobData struct { + // Manifest - The target manifest identifier to which devices will be migrated. + Manifest *string `json:"manifest,omitempty"` + // Type - Possible values include: 'TypeBasicJobDataTypeJobData', 'TypeBasicJobDataTypeDeviceManifestMigration', 'TypeBasicJobDataTypeDeviceTemplateMigration' + Type TypeBasicJobData `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceManifestMigrationJobData. +func (dmmjd DeviceManifestMigrationJobData) MarshalJSON() ([]byte, error) { + dmmjd.Type = TypeBasicJobDataTypeDeviceManifestMigration + objectMap := make(map[string]interface{}) + if dmmjd.Manifest != nil { + objectMap["manifest"] = dmmjd.Manifest + } + if dmmjd.Type != "" { + objectMap["type"] = dmmjd.Type + } + return json.Marshal(objectMap) +} + +// AsDeviceManifestMigrationJobData is the BasicJobData implementation for DeviceManifestMigrationJobData. +func (dmmjd DeviceManifestMigrationJobData) AsDeviceManifestMigrationJobData() (*DeviceManifestMigrationJobData, bool) { + return &dmmjd, true +} + +// AsDeviceTemplateMigrationJobData is the BasicJobData implementation for DeviceManifestMigrationJobData. +func (dmmjd DeviceManifestMigrationJobData) AsDeviceTemplateMigrationJobData() (*DeviceTemplateMigrationJobData, bool) { + return nil, false +} + +// AsJobData is the BasicJobData implementation for DeviceManifestMigrationJobData. +func (dmmjd DeviceManifestMigrationJobData) AsJobData() (*JobData, bool) { + return nil, false +} + +// AsBasicJobData is the BasicJobData implementation for DeviceManifestMigrationJobData. +func (dmmjd DeviceManifestMigrationJobData) AsBasicJobData() (BasicJobData, bool) { + return &dmmjd, true +} + +// DeviceRelationship an object representing the relationship between an upstream and a downstream device. +type DeviceRelationship struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; The unique identifier of this relationship. + ID *string `json:"id,omitempty"` + // Source - The device ID of the source (parent) device. + Source *string `json:"source,omitempty"` + // Target - The device ID of the target (child) device. + Target *string `json:"target,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceRelationship. +func (dr DeviceRelationship) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dr.Source != nil { + objectMap["source"] = dr.Source + } + if dr.Target != nil { + objectMap["target"] = dr.Target + } + return json.Marshal(objectMap) +} + +// DeviceRelationshipCollection the paged results of device relationships. +type DeviceRelationshipCollection struct { + autorest.Response `json:"-"` + // Value - The collection of device relationships. + Value *[]DeviceRelationship `json:"value,omitempty"` + // NextLink - URL to get the next page of device relationships. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceRelationshipCollectionIterator provides access to a complete listing of DeviceRelationship values. +type DeviceRelationshipCollectionIterator struct { + i int + page DeviceRelationshipCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceRelationshipCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceRelationshipCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceRelationshipCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceRelationshipCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceRelationshipCollectionIterator) Response() DeviceRelationshipCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceRelationshipCollectionIterator) Value() DeviceRelationship { + if !iter.page.NotDone() { + return DeviceRelationship{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceRelationshipCollectionIterator type. +func NewDeviceRelationshipCollectionIterator(page DeviceRelationshipCollectionPage) DeviceRelationshipCollectionIterator { + return DeviceRelationshipCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (drc DeviceRelationshipCollection) IsEmpty() bool { + return drc.Value == nil || len(*drc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (drc DeviceRelationshipCollection) hasNextLink() bool { + return drc.NextLink != nil && len(*drc.NextLink) != 0 +} + +// deviceRelationshipCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (drc DeviceRelationshipCollection) deviceRelationshipCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !drc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(drc.NextLink))) +} + +// DeviceRelationshipCollectionPage contains a page of DeviceRelationship values. +type DeviceRelationshipCollectionPage struct { + fn func(context.Context, DeviceRelationshipCollection) (DeviceRelationshipCollection, error) + drc DeviceRelationshipCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceRelationshipCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceRelationshipCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.drc) + if err != nil { + return err + } + page.drc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceRelationshipCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceRelationshipCollectionPage) NotDone() bool { + return !page.drc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceRelationshipCollectionPage) Response() DeviceRelationshipCollection { + return page.drc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceRelationshipCollectionPage) Values() []DeviceRelationship { + if page.drc.IsEmpty() { + return nil + } + return *page.drc.Value +} + +// Creates a new instance of the DeviceRelationshipCollectionPage type. +func NewDeviceRelationshipCollectionPage(cur DeviceRelationshipCollection, getNextPage func(context.Context, DeviceRelationshipCollection) (DeviceRelationshipCollection, error)) DeviceRelationshipCollectionPage { + return DeviceRelationshipCollectionPage{ + fn: getNextPage, + drc: cur, + } +} + +// DeviceTelemetry the device telemetry definition. +type DeviceTelemetry struct { + autorest.Response `json:"-"` + // Value - The last known value of this device telemetry. + Value interface{} `json:"value,omitempty"` + // Timestamp - String-formatted date representing the time when the telemetry value was sent. + Timestamp *date.Time `json:"timestamp,omitempty"` +} + +// DeviceTemplate the device template definition. +type DeviceTemplate struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the device template. + ID *string `json:"@id,omitempty"` + // Type - The JSON-LD types of this device template. + Type *[]string `json:"@type,omitempty"` + // Etag - ETag used to prevent conflict in device template updates. + Etag *string `json:"etag,omitempty"` + // DisplayName - Display name of the device template. + DisplayName *string `json:"displayName,omitempty"` + // Description - Detailed description of the device template. + Description *string `json:"description,omitempty"` + // CapabilityModel - The capability model utilized by this device template. + CapabilityModel interface{} `json:"capabilityModel,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceTemplate. +func (dt DeviceTemplate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dt.Type != nil { + objectMap["@type"] = dt.Type + } + if dt.Etag != nil { + objectMap["etag"] = dt.Etag + } + if dt.DisplayName != nil { + objectMap["displayName"] = dt.DisplayName + } + if dt.Description != nil { + objectMap["description"] = dt.Description + } + if dt.CapabilityModel != nil { + objectMap["capabilityModel"] = dt.CapabilityModel + } + return json.Marshal(objectMap) +} + +// DeviceTemplateCollection the paged results of device templates. +type DeviceTemplateCollection struct { + autorest.Response `json:"-"` + // Value - The collection of device templates. + Value *[]DeviceTemplate `json:"value,omitempty"` + // NextLink - URL to get the next page of device templates. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeviceTemplateCollectionIterator provides access to a complete listing of DeviceTemplate values. +type DeviceTemplateCollectionIterator struct { + i int + page DeviceTemplateCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeviceTemplateCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplateCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeviceTemplateCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeviceTemplateCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeviceTemplateCollectionIterator) Response() DeviceTemplateCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeviceTemplateCollectionIterator) Value() DeviceTemplate { + if !iter.page.NotDone() { + return DeviceTemplate{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeviceTemplateCollectionIterator type. +func NewDeviceTemplateCollectionIterator(page DeviceTemplateCollectionPage) DeviceTemplateCollectionIterator { + return DeviceTemplateCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dtc DeviceTemplateCollection) IsEmpty() bool { + return dtc.Value == nil || len(*dtc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dtc DeviceTemplateCollection) hasNextLink() bool { + return dtc.NextLink != nil && len(*dtc.NextLink) != 0 +} + +// deviceTemplateCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dtc DeviceTemplateCollection) deviceTemplateCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !dtc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dtc.NextLink))) +} + +// DeviceTemplateCollectionPage contains a page of DeviceTemplate values. +type DeviceTemplateCollectionPage struct { + fn func(context.Context, DeviceTemplateCollection) (DeviceTemplateCollection, error) + dtc DeviceTemplateCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeviceTemplateCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeviceTemplateCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dtc) + if err != nil { + return err + } + page.dtc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeviceTemplateCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeviceTemplateCollectionPage) NotDone() bool { + return !page.dtc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeviceTemplateCollectionPage) Response() DeviceTemplateCollection { + return page.dtc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeviceTemplateCollectionPage) Values() []DeviceTemplate { + if page.dtc.IsEmpty() { + return nil + } + return *page.dtc.Value +} + +// Creates a new instance of the DeviceTemplateCollectionPage type. +func NewDeviceTemplateCollectionPage(cur DeviceTemplateCollection, getNextPage func(context.Context, DeviceTemplateCollection) (DeviceTemplateCollection, error)) DeviceTemplateCollectionPage { + return DeviceTemplateCollectionPage{ + fn: getNextPage, + dtc: cur, + } +} + +// DeviceTemplateMigrationJobData the device template migration job data definition. +type DeviceTemplateMigrationJobData struct { + // Template - The target device template to which devices will be migrated. + Template *string `json:"template,omitempty"` + // Type - Possible values include: 'TypeBasicJobDataTypeJobData', 'TypeBasicJobDataTypeDeviceManifestMigration', 'TypeBasicJobDataTypeDeviceTemplateMigration' + Type TypeBasicJobData `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeviceTemplateMigrationJobData. +func (dtmjd DeviceTemplateMigrationJobData) MarshalJSON() ([]byte, error) { + dtmjd.Type = TypeBasicJobDataTypeDeviceTemplateMigration + objectMap := make(map[string]interface{}) + if dtmjd.Template != nil { + objectMap["template"] = dtmjd.Template + } + if dtmjd.Type != "" { + objectMap["type"] = dtmjd.Type + } + return json.Marshal(objectMap) +} + +// AsDeviceManifestMigrationJobData is the BasicJobData implementation for DeviceTemplateMigrationJobData. +func (dtmjd DeviceTemplateMigrationJobData) AsDeviceManifestMigrationJobData() (*DeviceManifestMigrationJobData, bool) { + return nil, false +} + +// AsDeviceTemplateMigrationJobData is the BasicJobData implementation for DeviceTemplateMigrationJobData. +func (dtmjd DeviceTemplateMigrationJobData) AsDeviceTemplateMigrationJobData() (*DeviceTemplateMigrationJobData, bool) { + return &dtmjd, true +} + +// AsJobData is the BasicJobData implementation for DeviceTemplateMigrationJobData. +func (dtmjd DeviceTemplateMigrationJobData) AsJobData() (*JobData, bool) { + return nil, false +} + +// AsBasicJobData is the BasicJobData implementation for DeviceTemplateMigrationJobData. +func (dtmjd DeviceTemplateMigrationJobData) AsBasicJobData() (BasicJobData, bool) { + return &dtmjd, true +} + +// EmailUser the email user definition. +type EmailUser struct { + // Email - Email address of the user. + Email *string `json:"email,omitempty"` + // ID - READ-ONLY; Unique ID of the user. + ID *string `json:"id,omitempty"` + // Type - Possible values include: 'TypeBasicUserTypeUser', 'TypeBasicUserTypeAdGroup', 'TypeBasicUserTypeEmail', 'TypeBasicUserTypeServicePrincipal' + Type TypeBasicUser `json:"type,omitempty"` + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` +} + +// MarshalJSON is the custom marshaler for EmailUser. +func (eu EmailUser) MarshalJSON() ([]byte, error) { + eu.Type = TypeBasicUserTypeEmail + objectMap := make(map[string]interface{}) + if eu.Email != nil { + objectMap["email"] = eu.Email + } + if eu.Type != "" { + objectMap["type"] = eu.Type + } + if eu.Roles != nil { + objectMap["roles"] = eu.Roles + } + return json.Marshal(objectMap) +} + +// AsADGroupUser is the BasicUser implementation for EmailUser. +func (eu EmailUser) AsADGroupUser() (*ADGroupUser, bool) { + return nil, false +} + +// AsEmailUser is the BasicUser implementation for EmailUser. +func (eu EmailUser) AsEmailUser() (*EmailUser, bool) { + return &eu, true +} + +// AsServicePrincipalUser is the BasicUser implementation for EmailUser. +func (eu EmailUser) AsServicePrincipalUser() (*ServicePrincipalUser, bool) { + return nil, false +} + +// AsUser is the BasicUser implementation for EmailUser. +func (eu EmailUser) AsUser() (*User, bool) { + return nil, false +} + +// AsBasicUser is the BasicUser implementation for EmailUser. +func (eu EmailUser) AsBasicUser() (BasicUser, bool) { + return &eu, true +} + +// Enrichment the enrichment definition for data export. +type Enrichment struct { + // Target - The device template or interface which defines the target capability for the enrichment. + Target *string `json:"target,omitempty"` + // Path - The path to the target capability within the device template or the system property to use. + Path *string `json:"path,omitempty"` + // Value - The raw value used for the enrichment. + Value interface{} `json:"value,omitempty"` +} + +// EnrollmentGroup the enrollment group definition. +type EnrollmentGroup struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the enrollment group. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the enrollment group. + DisplayName *string `json:"displayName,omitempty"` + // Enabled - Whether the devices using the group are allowed to connect to IoT Central. + Enabled *bool `json:"enabled,omitempty"` + // Type - Type of devices that connect through the group. Possible values include: 'EnrollmentGroupTypeIoTdevices', 'EnrollmentGroupTypeIoTEdgedevices' + Type EnrollmentGroupType `json:"type,omitempty"` + // Attestation - The attestation mechanism for the enrollment group. + Attestation BasicGroupAttestation `json:"attestation,omitempty"` + // Etag - ETag used to prevent conflict in enrollment group updates. + Etag *string `json:"etag,omitempty"` + // IDScope - READ-ONLY; ID scope for connecting to the IoT Central application. + IDScope *string `json:"idScope,omitempty"` +} + +// MarshalJSON is the custom marshaler for EnrollmentGroup. +func (eg EnrollmentGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if eg.DisplayName != nil { + objectMap["displayName"] = eg.DisplayName + } + if eg.Enabled != nil { + objectMap["enabled"] = eg.Enabled + } + if eg.Type != "" { + objectMap["type"] = eg.Type + } + objectMap["attestation"] = eg.Attestation + if eg.Etag != nil { + objectMap["etag"] = eg.Etag + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for EnrollmentGroup struct. +func (eg *EnrollmentGroup) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + eg.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + eg.DisplayName = &displayName + } + case "enabled": + if v != nil { + var enabled bool + err = json.Unmarshal(*v, &enabled) + if err != nil { + return err + } + eg.Enabled = &enabled + } + case "type": + if v != nil { + var typeVar EnrollmentGroupType + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + eg.Type = typeVar + } + case "attestation": + if v != nil { + attestation, err := unmarshalBasicGroupAttestation(*v) + if err != nil { + return err + } + eg.Attestation = attestation + } + case "etag": + if v != nil { + var etag string + err = json.Unmarshal(*v, &etag) + if err != nil { + return err + } + eg.Etag = &etag + } + case "idScope": + if v != nil { + var IDScope string + err = json.Unmarshal(*v, &IDScope) + if err != nil { + return err + } + eg.IDScope = &IDScope + } + } + } + + return nil +} + +// EnrollmentGroupCollection the paged results of enrollment groups. +type EnrollmentGroupCollection struct { + autorest.Response `json:"-"` + // Value - The collection of enrollment groups. + Value *[]EnrollmentGroup `json:"value,omitempty"` + // NextLink - URL to get the next page of enrollment groups. + NextLink *string `json:"nextLink,omitempty"` +} + +// EnrollmentGroupCollectionIterator provides access to a complete listing of EnrollmentGroup values. +type EnrollmentGroupCollectionIterator struct { + i int + page EnrollmentGroupCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *EnrollmentGroupCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *EnrollmentGroupCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter EnrollmentGroupCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter EnrollmentGroupCollectionIterator) Response() EnrollmentGroupCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter EnrollmentGroupCollectionIterator) Value() EnrollmentGroup { + if !iter.page.NotDone() { + return EnrollmentGroup{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the EnrollmentGroupCollectionIterator type. +func NewEnrollmentGroupCollectionIterator(page EnrollmentGroupCollectionPage) EnrollmentGroupCollectionIterator { + return EnrollmentGroupCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (egc EnrollmentGroupCollection) IsEmpty() bool { + return egc.Value == nil || len(*egc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (egc EnrollmentGroupCollection) hasNextLink() bool { + return egc.NextLink != nil && len(*egc.NextLink) != 0 +} + +// enrollmentGroupCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (egc EnrollmentGroupCollection) enrollmentGroupCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !egc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(egc.NextLink))) +} + +// EnrollmentGroupCollectionPage contains a page of EnrollmentGroup values. +type EnrollmentGroupCollectionPage struct { + fn func(context.Context, EnrollmentGroupCollection) (EnrollmentGroupCollection, error) + egc EnrollmentGroupCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *EnrollmentGroupCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EnrollmentGroupCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.egc) + if err != nil { + return err + } + page.egc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *EnrollmentGroupCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page EnrollmentGroupCollectionPage) NotDone() bool { + return !page.egc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page EnrollmentGroupCollectionPage) Response() EnrollmentGroupCollection { + return page.egc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page EnrollmentGroupCollectionPage) Values() []EnrollmentGroup { + if page.egc.IsEmpty() { + return nil + } + return *page.egc.Value +} + +// Creates a new instance of the EnrollmentGroupCollectionPage type. +func NewEnrollmentGroupCollectionPage(cur EnrollmentGroupCollection, getNextPage func(context.Context, EnrollmentGroupCollection) (EnrollmentGroupCollection, error)) EnrollmentGroupCollectionPage { + return EnrollmentGroupCollectionPage{ + fn: getNextPage, + egc: cur, + } +} + +// Error the response error definition. +type Error struct { + // Error - Error details for current request. + Error *ErrorDetails `json:"error,omitempty"` +} + +// ErrorDetails the detail information of the error. +type ErrorDetails struct { + // Code - Error code. + Code *string `json:"code,omitempty"` + // Message - Error message details. + Message *string `json:"message,omitempty"` + // RequestID - Correlation Id for current request. + RequestID *string `json:"requestId,omitempty"` + // Time - The time that error request failed. + Time *date.TimeRFC1123 `json:"time,omitempty"` +} + +// EventChartConfiguration configuration specifying options for a event chart tile. +type EventChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the event chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` +} + +// EventHistoryChartConfiguration configuration specifying options for a event history chart tile. +type EventHistoryChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the event history chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the event history chart + Format *TextFormatConfiguration `json:"format,omitempty"` +} + +// EventHubsV1Destination the event hub destination definition. +type EventHubsV1Destination struct { + Authorization BasicEventHubsV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) MarshalJSON() ([]byte, error) { + ehvd.Type = TypeBasicDestinationTypeEventhubsV1 + objectMap := make(map[string]interface{}) + objectMap["authorization"] = ehvd.Authorization + if ehvd.DisplayName != nil { + objectMap["displayName"] = ehvd.DisplayName + } + if ehvd.Type != "" { + objectMap["type"] = ehvd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return &ehvd, true +} + +// AsExportDestination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for EventHubsV1Destination. +func (ehvd EventHubsV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &ehvd, true +} + +// UnmarshalJSON is the custom unmarshaler for EventHubsV1Destination struct. +func (ehvd *EventHubsV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "authorization": + if v != nil { + authorization, err := unmarshalBasicEventHubsV1DestinationAuth(*v) + if err != nil { + return err + } + ehvd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ehvd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + ehvd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ehvd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + ehvd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + ehvd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + ehvd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicEventHubsV1DestinationAuth the authentication definition for event hub destination. +type BasicEventHubsV1DestinationAuth interface { + AsEventHubsV1DestinationConnectionStringAuth() (*EventHubsV1DestinationConnectionStringAuth, bool) + AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth() (*EventHubsV1DestinationSystemAssignedManagedIdentityAuth, bool) + AsEventHubsV1DestinationAuth() (*EventHubsV1DestinationAuth, bool) +} + +// EventHubsV1DestinationAuth the authentication definition for event hub destination. +type EventHubsV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth', 'TypeBasicEventHubsV1DestinationAuthTypeConnectionString', 'TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicEventHubsV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicEventHubsV1DestinationAuth(body []byte) (BasicEventHubsV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicEventHubsV1DestinationAuthTypeConnectionString): + var ehvdcsa EventHubsV1DestinationConnectionStringAuth + err := json.Unmarshal(body, &ehvdcsa) + return ehvdcsa, err + case string(TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity): + var ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth + err := json.Unmarshal(body, &ehvdsamia) + return ehvdsamia, err + default: + var ehvda EventHubsV1DestinationAuth + err := json.Unmarshal(body, &ehvda) + return ehvda, err + } +} +func unmarshalBasicEventHubsV1DestinationAuthArray(body []byte) ([]BasicEventHubsV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + ehvdaArray := make([]BasicEventHubsV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + ehvda, err := unmarshalBasicEventHubsV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + ehvdaArray[index] = ehvda + } + return ehvdaArray, nil +} + +// MarshalJSON is the custom marshaler for EventHubsV1DestinationAuth. +func (ehvda EventHubsV1DestinationAuth) MarshalJSON() ([]byte, error) { + ehvda.Type = TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth + objectMap := make(map[string]interface{}) + if ehvda.Type != "" { + objectMap["type"] = ehvda.Type + } + return json.Marshal(objectMap) +} + +// AsEventHubsV1DestinationConnectionStringAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationAuth. +func (ehvda EventHubsV1DestinationAuth) AsEventHubsV1DestinationConnectionStringAuth() (*EventHubsV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationAuth. +func (ehvda EventHubsV1DestinationAuth) AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth() (*EventHubsV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationAuth. +func (ehvda EventHubsV1DestinationAuth) AsEventHubsV1DestinationAuth() (*EventHubsV1DestinationAuth, bool) { + return &ehvda, true +} + +// AsBasicEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationAuth. +func (ehvda EventHubsV1DestinationAuth) AsBasicEventHubsV1DestinationAuth() (BasicEventHubsV1DestinationAuth, bool) { + return &ehvda, true +} + +// EventHubsV1DestinationConnectionStringAuth the authentication definition with connection string for +// event hub destination. +type EventHubsV1DestinationConnectionStringAuth struct { + // ConnectionString - The connection string for accessing the Event Hubs namespace, including the `EntityPath` of the event hub. + ConnectionString *string `json:"connectionString,omitempty"` + // Type - Possible values include: 'TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth', 'TypeBasicEventHubsV1DestinationAuthTypeConnectionString', 'TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicEventHubsV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for EventHubsV1DestinationConnectionStringAuth. +func (ehvdcsa EventHubsV1DestinationConnectionStringAuth) MarshalJSON() ([]byte, error) { + ehvdcsa.Type = TypeBasicEventHubsV1DestinationAuthTypeConnectionString + objectMap := make(map[string]interface{}) + if ehvdcsa.ConnectionString != nil { + objectMap["connectionString"] = ehvdcsa.ConnectionString + } + if ehvdcsa.Type != "" { + objectMap["type"] = ehvdcsa.Type + } + return json.Marshal(objectMap) +} + +// AsEventHubsV1DestinationConnectionStringAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationConnectionStringAuth. +func (ehvdcsa EventHubsV1DestinationConnectionStringAuth) AsEventHubsV1DestinationConnectionStringAuth() (*EventHubsV1DestinationConnectionStringAuth, bool) { + return &ehvdcsa, true +} + +// AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationConnectionStringAuth. +func (ehvdcsa EventHubsV1DestinationConnectionStringAuth) AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth() (*EventHubsV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationConnectionStringAuth. +func (ehvdcsa EventHubsV1DestinationConnectionStringAuth) AsEventHubsV1DestinationAuth() (*EventHubsV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationConnectionStringAuth. +func (ehvdcsa EventHubsV1DestinationConnectionStringAuth) AsBasicEventHubsV1DestinationAuth() (BasicEventHubsV1DestinationAuth, bool) { + return &ehvdcsa, true +} + +// EventHubsV1DestinationSystemAssignedManagedIdentityAuth the authentication definition with system +// assigned managed identity for event hub destination. +type EventHubsV1DestinationSystemAssignedManagedIdentityAuth struct { + // HostName - The host name of the Event Hubs namespace. + HostName *string `json:"hostName,omitempty"` + // EventHubName - The Event Hubs instance name. + EventHubName *string `json:"eventHubName,omitempty"` + // Type - Possible values include: 'TypeBasicEventHubsV1DestinationAuthTypeEventHubsV1DestinationAuth', 'TypeBasicEventHubsV1DestinationAuthTypeConnectionString', 'TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicEventHubsV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for EventHubsV1DestinationSystemAssignedManagedIdentityAuth. +func (ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth) MarshalJSON() ([]byte, error) { + ehvdsamia.Type = TypeBasicEventHubsV1DestinationAuthTypeSystemAssignedManagedIdentity + objectMap := make(map[string]interface{}) + if ehvdsamia.HostName != nil { + objectMap["hostName"] = ehvdsamia.HostName + } + if ehvdsamia.EventHubName != nil { + objectMap["eventHubName"] = ehvdsamia.EventHubName + } + if ehvdsamia.Type != "" { + objectMap["type"] = ehvdsamia.Type + } + return json.Marshal(objectMap) +} + +// AsEventHubsV1DestinationConnectionStringAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationSystemAssignedManagedIdentityAuth. +func (ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth) AsEventHubsV1DestinationConnectionStringAuth() (*EventHubsV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationSystemAssignedManagedIdentityAuth. +func (ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth) AsEventHubsV1DestinationSystemAssignedManagedIdentityAuth() (*EventHubsV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return &ehvdsamia, true +} + +// AsEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationSystemAssignedManagedIdentityAuth. +func (ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth) AsEventHubsV1DestinationAuth() (*EventHubsV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicEventHubsV1DestinationAuth is the BasicEventHubsV1DestinationAuth implementation for EventHubsV1DestinationSystemAssignedManagedIdentityAuth. +func (ehvdsamia EventHubsV1DestinationSystemAssignedManagedIdentityAuth) AsBasicEventHubsV1DestinationAuth() (BasicEventHubsV1DestinationAuth, bool) { + return &ehvdsamia, true +} + +// Export the data export definition. +type Export struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the export. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the export. + DisplayName *string `json:"displayName,omitempty"` + // Enabled - Toggle to start/stop an export from sending data. + Enabled *bool `json:"enabled,omitempty"` + // Source - The type of data to export. Possible values include: 'DestinationSourceTelemetry', 'DestinationSourceProperties', 'DestinationSourceDeviceLifecycle', 'DestinationSourceDeviceTemplateLifecycle', 'DestinationSourceDeviceConnectivity', 'DestinationSourceAudit' + Source DestinationSource `json:"source,omitempty"` + // Filter - Query defining which events from the source should be exported. + Filter *string `json:"filter,omitempty"` + // Enrichments - Additional pieces of information to include with each sent message. Data is represented as a set of key/value pairs, where the key is the name of the enrichment that will appear in the output message and the value identifies the data to send. + Enrichments map[string]*Enrichment `json:"enrichments"` + // Destinations - The list of destinations to which the export should send data. + Destinations *[]DestinationReference `json:"destinations,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for Export. +func (e Export) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if e.DisplayName != nil { + objectMap["displayName"] = e.DisplayName + } + if e.Enabled != nil { + objectMap["enabled"] = e.Enabled + } + if e.Source != "" { + objectMap["source"] = e.Source + } + if e.Filter != nil { + objectMap["filter"] = e.Filter + } + if e.Enrichments != nil { + objectMap["enrichments"] = e.Enrichments + } + if e.Destinations != nil { + objectMap["destinations"] = e.Destinations + } + return json.Marshal(objectMap) +} + +// ExportCollection the paged results of exports. +type ExportCollection struct { + autorest.Response `json:"-"` + // Value - The collection of exports. + Value *[]Export `json:"value,omitempty"` + // NextLink - URL to get the next page of exports. + NextLink *string `json:"nextLink,omitempty"` +} + +// ExportCollectionIterator provides access to a complete listing of Export values. +type ExportCollectionIterator struct { + i int + page ExportCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ExportCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ExportCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ExportCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ExportCollectionIterator) Response() ExportCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ExportCollectionIterator) Value() Export { + if !iter.page.NotDone() { + return Export{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ExportCollectionIterator type. +func NewExportCollectionIterator(page ExportCollectionPage) ExportCollectionIterator { + return ExportCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ec ExportCollection) IsEmpty() bool { + return ec.Value == nil || len(*ec.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (ec ExportCollection) hasNextLink() bool { + return ec.NextLink != nil && len(*ec.NextLink) != 0 +} + +// exportCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ec ExportCollection) exportCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !ec.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ec.NextLink))) +} + +// ExportCollectionPage contains a page of Export values. +type ExportCollectionPage struct { + fn func(context.Context, ExportCollection) (ExportCollection, error) + ec ExportCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ExportCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ExportCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.ec) + if err != nil { + return err + } + page.ec = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ExportCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ExportCollectionPage) NotDone() bool { + return !page.ec.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ExportCollectionPage) Response() ExportCollection { + return page.ec +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ExportCollectionPage) Values() []Export { + if page.ec.IsEmpty() { + return nil + } + return *page.ec.Value +} + +// Creates a new instance of the ExportCollectionPage type. +func NewExportCollectionPage(cur ExportCollection, getNextPage func(context.Context, ExportCollection) (ExportCollection, error)) ExportCollectionPage { + return ExportCollectionPage{ + fn: getNextPage, + ec: cur, + } +} + +// ExportDestination the export destination definition. +type ExportDestination struct { + // Transform - Query for transforming the message structure to a particular output. + Transform *string `json:"transform,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for ExportDestination. +func (ed ExportDestination) MarshalJSON() ([]byte, error) { + ed.Type = TypeBasicDestinationTypeExportDestination + objectMap := make(map[string]interface{}) + if ed.Transform != nil { + objectMap["transform"] = ed.Transform + } + if ed.DisplayName != nil { + objectMap["displayName"] = ed.DisplayName + } + if ed.Type != "" { + objectMap["type"] = ed.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsExportDestination() (*ExportDestination, bool) { + return &ed, true +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for ExportDestination. +func (ed ExportDestination) AsBasicDestination() (BasicDestination, bool) { + return &ed, true +} + +// ExternalContentTileConfiguration configuration specifying options for an external content tile. +type ExternalContentTileConfiguration struct { + // SourceURL - URL of the website to render inside the tile. Must be a valid HTTPS URL. + SourceURL *string `json:"sourceUrl,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) MarshalJSON() ([]byte, error) { + ectc.Type = TypeBasicTileConfigurationTypeExternalContent + objectMap := make(map[string]interface{}) + if ectc.SourceURL != nil { + objectMap["sourceUrl"] = ectc.SourceURL + } + if ectc.Type != "" { + objectMap["type"] = ectc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return &ectc, true +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for ExternalContentTileConfiguration. +func (ectc ExternalContentTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &ectc, true +} + +// FileUpload the file upload configuration definition. +type FileUpload struct { + autorest.Response `json:"-"` + // Account - The storage account name where to upload the file to + Account *string `json:"account,omitempty"` + // ConnectionString - The connection string used to configure the storage account + ConnectionString *string `json:"connectionString,omitempty"` + // Container - The name of the container inside the storage account + Container *string `json:"container,omitempty"` + // SasTTL - ISO 8601 duration standard, The amount of time the device’s request to upload a file is valid before it expires. + SasTTL *string `json:"sasTtl,omitempty"` + // State - READ-ONLY; The state of the file upload configuration. Possible values include: 'FileUploadStatePending', 'FileUploadStateUpdating', 'FileUploadStateDeleting', 'FileUploadStateSucceeded', 'FileUploadStateFailed' + State FileUploadState `json:"state,omitempty"` + // Etag - ETag used to prevent conflict with multiple uploads + Etag *string `json:"etag,omitempty"` + // ReadAccess - The flag indicate if user be able to access device uploaded files from IoT Central portal + ReadAccess *bool `json:"readAccess,omitempty"` +} + +// MarshalJSON is the custom marshaler for FileUpload. +func (fu FileUpload) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if fu.Account != nil { + objectMap["account"] = fu.Account + } + if fu.ConnectionString != nil { + objectMap["connectionString"] = fu.ConnectionString + } + if fu.Container != nil { + objectMap["container"] = fu.Container + } + if fu.SasTTL != nil { + objectMap["sasTtl"] = fu.SasTTL + } + if fu.Etag != nil { + objectMap["etag"] = fu.Etag + } + if fu.ReadAccess != nil { + objectMap["readAccess"] = fu.ReadAccess + } + return json.Marshal(objectMap) +} + +// BasicGroupAttestation the attestation definition for an enrollment group. +type BasicGroupAttestation interface { + AsGroupSymmetricKeyAttestation() (*GroupSymmetricKeyAttestation, bool) + AsGroupX509Attestation() (*GroupX509Attestation, bool) + AsGroupAttestation() (*GroupAttestation, bool) +} + +// GroupAttestation the attestation definition for an enrollment group. +type GroupAttestation struct { + // Type - Possible values include: 'TypeBasicGroupAttestationTypeGroupAttestation', 'TypeBasicGroupAttestationTypeSymmetricKey', 'TypeBasicGroupAttestationTypeX509' + Type TypeBasicGroupAttestation `json:"type,omitempty"` +} + +func unmarshalBasicGroupAttestation(body []byte) (BasicGroupAttestation, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicGroupAttestationTypeSymmetricKey): + var gska GroupSymmetricKeyAttestation + err := json.Unmarshal(body, &gska) + return gska, err + case string(TypeBasicGroupAttestationTypeX509): + var gxa GroupX509Attestation + err := json.Unmarshal(body, &gxa) + return gxa, err + default: + var ga GroupAttestation + err := json.Unmarshal(body, &ga) + return ga, err + } +} +func unmarshalBasicGroupAttestationArray(body []byte) ([]BasicGroupAttestation, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + gaArray := make([]BasicGroupAttestation, len(rawMessages)) + + for index, rawMessage := range rawMessages { + ga, err := unmarshalBasicGroupAttestation(*rawMessage) + if err != nil { + return nil, err + } + gaArray[index] = ga + } + return gaArray, nil +} + +// MarshalJSON is the custom marshaler for GroupAttestation. +func (ga GroupAttestation) MarshalJSON() ([]byte, error) { + ga.Type = TypeBasicGroupAttestationTypeGroupAttestation + objectMap := make(map[string]interface{}) + if ga.Type != "" { + objectMap["type"] = ga.Type + } + return json.Marshal(objectMap) +} + +// AsGroupSymmetricKeyAttestation is the BasicGroupAttestation implementation for GroupAttestation. +func (ga GroupAttestation) AsGroupSymmetricKeyAttestation() (*GroupSymmetricKeyAttestation, bool) { + return nil, false +} + +// AsGroupX509Attestation is the BasicGroupAttestation implementation for GroupAttestation. +func (ga GroupAttestation) AsGroupX509Attestation() (*GroupX509Attestation, bool) { + return nil, false +} + +// AsGroupAttestation is the BasicGroupAttestation implementation for GroupAttestation. +func (ga GroupAttestation) AsGroupAttestation() (*GroupAttestation, bool) { + return &ga, true +} + +// AsBasicGroupAttestation is the BasicGroupAttestation implementation for GroupAttestation. +func (ga GroupAttestation) AsBasicGroupAttestation() (BasicGroupAttestation, bool) { + return &ga, true +} + +// GroupSymmetricKeyAttestation the symmetric key attestation definition. +type GroupSymmetricKeyAttestation struct { + // SymmetricKey - The symmetric key credentials for this attestation. + SymmetricKey *SymmetricKey `json:"symmetricKey,omitempty"` + // Type - Possible values include: 'TypeBasicGroupAttestationTypeGroupAttestation', 'TypeBasicGroupAttestationTypeSymmetricKey', 'TypeBasicGroupAttestationTypeX509' + Type TypeBasicGroupAttestation `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for GroupSymmetricKeyAttestation. +func (gska GroupSymmetricKeyAttestation) MarshalJSON() ([]byte, error) { + gska.Type = TypeBasicGroupAttestationTypeSymmetricKey + objectMap := make(map[string]interface{}) + if gska.SymmetricKey != nil { + objectMap["symmetricKey"] = gska.SymmetricKey + } + if gska.Type != "" { + objectMap["type"] = gska.Type + } + return json.Marshal(objectMap) +} + +// AsGroupSymmetricKeyAttestation is the BasicGroupAttestation implementation for GroupSymmetricKeyAttestation. +func (gska GroupSymmetricKeyAttestation) AsGroupSymmetricKeyAttestation() (*GroupSymmetricKeyAttestation, bool) { + return &gska, true +} + +// AsGroupX509Attestation is the BasicGroupAttestation implementation for GroupSymmetricKeyAttestation. +func (gska GroupSymmetricKeyAttestation) AsGroupX509Attestation() (*GroupX509Attestation, bool) { + return nil, false +} + +// AsGroupAttestation is the BasicGroupAttestation implementation for GroupSymmetricKeyAttestation. +func (gska GroupSymmetricKeyAttestation) AsGroupAttestation() (*GroupAttestation, bool) { + return nil, false +} + +// AsBasicGroupAttestation is the BasicGroupAttestation implementation for GroupSymmetricKeyAttestation. +func (gska GroupSymmetricKeyAttestation) AsBasicGroupAttestation() (BasicGroupAttestation, bool) { + return &gska, true +} + +// GroupTileConfiguration configuration specifying a set of devices to display data for in a tile. +type GroupTileConfiguration struct { + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` +} + +// GroupX509Attestation the X509 attestation definition. +type GroupX509Attestation struct { + // X509 - The X.509 credentials for this attestation. + X509 *SigningX509 `json:"x509,omitempty"` + // Type - Possible values include: 'TypeBasicGroupAttestationTypeGroupAttestation', 'TypeBasicGroupAttestationTypeSymmetricKey', 'TypeBasicGroupAttestationTypeX509' + Type TypeBasicGroupAttestation `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for GroupX509Attestation. +func (gxa GroupX509Attestation) MarshalJSON() ([]byte, error) { + gxa.Type = TypeBasicGroupAttestationTypeX509 + objectMap := make(map[string]interface{}) + if gxa.X509 != nil { + objectMap["x509"] = gxa.X509 + } + if gxa.Type != "" { + objectMap["type"] = gxa.Type + } + return json.Marshal(objectMap) +} + +// AsGroupSymmetricKeyAttestation is the BasicGroupAttestation implementation for GroupX509Attestation. +func (gxa GroupX509Attestation) AsGroupSymmetricKeyAttestation() (*GroupSymmetricKeyAttestation, bool) { + return nil, false +} + +// AsGroupX509Attestation is the BasicGroupAttestation implementation for GroupX509Attestation. +func (gxa GroupX509Attestation) AsGroupX509Attestation() (*GroupX509Attestation, bool) { + return &gxa, true +} + +// AsGroupAttestation is the BasicGroupAttestation implementation for GroupX509Attestation. +func (gxa GroupX509Attestation) AsGroupAttestation() (*GroupAttestation, bool) { + return nil, false +} + +// AsBasicGroupAttestation is the BasicGroupAttestation implementation for GroupX509Attestation. +func (gxa GroupX509Attestation) AsBasicGroupAttestation() (BasicGroupAttestation, bool) { + return &gxa, true +} + +// HeatMapConfiguration configuration specifying options for a heat map tile. +type HeatMapConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the heatmap chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the heatmap chart + Format *ChartFormatConfiguration `json:"format,omitempty"` +} + +// ImageTileConfiguration configuration specifying options for an image tile +type ImageTileConfiguration struct { + // Image - The asset id of the image to display + Image *string `json:"image,omitempty"` + // Href - The URL the tile links to when clicked + Href *string `json:"href,omitempty"` + // Format - Format options for the image tile + Format *ImageTileConfigurationFormat `json:"format,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ImageTileConfiguration. +func (itc ImageTileConfiguration) MarshalJSON() ([]byte, error) { + itc.Type = TypeBasicTileConfigurationTypeImage + objectMap := make(map[string]interface{}) + if itc.Image != nil { + objectMap["image"] = itc.Image + } + if itc.Href != nil { + objectMap["href"] = itc.Href + } + if itc.Format != nil { + objectMap["format"] = itc.Format + } + if itc.Type != "" { + objectMap["type"] = itc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return &itc, true +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for ImageTileConfiguration. +func (itc ImageTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &itc, true +} + +// ImageTileConfigurationFormat format options for the image tile +type ImageTileConfigurationFormat struct { + // BackgroundColor - The background color to show behind the image + BackgroundColor *string `json:"backgroundColor,omitempty"` + // FitImage - Whether to stretch the image to fit the aspect ratio of the tile or display in the image's native aspect ratio + FitImage *bool `json:"fitImage,omitempty"` + // TextColor - The color of the text in the tile + TextColor *string `json:"textColor,omitempty"` + // TextSize - Size of the test in the tile + TextSize *float64 `json:"textSize,omitempty"` + // TextSizeUnit - The unit of size for the text in the tile. Possible values include: 'ImageTileTextUnitsPixels' + TextSizeUnit ImageTileTextUnits `json:"textSizeUnit,omitempty"` + // ShowTitle - Whether or not to show the display name text on the tile + ShowTitle *bool `json:"showTitle,omitempty"` +} + +// Job the job definition. +type Job struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the job. + ID *string `json:"id,omitempty"` + // ScheduledJobID - Id of the scheduled job definition that created this job. + ScheduledJobID *string `json:"scheduledJobId,omitempty"` + // DisplayName - Display name of the job. + DisplayName *string `json:"displayName,omitempty"` + // Description - Detailed description of the job. + Description *string `json:"description,omitempty"` + // Group - The ID of the device group on which to execute the job. + Group *string `json:"group,omitempty"` + // Batch - The batching configuration for the job. + Batch *JobBatch `json:"batch,omitempty"` + // CancellationThreshold - The cancellation threshold for the job. + CancellationThreshold *JobCancellationThreshold `json:"cancellationThreshold,omitempty"` + // Data - The capabilities being updated by the job and the values with which they are being updated. + Data *[]BasicJobData `json:"data,omitempty"` + // Start - READ-ONLY; The start time of the job + Start *date.Time `json:"start,omitempty"` + // End - READ-ONLY; The end time of the job + End *date.Time `json:"end,omitempty"` + // Progress - READ-ONLY; The progress statistics of the job. + Progress *JobProgress `json:"progress,omitempty"` + // Status - READ-ONLY; Indicates whether the job is starting, running, etc. + Status *string `json:"status,omitempty"` + // Organizations - List of organizations of the job, only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` +} + +// MarshalJSON is the custom marshaler for Job. +func (j Job) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if j.ScheduledJobID != nil { + objectMap["scheduledJobId"] = j.ScheduledJobID + } + if j.DisplayName != nil { + objectMap["displayName"] = j.DisplayName + } + if j.Description != nil { + objectMap["description"] = j.Description + } + if j.Group != nil { + objectMap["group"] = j.Group + } + if j.Batch != nil { + objectMap["batch"] = j.Batch + } + if j.CancellationThreshold != nil { + objectMap["cancellationThreshold"] = j.CancellationThreshold + } + if j.Data != nil { + objectMap["data"] = j.Data + } + if j.Organizations != nil { + objectMap["organizations"] = j.Organizations + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Job struct. +func (j *Job) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + j.ID = &ID + } + case "scheduledJobId": + if v != nil { + var scheduledJobID string + err = json.Unmarshal(*v, &scheduledJobID) + if err != nil { + return err + } + j.ScheduledJobID = &scheduledJobID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + j.DisplayName = &displayName + } + case "description": + if v != nil { + var description string + err = json.Unmarshal(*v, &description) + if err != nil { + return err + } + j.Description = &description + } + case "group": + if v != nil { + var group string + err = json.Unmarshal(*v, &group) + if err != nil { + return err + } + j.Group = &group + } + case "batch": + if v != nil { + var batch JobBatch + err = json.Unmarshal(*v, &batch) + if err != nil { + return err + } + j.Batch = &batch + } + case "cancellationThreshold": + if v != nil { + var cancellationThreshold JobCancellationThreshold + err = json.Unmarshal(*v, &cancellationThreshold) + if err != nil { + return err + } + j.CancellationThreshold = &cancellationThreshold + } + case "data": + if v != nil { + data, err := unmarshalBasicJobDataArray(*v) + if err != nil { + return err + } + j.Data = &data + } + case "start": + if v != nil { + var start date.Time + err = json.Unmarshal(*v, &start) + if err != nil { + return err + } + j.Start = &start + } + case "end": + if v != nil { + var end date.Time + err = json.Unmarshal(*v, &end) + if err != nil { + return err + } + j.End = &end + } + case "progress": + if v != nil { + var progress JobProgress + err = json.Unmarshal(*v, &progress) + if err != nil { + return err + } + j.Progress = &progress + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + j.Status = &status + } + case "organizations": + if v != nil { + var organizations []string + err = json.Unmarshal(*v, &organizations) + if err != nil { + return err + } + j.Organizations = &organizations + } + } + } + + return nil +} + +// JobBatch the job batch definition. +type JobBatch struct { + // Type - Whether batching is done on a specified number of devices or a percentage of the total devices. Possible values include: 'JobBatchTypeNumber', 'JobBatchTypePercentage' + Type JobBatchType `json:"type,omitempty"` + // Value - The number or percentage of devices on which batching is done. + Value *float64 `json:"value,omitempty"` +} + +// JobCancellationThreshold the job cancellation threshold definition. +type JobCancellationThreshold struct { + // Type - Whether the cancellation threshold is per a specified number of devices or a percentage of the total devices. Possible values include: 'JobCancellationThresholdTypeNumber', 'JobCancellationThresholdTypePercentage' + Type JobCancellationThresholdType `json:"type,omitempty"` + // Value - The number or percentage of devices on which the cancellation threshold is applied. + Value *float64 `json:"value,omitempty"` + // Batch - Whether the cancellation threshold applies per-batch or to the overall job. + Batch *bool `json:"batch,omitempty"` +} + +// JobCollection the paged results of jobs. +type JobCollection struct { + autorest.Response `json:"-"` + // Value - The collection of jobs. + Value *[]Job `json:"value,omitempty"` + // NextLink - URL to get the next page of jobs. + NextLink *string `json:"nextLink,omitempty"` +} + +// JobCollectionIterator provides access to a complete listing of Job values. +type JobCollectionIterator struct { + i int + page JobCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *JobCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *JobCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter JobCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter JobCollectionIterator) Response() JobCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter JobCollectionIterator) Value() Job { + if !iter.page.NotDone() { + return Job{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the JobCollectionIterator type. +func NewJobCollectionIterator(page JobCollectionPage) JobCollectionIterator { + return JobCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (jc JobCollection) IsEmpty() bool { + return jc.Value == nil || len(*jc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (jc JobCollection) hasNextLink() bool { + return jc.NextLink != nil && len(*jc.NextLink) != 0 +} + +// jobCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (jc JobCollection) jobCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !jc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(jc.NextLink))) +} + +// JobCollectionPage contains a page of Job values. +type JobCollectionPage struct { + fn func(context.Context, JobCollection) (JobCollection, error) + jc JobCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *JobCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.jc) + if err != nil { + return err + } + page.jc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *JobCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page JobCollectionPage) NotDone() bool { + return !page.jc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page JobCollectionPage) Response() JobCollection { + return page.jc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page JobCollectionPage) Values() []Job { + if page.jc.IsEmpty() { + return nil + } + return *page.jc.Value +} + +// Creates a new instance of the JobCollectionPage type. +func NewJobCollectionPage(cur JobCollection, getNextPage func(context.Context, JobCollection) (JobCollection, error)) JobCollectionPage { + return JobCollectionPage{ + fn: getNextPage, + jc: cur, + } +} + +// BasicJobData the job data definition. +type BasicJobData interface { + AsDeviceManifestMigrationJobData() (*DeviceManifestMigrationJobData, bool) + AsDeviceTemplateMigrationJobData() (*DeviceTemplateMigrationJobData, bool) + AsJobData() (*JobData, bool) +} + +// JobData the job data definition. +type JobData struct { + // Type - Possible values include: 'TypeBasicJobDataTypeJobData', 'TypeBasicJobDataTypeDeviceManifestMigration', 'TypeBasicJobDataTypeDeviceTemplateMigration' + Type TypeBasicJobData `json:"type,omitempty"` +} + +func unmarshalBasicJobData(body []byte) (BasicJobData, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicJobDataTypeDeviceManifestMigration): + var dmmjd DeviceManifestMigrationJobData + err := json.Unmarshal(body, &dmmjd) + return dmmjd, err + case string(TypeBasicJobDataTypeDeviceTemplateMigration): + var dtmjd DeviceTemplateMigrationJobData + err := json.Unmarshal(body, &dtmjd) + return dtmjd, err + default: + var jd JobData + err := json.Unmarshal(body, &jd) + return jd, err + } +} +func unmarshalBasicJobDataArray(body []byte) ([]BasicJobData, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + jdArray := make([]BasicJobData, len(rawMessages)) + + for index, rawMessage := range rawMessages { + jd, err := unmarshalBasicJobData(*rawMessage) + if err != nil { + return nil, err + } + jdArray[index] = jd + } + return jdArray, nil +} + +// MarshalJSON is the custom marshaler for JobData. +func (jd JobData) MarshalJSON() ([]byte, error) { + jd.Type = TypeBasicJobDataTypeJobData + objectMap := make(map[string]interface{}) + if jd.Type != "" { + objectMap["type"] = jd.Type + } + return json.Marshal(objectMap) +} + +// AsDeviceManifestMigrationJobData is the BasicJobData implementation for JobData. +func (jd JobData) AsDeviceManifestMigrationJobData() (*DeviceManifestMigrationJobData, bool) { + return nil, false +} + +// AsDeviceTemplateMigrationJobData is the BasicJobData implementation for JobData. +func (jd JobData) AsDeviceTemplateMigrationJobData() (*DeviceTemplateMigrationJobData, bool) { + return nil, false +} + +// AsJobData is the BasicJobData implementation for JobData. +func (jd JobData) AsJobData() (*JobData, bool) { + return &jd, true +} + +// AsBasicJobData is the BasicJobData implementation for JobData. +func (jd JobData) AsBasicJobData() (BasicJobData, bool) { + return &jd, true +} + +// JobDeviceStatus the job device status definition. +type JobDeviceStatus struct { + // ID - READ-ONLY; ID of the device whose job status is being provided. + ID *string `json:"id,omitempty"` + // Status - READ-ONLY; Indicates whether the job is starting, running, etc. for the given device. + Status *string `json:"status,omitempty"` +} + +// MarshalJSON is the custom marshaler for JobDeviceStatus. +func (jds JobDeviceStatus) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// JobDeviceStatusCollection the paged results of job device statuses. +type JobDeviceStatusCollection struct { + autorest.Response `json:"-"` + // Value - The collection of job device statuses. + Value *[]JobDeviceStatus `json:"value,omitempty"` + // NextLink - URL to get the next page of job device statuses. + NextLink *string `json:"nextLink,omitempty"` +} + +// JobDeviceStatusCollectionIterator provides access to a complete listing of JobDeviceStatus values. +type JobDeviceStatusCollectionIterator struct { + i int + page JobDeviceStatusCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *JobDeviceStatusCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobDeviceStatusCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *JobDeviceStatusCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter JobDeviceStatusCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter JobDeviceStatusCollectionIterator) Response() JobDeviceStatusCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter JobDeviceStatusCollectionIterator) Value() JobDeviceStatus { + if !iter.page.NotDone() { + return JobDeviceStatus{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the JobDeviceStatusCollectionIterator type. +func NewJobDeviceStatusCollectionIterator(page JobDeviceStatusCollectionPage) JobDeviceStatusCollectionIterator { + return JobDeviceStatusCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (jdsc JobDeviceStatusCollection) IsEmpty() bool { + return jdsc.Value == nil || len(*jdsc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (jdsc JobDeviceStatusCollection) hasNextLink() bool { + return jdsc.NextLink != nil && len(*jdsc.NextLink) != 0 +} + +// jobDeviceStatusCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (jdsc JobDeviceStatusCollection) jobDeviceStatusCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !jdsc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(jdsc.NextLink))) +} + +// JobDeviceStatusCollectionPage contains a page of JobDeviceStatus values. +type JobDeviceStatusCollectionPage struct { + fn func(context.Context, JobDeviceStatusCollection) (JobDeviceStatusCollection, error) + jdsc JobDeviceStatusCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *JobDeviceStatusCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/JobDeviceStatusCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.jdsc) + if err != nil { + return err + } + page.jdsc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *JobDeviceStatusCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page JobDeviceStatusCollectionPage) NotDone() bool { + return !page.jdsc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page JobDeviceStatusCollectionPage) Response() JobDeviceStatusCollection { + return page.jdsc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page JobDeviceStatusCollectionPage) Values() []JobDeviceStatus { + if page.jdsc.IsEmpty() { + return nil + } + return *page.jdsc.Value +} + +// Creates a new instance of the JobDeviceStatusCollectionPage type. +func NewJobDeviceStatusCollectionPage(cur JobDeviceStatusCollection, getNextPage func(context.Context, JobDeviceStatusCollection) (JobDeviceStatusCollection, error)) JobDeviceStatusCollectionPage { + return JobDeviceStatusCollectionPage{ + fn: getNextPage, + jdsc: cur, + } +} + +// JobProgress progress summary for a scheduled job. +type JobProgress struct { + // Total - The total number of entities targeted by the job. + Total *int32 `json:"total,omitempty"` + // Pending - The number of entities for which the job is not yet running. + Pending *int32 `json:"pending,omitempty"` + // Completed - The number of entities for which the job has completed. + Completed *int32 `json:"completed,omitempty"` + // Failed - The number of entities for which the job has failed. + Failed *int32 `json:"failed,omitempty"` +} + +// JobSchedule the schedule definition of job. +type JobSchedule struct { + // Recurrence - The recurrence of the scheduled job. If not provided, the job will run once at the specified start time. Possible values include: 'JobRecurrenceDaily', 'JobRecurrenceWeekly', 'JobRecurrenceMonthly' + Recurrence JobRecurrence `json:"recurrence,omitempty"` + // Start - The start time for the scheduled job + Start *date.Time `json:"start,omitempty"` + // End - The specification of when to end the scheduled job. + End BasicJobScheduleEnd `json:"end,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for JobSchedule struct. +func (js *JobSchedule) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "recurrence": + if v != nil { + var recurrence JobRecurrence + err = json.Unmarshal(*v, &recurrence) + if err != nil { + return err + } + js.Recurrence = recurrence + } + case "start": + if v != nil { + var start date.Time + err = json.Unmarshal(*v, &start) + if err != nil { + return err + } + js.Start = &start + } + case "end": + if v != nil { + end, err := unmarshalBasicJobScheduleEnd(*v) + if err != nil { + return err + } + js.End = end + } + } + } + + return nil +} + +// BasicJobScheduleEnd the end definition of job schedule. +type BasicJobScheduleEnd interface { + AsDateJobScheduleEnd() (*DateJobScheduleEnd, bool) + AsOccurrencesJobScheduleEnd() (*OccurrencesJobScheduleEnd, bool) + AsJobScheduleEnd() (*JobScheduleEnd, bool) +} + +// JobScheduleEnd the end definition of job schedule. +type JobScheduleEnd struct { + // Type - Possible values include: 'TypeBasicJobScheduleEndTypeJobScheduleEnd', 'TypeBasicJobScheduleEndTypeDate', 'TypeBasicJobScheduleEndTypeOccurrences' + Type TypeBasicJobScheduleEnd `json:"type,omitempty"` +} + +func unmarshalBasicJobScheduleEnd(body []byte) (BasicJobScheduleEnd, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicJobScheduleEndTypeDate): + var djse DateJobScheduleEnd + err := json.Unmarshal(body, &djse) + return djse, err + case string(TypeBasicJobScheduleEndTypeOccurrences): + var ojse OccurrencesJobScheduleEnd + err := json.Unmarshal(body, &ojse) + return ojse, err + default: + var jse JobScheduleEnd + err := json.Unmarshal(body, &jse) + return jse, err + } +} +func unmarshalBasicJobScheduleEndArray(body []byte) ([]BasicJobScheduleEnd, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + jseArray := make([]BasicJobScheduleEnd, len(rawMessages)) + + for index, rawMessage := range rawMessages { + jse, err := unmarshalBasicJobScheduleEnd(*rawMessage) + if err != nil { + return nil, err + } + jseArray[index] = jse + } + return jseArray, nil +} + +// MarshalJSON is the custom marshaler for JobScheduleEnd. +func (jse JobScheduleEnd) MarshalJSON() ([]byte, error) { + jse.Type = TypeBasicJobScheduleEndTypeJobScheduleEnd + objectMap := make(map[string]interface{}) + if jse.Type != "" { + objectMap["type"] = jse.Type + } + return json.Marshal(objectMap) +} + +// AsDateJobScheduleEnd is the BasicJobScheduleEnd implementation for JobScheduleEnd. +func (jse JobScheduleEnd) AsDateJobScheduleEnd() (*DateJobScheduleEnd, bool) { + return nil, false +} + +// AsOccurrencesJobScheduleEnd is the BasicJobScheduleEnd implementation for JobScheduleEnd. +func (jse JobScheduleEnd) AsOccurrencesJobScheduleEnd() (*OccurrencesJobScheduleEnd, bool) { + return nil, false +} + +// AsJobScheduleEnd is the BasicJobScheduleEnd implementation for JobScheduleEnd. +func (jse JobScheduleEnd) AsJobScheduleEnd() (*JobScheduleEnd, bool) { + return &jse, true +} + +// AsBasicJobScheduleEnd is the BasicJobScheduleEnd implementation for JobScheduleEnd. +func (jse JobScheduleEnd) AsBasicJobScheduleEnd() (BasicJobScheduleEnd, bool) { + return &jse, true +} + +// KpiTileConfiguration configuration specifying options for KPI tile. +type KpiTileConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the KPI chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the KPI tile + Format *TextFormatConfiguration `json:"format,omitempty"` +} + +// LabelTileConfiguration configuration specifying options for a label tile +type LabelTileConfiguration struct { + // Text - The text to display in the tile + Text *string `json:"text,omitempty"` + // TextSize - The font size of the text being displayed + TextSize *float64 `json:"textSize,omitempty"` + // TextSizeUnit - Possible values include: 'TileTextSizeUnitPoints' + TextSizeUnit TileTextSizeUnit `json:"textSizeUnit,omitempty"` + // WordWrap - Whether to wrap the text being displayed + WordWrap *bool `json:"wordWrap,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for LabelTileConfiguration. +func (ltc LabelTileConfiguration) MarshalJSON() ([]byte, error) { + ltc.Type = TypeBasicTileConfigurationTypeLabel + objectMap := make(map[string]interface{}) + if ltc.Text != nil { + objectMap["text"] = ltc.Text + } + if ltc.TextSize != nil { + objectMap["textSize"] = ltc.TextSize + } + if ltc.TextSizeUnit != "" { + objectMap["textSizeUnit"] = ltc.TextSizeUnit + } + if ltc.WordWrap != nil { + objectMap["wordWrap"] = ltc.WordWrap + } + if ltc.Type != "" { + objectMap["type"] = ltc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return <c, true +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for LabelTileConfiguration. +func (ltc LabelTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return <c, true +} + +// LineChartConfiguration configuration specifying options for a line chart tile. +type LineChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the line chart + QueryRange BasicQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the line chart + Format *ChartFormatConfiguration `json:"format,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for LineChartConfiguration struct. +func (lcc *LineChartConfiguration) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + lcc.Type = &typeVar + } + case "group": + if v != nil { + var group string + err = json.Unmarshal(*v, &group) + if err != nil { + return err + } + lcc.Group = &group + } + case "devices": + if v != nil { + var devices []string + err = json.Unmarshal(*v, &devices) + if err != nil { + return err + } + lcc.Devices = &devices + } + case "capabilities": + if v != nil { + var capabilities []TileCapability + err = json.Unmarshal(*v, &capabilities) + if err != nil { + return err + } + lcc.Capabilities = &capabilities + } + case "queryRange": + if v != nil { + queryRange, err := unmarshalBasicQueryRangeConfiguration(*v) + if err != nil { + return err + } + lcc.QueryRange = queryRange + } + case "format": + if v != nil { + var formatVar ChartFormatConfiguration + err = json.Unmarshal(*v, &formatVar) + if err != nil { + return err + } + lcc.Format = &formatVar + } + } + } + + return nil +} + +// LkvTileConfiguration configuration specifying options for a last known value tile. +type LkvTileConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // ShowTrend - Show the trend between the last known value and the value before that + ShowTrend *bool `json:"showTrend,omitempty"` + // Format - The format configuration of the LKV tile + Format *TextFormatConfiguration `json:"format,omitempty"` +} + +// MapFormatConfiguration configuration specifying formatting options for a map tile. +type MapFormatConfiguration struct { + // ZoomLevel - The zoom level of the map + ZoomLevel *int32 `json:"zoomLevel,omitempty"` +} + +// MapPropertyConfiguration configuration specifying options for a map property tile. +type MapPropertyConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // ZoomLevel - The zoom level of the map + ZoomLevel *float64 `json:"zoomLevel,omitempty"` +} + +// MapTelemetryConfiguration configuration specifying options for a map telemetry tile. +type MapTelemetryConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // ZoomLevel - The zoom level of the map + ZoomLevel *float64 `json:"zoomLevel,omitempty"` +} + +// MapTileConfiguration configuration specifying options for a map tile. +type MapTileConfiguration struct { + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // ZoomLevel - The zoom level of the map + ZoomLevel *float64 `json:"zoomLevel,omitempty"` +} + +// MarkdownTileConfiguration configuration specifying options for a markdown tile. +type MarkdownTileConfiguration struct { + // Href - Link to visit when tile is clicked + Href *string `json:"href,omitempty"` + // Description - Markdown string to render inside the tile + Description *string `json:"description,omitempty"` + // Image - Base64 encoded + Image *string `json:"image,omitempty"` + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) MarshalJSON() ([]byte, error) { + mtc.Type = TypeBasicTileConfigurationTypeMarkdown + objectMap := make(map[string]interface{}) + if mtc.Href != nil { + objectMap["href"] = mtc.Href + } + if mtc.Description != nil { + objectMap["description"] = mtc.Description + } + if mtc.Image != nil { + objectMap["image"] = mtc.Image + } + if mtc.Type != "" { + objectMap["type"] = mtc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return &mtc, true +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return nil, false +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for MarkdownTileConfiguration. +func (mtc MarkdownTileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &mtc, true +} + +// OccurrencesJobScheduleEnd the occurences based end definition of job schedule. +type OccurrencesJobScheduleEnd struct { + // Occurrences - The number of occurrences after which to end the scheduled job. + Occurrences *int32 `json:"occurrences,omitempty"` + // Type - Possible values include: 'TypeBasicJobScheduleEndTypeJobScheduleEnd', 'TypeBasicJobScheduleEndTypeDate', 'TypeBasicJobScheduleEndTypeOccurrences' + Type TypeBasicJobScheduleEnd `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for OccurrencesJobScheduleEnd. +func (ojse OccurrencesJobScheduleEnd) MarshalJSON() ([]byte, error) { + ojse.Type = TypeBasicJobScheduleEndTypeOccurrences + objectMap := make(map[string]interface{}) + if ojse.Occurrences != nil { + objectMap["occurrences"] = ojse.Occurrences + } + if ojse.Type != "" { + objectMap["type"] = ojse.Type + } + return json.Marshal(objectMap) +} + +// AsDateJobScheduleEnd is the BasicJobScheduleEnd implementation for OccurrencesJobScheduleEnd. +func (ojse OccurrencesJobScheduleEnd) AsDateJobScheduleEnd() (*DateJobScheduleEnd, bool) { + return nil, false +} + +// AsOccurrencesJobScheduleEnd is the BasicJobScheduleEnd implementation for OccurrencesJobScheduleEnd. +func (ojse OccurrencesJobScheduleEnd) AsOccurrencesJobScheduleEnd() (*OccurrencesJobScheduleEnd, bool) { + return &ojse, true +} + +// AsJobScheduleEnd is the BasicJobScheduleEnd implementation for OccurrencesJobScheduleEnd. +func (ojse OccurrencesJobScheduleEnd) AsJobScheduleEnd() (*JobScheduleEnd, bool) { + return nil, false +} + +// AsBasicJobScheduleEnd is the BasicJobScheduleEnd implementation for OccurrencesJobScheduleEnd. +func (ojse OccurrencesJobScheduleEnd) AsBasicJobScheduleEnd() (BasicJobScheduleEnd, bool) { + return &ojse, true +} + +// Organization the organization definition. +type Organization struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the organization. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the organization. + DisplayName *string `json:"displayName,omitempty"` + // Parent - ID of the parent of the organization. + Parent *string `json:"parent,omitempty"` +} + +// MarshalJSON is the custom marshaler for Organization. +func (o Organization) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if o.DisplayName != nil { + objectMap["displayName"] = o.DisplayName + } + if o.Parent != nil { + objectMap["parent"] = o.Parent + } + return json.Marshal(objectMap) +} + +// OrganizationCollection the paged results of organizations. +type OrganizationCollection struct { + autorest.Response `json:"-"` + // Value - The collection of organizations. + Value *[]Organization `json:"value,omitempty"` + // NextLink - URL to get the next page of organizations. + NextLink *string `json:"nextLink,omitempty"` +} + +// OrganizationCollectionIterator provides access to a complete listing of Organization values. +type OrganizationCollectionIterator struct { + i int + page OrganizationCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OrganizationCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *OrganizationCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OrganizationCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OrganizationCollectionIterator) Response() OrganizationCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OrganizationCollectionIterator) Value() Organization { + if !iter.page.NotDone() { + return Organization{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the OrganizationCollectionIterator type. +func NewOrganizationCollectionIterator(page OrganizationCollectionPage) OrganizationCollectionIterator { + return OrganizationCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (oc OrganizationCollection) IsEmpty() bool { + return oc.Value == nil || len(*oc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (oc OrganizationCollection) hasNextLink() bool { + return oc.NextLink != nil && len(*oc.NextLink) != 0 +} + +// organizationCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (oc OrganizationCollection) organizationCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !oc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(oc.NextLink))) +} + +// OrganizationCollectionPage contains a page of Organization values. +type OrganizationCollectionPage struct { + fn func(context.Context, OrganizationCollection) (OrganizationCollection, error) + oc OrganizationCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OrganizationCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.oc) + if err != nil { + return err + } + page.oc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *OrganizationCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OrganizationCollectionPage) NotDone() bool { + return !page.oc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OrganizationCollectionPage) Response() OrganizationCollection { + return page.oc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OrganizationCollectionPage) Values() []Organization { + if page.oc.IsEmpty() { + return nil + } + return *page.oc.Value +} + +// Creates a new instance of the OrganizationCollectionPage type. +func NewOrganizationCollectionPage(cur OrganizationCollection, getNextPage func(context.Context, OrganizationCollection) (OrganizationCollection, error)) OrganizationCollectionPage { + return OrganizationCollectionPage{ + fn: getNextPage, + oc: cur, + } +} + +// Permission the permission definition. +type Permission struct { + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` +} + +// PieChartConfiguration configuration specifying options for a pie chart tile. +type PieChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the pie chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the pie chart + Format *ChartFormatConfiguration `json:"format,omitempty"` +} + +// PropertyJobData the property job data definition. +type PropertyJobData struct { + // Type - Type of the job data. + Type *string `json:"type,omitempty"` + // Target - The device template which defines the target capability for the job. + Target *string `json:"target,omitempty"` + // Path - The path to the target capability within the device template. + Path *string `json:"path,omitempty"` + // Value - The value used to update the target capability, if any. + Value interface{} `json:"value,omitempty"` +} + +// PropertyTileConfiguration configuration specifying options for a property tile. +type PropertyTileConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // Format - The format configuration of the property tile + Format *TextFormatConfiguration `json:"format,omitempty"` +} + +// BasicQueryRangeConfiguration configuration specifying how much data to return for a tile. +type BasicQueryRangeConfiguration interface { + AsTimeQueryRangeConfiguration() (*TimeQueryRangeConfiguration, bool) + AsCountQueryRangeConfiguration() (*CountQueryRangeConfiguration, bool) + AsQueryRangeConfiguration() (*QueryRangeConfiguration, bool) +} + +// QueryRangeConfiguration configuration specifying how much data to return for a tile. +type QueryRangeConfiguration struct { + // Type - Possible values include: 'TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration', 'TypeBasicQueryRangeConfigurationTypeTime', 'TypeBasicQueryRangeConfigurationTypeCount' + Type TypeBasicQueryRangeConfiguration `json:"type,omitempty"` +} + +func unmarshalBasicQueryRangeConfiguration(body []byte) (BasicQueryRangeConfiguration, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicQueryRangeConfigurationTypeTime): + var tqrc TimeQueryRangeConfiguration + err := json.Unmarshal(body, &tqrc) + return tqrc, err + case string(TypeBasicQueryRangeConfigurationTypeCount): + var cqrc CountQueryRangeConfiguration + err := json.Unmarshal(body, &cqrc) + return cqrc, err + default: + var qrc QueryRangeConfiguration + err := json.Unmarshal(body, &qrc) + return qrc, err + } +} +func unmarshalBasicQueryRangeConfigurationArray(body []byte) ([]BasicQueryRangeConfiguration, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + qrcArray := make([]BasicQueryRangeConfiguration, len(rawMessages)) + + for index, rawMessage := range rawMessages { + qrc, err := unmarshalBasicQueryRangeConfiguration(*rawMessage) + if err != nil { + return nil, err + } + qrcArray[index] = qrc + } + return qrcArray, nil +} + +// MarshalJSON is the custom marshaler for QueryRangeConfiguration. +func (qrc QueryRangeConfiguration) MarshalJSON() ([]byte, error) { + qrc.Type = TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration + objectMap := make(map[string]interface{}) + if qrc.Type != "" { + objectMap["type"] = qrc.Type + } + return json.Marshal(objectMap) +} + +// AsTimeQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for QueryRangeConfiguration. +func (qrc QueryRangeConfiguration) AsTimeQueryRangeConfiguration() (*TimeQueryRangeConfiguration, bool) { + return nil, false +} + +// AsCountQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for QueryRangeConfiguration. +func (qrc QueryRangeConfiguration) AsCountQueryRangeConfiguration() (*CountQueryRangeConfiguration, bool) { + return nil, false +} + +// AsQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for QueryRangeConfiguration. +func (qrc QueryRangeConfiguration) AsQueryRangeConfiguration() (*QueryRangeConfiguration, bool) { + return &qrc, true +} + +// AsBasicQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for QueryRangeConfiguration. +func (qrc QueryRangeConfiguration) AsBasicQueryRangeConfiguration() (BasicQueryRangeConfiguration, bool) { + return &qrc, true +} + +// QueryRequest the query request payload definition. +type QueryRequest struct { + // Query - Query to be executed. + Query *string `json:"query,omitempty"` +} + +// QueryResponse the query response payload definition. +type QueryResponse struct { + autorest.Response `json:"-"` + Results *[]interface{} `json:"results,omitempty"` +} + +// Role the role definition. +type Role struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the role. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the role. + DisplayName *string `json:"displayName,omitempty"` +} + +// MarshalJSON is the custom marshaler for Role. +func (r Role) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.DisplayName != nil { + objectMap["displayName"] = r.DisplayName + } + return json.Marshal(objectMap) +} + +// RoleAssignment the role assignment definition. +type RoleAssignment struct { + // Role - ID of the role for this role assignment. + Role *string `json:"role,omitempty"` + // Organization - ID of the organization for this role assignment. + Organization *string `json:"organization,omitempty"` +} + +// RoleCollection the paged results of roles. +type RoleCollection struct { + autorest.Response `json:"-"` + // Value - The collection of roles. + Value *[]Role `json:"value,omitempty"` + // NextLink - URL to get the next page of roles. + NextLink *string `json:"nextLink,omitempty"` +} + +// RoleCollectionIterator provides access to a complete listing of Role values. +type RoleCollectionIterator struct { + i int + page RoleCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *RoleCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RoleCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *RoleCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter RoleCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter RoleCollectionIterator) Response() RoleCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter RoleCollectionIterator) Value() Role { + if !iter.page.NotDone() { + return Role{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the RoleCollectionIterator type. +func NewRoleCollectionIterator(page RoleCollectionPage) RoleCollectionIterator { + return RoleCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (rc RoleCollection) IsEmpty() bool { + return rc.Value == nil || len(*rc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (rc RoleCollection) hasNextLink() bool { + return rc.NextLink != nil && len(*rc.NextLink) != 0 +} + +// roleCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rc RoleCollection) roleCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !rc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rc.NextLink))) +} + +// RoleCollectionPage contains a page of Role values. +type RoleCollectionPage struct { + fn func(context.Context, RoleCollection) (RoleCollection, error) + rc RoleCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *RoleCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RoleCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.rc) + if err != nil { + return err + } + page.rc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *RoleCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page RoleCollectionPage) NotDone() bool { + return !page.rc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page RoleCollectionPage) Response() RoleCollection { + return page.rc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page RoleCollectionPage) Values() []Role { + if page.rc.IsEmpty() { + return nil + } + return *page.rc.Value +} + +// Creates a new instance of the RoleCollectionPage type. +func NewRoleCollectionPage(cur RoleCollection, getNextPage func(context.Context, RoleCollection) (RoleCollection, error)) RoleCollectionPage { + return RoleCollectionPage{ + fn: getNextPage, + rc: cur, + } +} + +// ScheduledJob the scheduled job definition. +type ScheduledJob struct { + autorest.Response `json:"-"` + // Etag - ETag used to prevent conflict in scheduled job updates. + Etag *string `json:"etag,omitempty"` + // ID - READ-ONLY; Unique ID of the scheduled job. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the scheduled job. + DisplayName *string `json:"displayName,omitempty"` + // Description - Detailed description of the scheduled job. + Description *string `json:"description,omitempty"` + // Group - The ID of the device group on which to execute the scheduled job. + Group *string `json:"group,omitempty"` + // Batch - The batching configuration for the scheduled job. + Batch *JobBatch `json:"batch,omitempty"` + // CancellationThreshold - The cancellation threshold for the scheduled job. + CancellationThreshold *JobCancellationThreshold `json:"cancellationThreshold,omitempty"` + // Data - Data related to the operation being performed by this job. All entries must be of the same type. + Data *[]BasicJobData `json:"data,omitempty"` + // Organizations - List of organizations of the job, only one organization is supported today, multiple organizations will be supported soon. + Organizations *[]string `json:"organizations,omitempty"` + // Schedule - The schedule at which to execute the job. + Schedule *JobSchedule `json:"schedule,omitempty"` + // Enabled - Whether the scheduled job is enabled. + Enabled *bool `json:"enabled,omitempty"` + // Completed - READ-ONLY; Whether the scheduled job has completed. + Completed *bool `json:"completed,omitempty"` +} + +// MarshalJSON is the custom marshaler for ScheduledJob. +func (sj ScheduledJob) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sj.Etag != nil { + objectMap["etag"] = sj.Etag + } + if sj.DisplayName != nil { + objectMap["displayName"] = sj.DisplayName + } + if sj.Description != nil { + objectMap["description"] = sj.Description + } + if sj.Group != nil { + objectMap["group"] = sj.Group + } + if sj.Batch != nil { + objectMap["batch"] = sj.Batch + } + if sj.CancellationThreshold != nil { + objectMap["cancellationThreshold"] = sj.CancellationThreshold + } + if sj.Data != nil { + objectMap["data"] = sj.Data + } + if sj.Organizations != nil { + objectMap["organizations"] = sj.Organizations + } + if sj.Schedule != nil { + objectMap["schedule"] = sj.Schedule + } + if sj.Enabled != nil { + objectMap["enabled"] = sj.Enabled + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ScheduledJob struct. +func (sj *ScheduledJob) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "etag": + if v != nil { + var etag string + err = json.Unmarshal(*v, &etag) + if err != nil { + return err + } + sj.Etag = &etag + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + sj.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + sj.DisplayName = &displayName + } + case "description": + if v != nil { + var description string + err = json.Unmarshal(*v, &description) + if err != nil { + return err + } + sj.Description = &description + } + case "group": + if v != nil { + var group string + err = json.Unmarshal(*v, &group) + if err != nil { + return err + } + sj.Group = &group + } + case "batch": + if v != nil { + var batch JobBatch + err = json.Unmarshal(*v, &batch) + if err != nil { + return err + } + sj.Batch = &batch + } + case "cancellationThreshold": + if v != nil { + var cancellationThreshold JobCancellationThreshold + err = json.Unmarshal(*v, &cancellationThreshold) + if err != nil { + return err + } + sj.CancellationThreshold = &cancellationThreshold + } + case "data": + if v != nil { + data, err := unmarshalBasicJobDataArray(*v) + if err != nil { + return err + } + sj.Data = &data + } + case "organizations": + if v != nil { + var organizations []string + err = json.Unmarshal(*v, &organizations) + if err != nil { + return err + } + sj.Organizations = &organizations + } + case "schedule": + if v != nil { + var schedule JobSchedule + err = json.Unmarshal(*v, &schedule) + if err != nil { + return err + } + sj.Schedule = &schedule + } + case "enabled": + if v != nil { + var enabled bool + err = json.Unmarshal(*v, &enabled) + if err != nil { + return err + } + sj.Enabled = &enabled + } + case "completed": + if v != nil { + var completed bool + err = json.Unmarshal(*v, &completed) + if err != nil { + return err + } + sj.Completed = &completed + } + } + } + + return nil +} + +// ScheduledJobCollection the paged results of scheduled job definitions. +type ScheduledJobCollection struct { + autorest.Response `json:"-"` + // Value - The collection of scheduled jobs. + Value *[]ScheduledJob `json:"value,omitempty"` + // NextLink - URL to get the next page of scheduled jobs. + NextLink *string `json:"nextLink,omitempty"` +} + +// ScheduledJobCollectionIterator provides access to a complete listing of ScheduledJob values. +type ScheduledJobCollectionIterator struct { + i int + page ScheduledJobCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ScheduledJobCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ScheduledJobCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ScheduledJobCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ScheduledJobCollectionIterator) Response() ScheduledJobCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ScheduledJobCollectionIterator) Value() ScheduledJob { + if !iter.page.NotDone() { + return ScheduledJob{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ScheduledJobCollectionIterator type. +func NewScheduledJobCollectionIterator(page ScheduledJobCollectionPage) ScheduledJobCollectionIterator { + return ScheduledJobCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (sjc ScheduledJobCollection) IsEmpty() bool { + return sjc.Value == nil || len(*sjc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (sjc ScheduledJobCollection) hasNextLink() bool { + return sjc.NextLink != nil && len(*sjc.NextLink) != 0 +} + +// scheduledJobCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (sjc ScheduledJobCollection) scheduledJobCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !sjc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(sjc.NextLink))) +} + +// ScheduledJobCollectionPage contains a page of ScheduledJob values. +type ScheduledJobCollectionPage struct { + fn func(context.Context, ScheduledJobCollection) (ScheduledJobCollection, error) + sjc ScheduledJobCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ScheduledJobCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.sjc) + if err != nil { + return err + } + page.sjc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ScheduledJobCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ScheduledJobCollectionPage) NotDone() bool { + return !page.sjc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ScheduledJobCollectionPage) Response() ScheduledJobCollection { + return page.sjc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ScheduledJobCollectionPage) Values() []ScheduledJob { + if page.sjc.IsEmpty() { + return nil + } + return *page.sjc.Value +} + +// Creates a new instance of the ScheduledJobCollectionPage type. +func NewScheduledJobCollectionPage(cur ScheduledJobCollection, getNextPage func(context.Context, ScheduledJobCollection) (ScheduledJobCollection, error)) ScheduledJobCollectionPage { + return ScheduledJobCollectionPage{ + fn: getNextPage, + sjc: cur, + } +} + +// ServiceBusQueueV1Destination the service bus queue destination definition. +type ServiceBusQueueV1Destination struct { + Authorization BasicServiceBusQueueV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) MarshalJSON() ([]byte, error) { + sbqvd.Type = TypeBasicDestinationTypeServicebusqueueV1 + objectMap := make(map[string]interface{}) + objectMap["authorization"] = sbqvd.Authorization + if sbqvd.DisplayName != nil { + objectMap["displayName"] = sbqvd.DisplayName + } + if sbqvd.Type != "" { + objectMap["type"] = sbqvd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return &sbqvd, true +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for ServiceBusQueueV1Destination. +func (sbqvd ServiceBusQueueV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &sbqvd, true +} + +// UnmarshalJSON is the custom unmarshaler for ServiceBusQueueV1Destination struct. +func (sbqvd *ServiceBusQueueV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "authorization": + if v != nil { + authorization, err := unmarshalBasicServiceBusQueueV1DestinationAuth(*v) + if err != nil { + return err + } + sbqvd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + sbqvd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + sbqvd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + sbqvd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + sbqvd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + sbqvd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + sbqvd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicServiceBusQueueV1DestinationAuth the authentication definition for service bus queue definition. +type BasicServiceBusQueueV1DestinationAuth interface { + AsServiceBusQueueV1DestinationConnectionStringAuth() (*ServiceBusQueueV1DestinationConnectionStringAuth, bool) + AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth, bool) + AsServiceBusQueueV1DestinationAuth() (*ServiceBusQueueV1DestinationAuth, bool) +} + +// ServiceBusQueueV1DestinationAuth the authentication definition for service bus queue definition. +type ServiceBusQueueV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth', 'TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusQueueV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicServiceBusQueueV1DestinationAuth(body []byte) (BasicServiceBusQueueV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString): + var sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth + err := json.Unmarshal(body, &sbqvdcsa) + return sbqvdcsa, err + case string(TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity): + var sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth + err := json.Unmarshal(body, &sbqvdsamia) + return sbqvdsamia, err + default: + var sbqvda ServiceBusQueueV1DestinationAuth + err := json.Unmarshal(body, &sbqvda) + return sbqvda, err + } +} +func unmarshalBasicServiceBusQueueV1DestinationAuthArray(body []byte) ([]BasicServiceBusQueueV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + sbqvdaArray := make([]BasicServiceBusQueueV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + sbqvda, err := unmarshalBasicServiceBusQueueV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + sbqvdaArray[index] = sbqvda + } + return sbqvdaArray, nil +} + +// MarshalJSON is the custom marshaler for ServiceBusQueueV1DestinationAuth. +func (sbqvda ServiceBusQueueV1DestinationAuth) MarshalJSON() ([]byte, error) { + sbqvda.Type = TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth + objectMap := make(map[string]interface{}) + if sbqvda.Type != "" { + objectMap["type"] = sbqvda.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusQueueV1DestinationConnectionStringAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationAuth. +func (sbqvda ServiceBusQueueV1DestinationAuth) AsServiceBusQueueV1DestinationConnectionStringAuth() (*ServiceBusQueueV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationAuth. +func (sbqvda ServiceBusQueueV1DestinationAuth) AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationAuth. +func (sbqvda ServiceBusQueueV1DestinationAuth) AsServiceBusQueueV1DestinationAuth() (*ServiceBusQueueV1DestinationAuth, bool) { + return &sbqvda, true +} + +// AsBasicServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationAuth. +func (sbqvda ServiceBusQueueV1DestinationAuth) AsBasicServiceBusQueueV1DestinationAuth() (BasicServiceBusQueueV1DestinationAuth, bool) { + return &sbqvda, true +} + +// ServiceBusQueueV1DestinationConnectionStringAuth the authentication definition with connection string +// for service bus queue definition. +type ServiceBusQueueV1DestinationConnectionStringAuth struct { + // ConnectionString - The connection string for accessing the Service Bus namespace, including the `EntityPath` of the queue. + ConnectionString *string `json:"connectionString,omitempty"` + // Type - Possible values include: 'TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth', 'TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusQueueV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusQueueV1DestinationConnectionStringAuth. +func (sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth) MarshalJSON() ([]byte, error) { + sbqvdcsa.Type = TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString + objectMap := make(map[string]interface{}) + if sbqvdcsa.ConnectionString != nil { + objectMap["connectionString"] = sbqvdcsa.ConnectionString + } + if sbqvdcsa.Type != "" { + objectMap["type"] = sbqvdcsa.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusQueueV1DestinationConnectionStringAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationConnectionStringAuth. +func (sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth) AsServiceBusQueueV1DestinationConnectionStringAuth() (*ServiceBusQueueV1DestinationConnectionStringAuth, bool) { + return &sbqvdcsa, true +} + +// AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationConnectionStringAuth. +func (sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth) AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationConnectionStringAuth. +func (sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth) AsServiceBusQueueV1DestinationAuth() (*ServiceBusQueueV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationConnectionStringAuth. +func (sbqvdcsa ServiceBusQueueV1DestinationConnectionStringAuth) AsBasicServiceBusQueueV1DestinationAuth() (BasicServiceBusQueueV1DestinationAuth, bool) { + return &sbqvdcsa, true +} + +// ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth the authentication definition with system +// assigned managed identity for service bus queue definition. +type ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth struct { + // HostName - The host name of the Service Bus namespace. + HostName *string `json:"hostName,omitempty"` + // QueueName - The Service Bus queue name. + QueueName *string `json:"queueName,omitempty"` + // Type - Possible values include: 'TypeBasicServiceBusQueueV1DestinationAuthTypeServiceBusQueueV1DestinationAuth', 'TypeBasicServiceBusQueueV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusQueueV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth. +func (sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth) MarshalJSON() ([]byte, error) { + sbqvdsamia.Type = TypeBasicServiceBusQueueV1DestinationAuthTypeSystemAssignedManagedIdentity + objectMap := make(map[string]interface{}) + if sbqvdsamia.HostName != nil { + objectMap["hostName"] = sbqvdsamia.HostName + } + if sbqvdsamia.QueueName != nil { + objectMap["queueName"] = sbqvdsamia.QueueName + } + if sbqvdsamia.Type != "" { + objectMap["type"] = sbqvdsamia.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusQueueV1DestinationConnectionStringAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth. +func (sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusQueueV1DestinationConnectionStringAuth() (*ServiceBusQueueV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth. +func (sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return &sbqvdsamia, true +} + +// AsServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth. +func (sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusQueueV1DestinationAuth() (*ServiceBusQueueV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicServiceBusQueueV1DestinationAuth is the BasicServiceBusQueueV1DestinationAuth implementation for ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth. +func (sbqvdsamia ServiceBusQueueV1DestinationSystemAssignedManagedIdentityAuth) AsBasicServiceBusQueueV1DestinationAuth() (BasicServiceBusQueueV1DestinationAuth, bool) { + return &sbqvdsamia, true +} + +// ServiceBusTopicV1Destination the service bus topic destination definition. +type ServiceBusTopicV1Destination struct { + Authorization BasicServiceBusTopicV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) MarshalJSON() ([]byte, error) { + sbtvd.Type = TypeBasicDestinationTypeServicebustopicV1 + objectMap := make(map[string]interface{}) + objectMap["authorization"] = sbtvd.Authorization + if sbtvd.DisplayName != nil { + objectMap["displayName"] = sbtvd.DisplayName + } + if sbtvd.Type != "" { + objectMap["type"] = sbtvd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return &sbtvd, true +} + +// AsWebhookV1Destination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return nil, false +} + +// AsDestination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for ServiceBusTopicV1Destination. +func (sbtvd ServiceBusTopicV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &sbtvd, true +} + +// UnmarshalJSON is the custom unmarshaler for ServiceBusTopicV1Destination struct. +func (sbtvd *ServiceBusTopicV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "authorization": + if v != nil { + authorization, err := unmarshalBasicServiceBusTopicV1DestinationAuth(*v) + if err != nil { + return err + } + sbtvd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + sbtvd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + sbtvd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + sbtvd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + sbtvd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + sbtvd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + sbtvd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicServiceBusTopicV1DestinationAuth the authentication definition for service bus topic destination. +type BasicServiceBusTopicV1DestinationAuth interface { + AsServiceBusTopicV1DestinationConnectionStringAuth() (*ServiceBusTopicV1DestinationConnectionStringAuth, bool) + AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth, bool) + AsServiceBusTopicV1DestinationAuth() (*ServiceBusTopicV1DestinationAuth, bool) +} + +// ServiceBusTopicV1DestinationAuth the authentication definition for service bus topic destination. +type ServiceBusTopicV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth', 'TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusTopicV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicServiceBusTopicV1DestinationAuth(body []byte) (BasicServiceBusTopicV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString): + var sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth + err := json.Unmarshal(body, &sbtvdcsa) + return sbtvdcsa, err + case string(TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity): + var sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth + err := json.Unmarshal(body, &sbtvdsamia) + return sbtvdsamia, err + default: + var sbtvda ServiceBusTopicV1DestinationAuth + err := json.Unmarshal(body, &sbtvda) + return sbtvda, err + } +} +func unmarshalBasicServiceBusTopicV1DestinationAuthArray(body []byte) ([]BasicServiceBusTopicV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + sbtvdaArray := make([]BasicServiceBusTopicV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + sbtvda, err := unmarshalBasicServiceBusTopicV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + sbtvdaArray[index] = sbtvda + } + return sbtvdaArray, nil +} + +// MarshalJSON is the custom marshaler for ServiceBusTopicV1DestinationAuth. +func (sbtvda ServiceBusTopicV1DestinationAuth) MarshalJSON() ([]byte, error) { + sbtvda.Type = TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth + objectMap := make(map[string]interface{}) + if sbtvda.Type != "" { + objectMap["type"] = sbtvda.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusTopicV1DestinationConnectionStringAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationAuth. +func (sbtvda ServiceBusTopicV1DestinationAuth) AsServiceBusTopicV1DestinationConnectionStringAuth() (*ServiceBusTopicV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationAuth. +func (sbtvda ServiceBusTopicV1DestinationAuth) AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationAuth. +func (sbtvda ServiceBusTopicV1DestinationAuth) AsServiceBusTopicV1DestinationAuth() (*ServiceBusTopicV1DestinationAuth, bool) { + return &sbtvda, true +} + +// AsBasicServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationAuth. +func (sbtvda ServiceBusTopicV1DestinationAuth) AsBasicServiceBusTopicV1DestinationAuth() (BasicServiceBusTopicV1DestinationAuth, bool) { + return &sbtvda, true +} + +// ServiceBusTopicV1DestinationConnectionStringAuth the authentication definition with connection string +// for service bus topic destination. +type ServiceBusTopicV1DestinationConnectionStringAuth struct { + // ConnectionString - The connection string for accessing the Service Bus namespace, including the `EntityPath` of the topic. + ConnectionString *string `json:"connectionString,omitempty"` + // Type - Possible values include: 'TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth', 'TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusTopicV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusTopicV1DestinationConnectionStringAuth. +func (sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth) MarshalJSON() ([]byte, error) { + sbtvdcsa.Type = TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString + objectMap := make(map[string]interface{}) + if sbtvdcsa.ConnectionString != nil { + objectMap["connectionString"] = sbtvdcsa.ConnectionString + } + if sbtvdcsa.Type != "" { + objectMap["type"] = sbtvdcsa.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusTopicV1DestinationConnectionStringAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationConnectionStringAuth. +func (sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth) AsServiceBusTopicV1DestinationConnectionStringAuth() (*ServiceBusTopicV1DestinationConnectionStringAuth, bool) { + return &sbtvdcsa, true +} + +// AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationConnectionStringAuth. +func (sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth) AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return nil, false +} + +// AsServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationConnectionStringAuth. +func (sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth) AsServiceBusTopicV1DestinationAuth() (*ServiceBusTopicV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationConnectionStringAuth. +func (sbtvdcsa ServiceBusTopicV1DestinationConnectionStringAuth) AsBasicServiceBusTopicV1DestinationAuth() (BasicServiceBusTopicV1DestinationAuth, bool) { + return &sbtvdcsa, true +} + +// ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth the authentication definition with system +// assigned managed identity for service bus topic destination. +type ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth struct { + // HostName - The host name of the Service Bus namespace. + HostName *string `json:"hostName,omitempty"` + // TopicName - The Service Bus topic name. + TopicName *string `json:"topicName,omitempty"` + // Type - Possible values include: 'TypeBasicServiceBusTopicV1DestinationAuthTypeServiceBusTopicV1DestinationAuth', 'TypeBasicServiceBusTopicV1DestinationAuthTypeConnectionString', 'TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity' + Type TypeBasicServiceBusTopicV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth. +func (sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth) MarshalJSON() ([]byte, error) { + sbtvdsamia.Type = TypeBasicServiceBusTopicV1DestinationAuthTypeSystemAssignedManagedIdentity + objectMap := make(map[string]interface{}) + if sbtvdsamia.HostName != nil { + objectMap["hostName"] = sbtvdsamia.HostName + } + if sbtvdsamia.TopicName != nil { + objectMap["topicName"] = sbtvdsamia.TopicName + } + if sbtvdsamia.Type != "" { + objectMap["type"] = sbtvdsamia.Type + } + return json.Marshal(objectMap) +} + +// AsServiceBusTopicV1DestinationConnectionStringAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth. +func (sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusTopicV1DestinationConnectionStringAuth() (*ServiceBusTopicV1DestinationConnectionStringAuth, bool) { + return nil, false +} + +// AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth. +func (sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth() (*ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth, bool) { + return &sbtvdsamia, true +} + +// AsServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth. +func (sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth) AsServiceBusTopicV1DestinationAuth() (*ServiceBusTopicV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicServiceBusTopicV1DestinationAuth is the BasicServiceBusTopicV1DestinationAuth implementation for ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth. +func (sbtvdsamia ServiceBusTopicV1DestinationSystemAssignedManagedIdentityAuth) AsBasicServiceBusTopicV1DestinationAuth() (BasicServiceBusTopicV1DestinationAuth, bool) { + return &sbtvdsamia, true +} + +// ServicePrincipalUser the service principal user definition. +type ServicePrincipalUser struct { + // TenantID - The AAD tenant ID of the service principal. + TenantID *string `json:"tenantId,omitempty"` + // ObjectID - The AAD object ID of the service principal. + ObjectID *string `json:"objectId,omitempty"` + // ID - READ-ONLY; Unique ID of the user. + ID *string `json:"id,omitempty"` + // Type - Possible values include: 'TypeBasicUserTypeUser', 'TypeBasicUserTypeAdGroup', 'TypeBasicUserTypeEmail', 'TypeBasicUserTypeServicePrincipal' + Type TypeBasicUser `json:"type,omitempty"` + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServicePrincipalUser. +func (spu ServicePrincipalUser) MarshalJSON() ([]byte, error) { + spu.Type = TypeBasicUserTypeServicePrincipal + objectMap := make(map[string]interface{}) + if spu.TenantID != nil { + objectMap["tenantId"] = spu.TenantID + } + if spu.ObjectID != nil { + objectMap["objectId"] = spu.ObjectID + } + if spu.Type != "" { + objectMap["type"] = spu.Type + } + if spu.Roles != nil { + objectMap["roles"] = spu.Roles + } + return json.Marshal(objectMap) +} + +// AsADGroupUser is the BasicUser implementation for ServicePrincipalUser. +func (spu ServicePrincipalUser) AsADGroupUser() (*ADGroupUser, bool) { + return nil, false +} + +// AsEmailUser is the BasicUser implementation for ServicePrincipalUser. +func (spu ServicePrincipalUser) AsEmailUser() (*EmailUser, bool) { + return nil, false +} + +// AsServicePrincipalUser is the BasicUser implementation for ServicePrincipalUser. +func (spu ServicePrincipalUser) AsServicePrincipalUser() (*ServicePrincipalUser, bool) { + return &spu, true +} + +// AsUser is the BasicUser implementation for ServicePrincipalUser. +func (spu ServicePrincipalUser) AsUser() (*User, bool) { + return nil, false +} + +// AsBasicUser is the BasicUser implementation for ServicePrincipalUser. +func (spu ServicePrincipalUser) AsBasicUser() (BasicUser, bool) { + return &spu, true +} + +// SetSetObject ... +type SetSetObject struct { + autorest.Response `json:"-"` + Value map[string]interface{} `json:"value"` +} + +// MarshalJSON is the custom marshaler for SetSetObject. +func (sso SetSetObject) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sso.Value != nil { + objectMap["value"] = sso.Value + } + return json.Marshal(objectMap) +} + +// SigningX509 the X509 definition. +type SigningX509 struct { + // SigningCertificates - The X.509 signing certificates for this credential. + SigningCertificates *SigningX509Certificates `json:"signingCertificates,omitempty"` +} + +// SigningX509Certificate the X509 certificate definition. +type SigningX509Certificate struct { + autorest.Response `json:"-"` + // Verified - Whether the certificate has been verified. + Verified *bool `json:"verified,omitempty"` + // Certificate - The string representation of this certificate. + Certificate *string `json:"certificate,omitempty"` + // Info - READ-ONLY; Information about this certificate. + Info *X509CertificateInfo `json:"info,omitempty"` + // Etag - ETag used to prevent conflict across multiple updates + Etag *string `json:"etag,omitempty"` +} + +// MarshalJSON is the custom marshaler for SigningX509Certificate. +func (sxc SigningX509Certificate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sxc.Verified != nil { + objectMap["verified"] = sxc.Verified + } + if sxc.Certificate != nil { + objectMap["certificate"] = sxc.Certificate + } + if sxc.Etag != nil { + objectMap["etag"] = sxc.Etag + } + return json.Marshal(objectMap) +} + +// SigningX509Certificates the X509 certificates definition. +type SigningX509Certificates struct { + // Primary - The primary X.509 certificate for this credential. + Primary *SigningX509Certificate `json:"primary,omitempty"` + // Secondary - The secondary X.509 certificate for this credential. + Secondary *SigningX509Certificate `json:"secondary,omitempty"` +} + +// StateChartConfiguration configuration specifying options for a state chart tile. +type StateChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the state chart + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` +} + +// StateHistoryChartConfiguration configuration specifying options for a state history chart tile. +type StateHistoryChartConfiguration struct { + // Type - The type of widget the tile renders + Type *string `json:"type,omitempty"` + // Group - The ID of the device group to display + Group *string `json:"group,omitempty"` + // Devices - The list of associated devices to display + Devices *[]string `json:"devices,omitempty"` + Capabilities *[]TileCapability `json:"capabilities,omitempty"` + // QueryRange - The query range configuration of the state history chart tile + QueryRange *TimeQueryRangeConfiguration `json:"queryRange,omitempty"` + // Format - The format configuration of the state history chart + Format *TextFormatConfiguration `json:"format,omitempty"` +} + +// SymmetricKey the symmetric key definition. +type SymmetricKey struct { + // PrimaryKey - The primary key for this credential. + PrimaryKey *string `json:"primaryKey,omitempty"` + // SecondaryKey - The secondary key for this credential. + SecondaryKey *string `json:"secondaryKey,omitempty"` +} + +// SymmetricKeyAttestation the symmetric key attestation definition. +type SymmetricKeyAttestation struct { + // SymmetricKey - The symmetric key credentials for this attestation. + SymmetricKey *SymmetricKey `json:"symmetricKey,omitempty"` + // Type - Possible values include: 'TypeAttestation', 'TypeSymmetricKey', 'TypeTpm', 'TypeX509' + Type Type `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) MarshalJSON() ([]byte, error) { + ska.Type = TypeSymmetricKey + objectMap := make(map[string]interface{}) + if ska.SymmetricKey != nil { + objectMap["symmetricKey"] = ska.SymmetricKey + } + if ska.Type != "" { + objectMap["type"] = ska.Type + } + return json.Marshal(objectMap) +} + +// AsSymmetricKeyAttestation is the BasicAttestation implementation for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) AsSymmetricKeyAttestation() (*SymmetricKeyAttestation, bool) { + return &ska, true +} + +// AsTpmAttestation is the BasicAttestation implementation for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) AsTpmAttestation() (*TpmAttestation, bool) { + return nil, false +} + +// AsX509Attestation is the BasicAttestation implementation for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) AsX509Attestation() (*X509Attestation, bool) { + return nil, false +} + +// AsAttestation is the BasicAttestation implementation for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) AsAttestation() (*Attestation, bool) { + return nil, false +} + +// AsBasicAttestation is the BasicAttestation implementation for SymmetricKeyAttestation. +func (ska SymmetricKeyAttestation) AsBasicAttestation() (BasicAttestation, bool) { + return &ska, true +} + +// TextFormatConfiguration configuration specifying formatting options for a text based tile. +type TextFormatConfiguration struct { + // AbbreviateValue - Whether to abbreviate the value + AbbreviateValue *bool `json:"abbreviateValue,omitempty"` + // DecimalPlaces - The number of decimal places being displayed + DecimalPlaces *int32 `json:"decimalPlaces,omitempty"` + // TextSize - The font size of the text being displayed + TextSize *float64 `json:"textSize,omitempty"` + // Unit - Possible values include: 'TileTextSizeUnitPoints' + Unit TileTextSizeUnit `json:"unit,omitempty"` + // WordWrap - Whether to wrap the text being displayed + WordWrap *bool `json:"wordWrap,omitempty"` +} + +// Tile configuration specifying tile object, including the layout, display name and configuration. +type Tile struct { + // ID - READ-ONLY; Unique ID of the tile. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the tile. + DisplayName *string `json:"displayName,omitempty"` + // Configuration - The configuration for the tile + Configuration BasicTileConfiguration `json:"configuration,omitempty"` + // Height - Height of the tile + Height *float64 `json:"height,omitempty"` + // Width - Width of the tile + Width *float64 `json:"width,omitempty"` + // X - Horizontal position of the tile + X *float64 `json:"x,omitempty"` + // Y - Vertical position of the tile + Y *float64 `json:"y,omitempty"` +} + +// MarshalJSON is the custom marshaler for Tile. +func (t Tile) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if t.DisplayName != nil { + objectMap["displayName"] = t.DisplayName + } + objectMap["configuration"] = t.Configuration + if t.Height != nil { + objectMap["height"] = t.Height + } + if t.Width != nil { + objectMap["width"] = t.Width + } + if t.X != nil { + objectMap["x"] = t.X + } + if t.Y != nil { + objectMap["y"] = t.Y + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Tile struct. +func (t *Tile) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + t.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + t.DisplayName = &displayName + } + case "configuration": + if v != nil { + configuration, err := unmarshalBasicTileConfiguration(*v) + if err != nil { + return err + } + t.Configuration = configuration + } + case "height": + if v != nil { + var height float64 + err = json.Unmarshal(*v, &height) + if err != nil { + return err + } + t.Height = &height + } + case "width": + if v != nil { + var width float64 + err = json.Unmarshal(*v, &width) + if err != nil { + return err + } + t.Width = &width + } + case "x": + if v != nil { + var x float64 + err = json.Unmarshal(*v, &x) + if err != nil { + return err + } + t.X = &x + } + case "y": + if v != nil { + var y float64 + err = json.Unmarshal(*v, &y) + if err != nil { + return err + } + t.Y = &y + } + } + } + + return nil +} + +// TileCapability specifies the capability to be displayed in the tile. +type TileCapability struct { + // Capability - The path of the capability associated with data to be rendered in the tile. + Capability *string `json:"capability,omitempty"` + // AggregateFunction - The aggregate function to apply to the data. Possible values include: 'CapabilityAggregateTypeSum', 'CapabilityAggregateTypeCount', 'CapabilityAggregateTypeMax', 'CapabilityAggregateTypeMin', 'CapabilityAggregateTypeAvg' + AggregateFunction CapabilityAggregateType `json:"aggregateFunction,omitempty"` +} + +// TileCapabilityConfiguration configuration specifying an array of capabilities to be displayed in the +// tile. +type TileCapabilityConfiguration struct { + Capabilities *[]TileCapability `json:"capabilities,omitempty"` +} + +// BasicTileConfiguration configuration specifying information about a tile. +type BasicTileConfiguration interface { + AsCommandTileConfiguration() (*CommandTileConfiguration, bool) + AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) + AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) + AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) + AsImageTileConfiguration() (*ImageTileConfiguration, bool) + AsLabelTileConfiguration() (*LabelTileConfiguration, bool) + AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) + AsTileConfiguration() (*TileConfiguration, bool) +} + +// TileConfiguration configuration specifying information about a tile. +type TileConfiguration struct { + // Type - Possible values include: 'TypeBasicTileConfigurationTypeTileConfiguration', 'TypeBasicTileConfigurationTypeCommand', 'TypeBasicTileConfigurationTypeDataExplorer', 'TypeBasicTileConfigurationTypeDeviceCount', 'TypeBasicTileConfigurationTypeExternalContent', 'TypeBasicTileConfigurationTypeImage', 'TypeBasicTileConfigurationTypeLabel', 'TypeBasicTileConfigurationTypeMarkdown' + Type TypeBasicTileConfiguration `json:"type,omitempty"` +} + +func unmarshalBasicTileConfiguration(body []byte) (BasicTileConfiguration, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicTileConfigurationTypeCommand): + var ctc CommandTileConfiguration + err := json.Unmarshal(body, &ctc) + return ctc, err + case string(TypeBasicTileConfigurationTypeDataExplorer): + var detc DataExplorerTileConfiguration + err := json.Unmarshal(body, &detc) + return detc, err + case string(TypeBasicTileConfigurationTypeDeviceCount): + var dctc DeviceCountTileConfiguration + err := json.Unmarshal(body, &dctc) + return dctc, err + case string(TypeBasicTileConfigurationTypeExternalContent): + var ectc ExternalContentTileConfiguration + err := json.Unmarshal(body, &ectc) + return ectc, err + case string(TypeBasicTileConfigurationTypeImage): + var itc ImageTileConfiguration + err := json.Unmarshal(body, &itc) + return itc, err + case string(TypeBasicTileConfigurationTypeLabel): + var ltc LabelTileConfiguration + err := json.Unmarshal(body, <c) + return ltc, err + case string(TypeBasicTileConfigurationTypeMarkdown): + var mtc MarkdownTileConfiguration + err := json.Unmarshal(body, &mtc) + return mtc, err + default: + var tc TileConfiguration + err := json.Unmarshal(body, &tc) + return tc, err + } +} +func unmarshalBasicTileConfigurationArray(body []byte) ([]BasicTileConfiguration, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + tcArray := make([]BasicTileConfiguration, len(rawMessages)) + + for index, rawMessage := range rawMessages { + tc, err := unmarshalBasicTileConfiguration(*rawMessage) + if err != nil { + return nil, err + } + tcArray[index] = tc + } + return tcArray, nil +} + +// MarshalJSON is the custom marshaler for TileConfiguration. +func (tc TileConfiguration) MarshalJSON() ([]byte, error) { + tc.Type = TypeBasicTileConfigurationTypeTileConfiguration + objectMap := make(map[string]interface{}) + if tc.Type != "" { + objectMap["type"] = tc.Type + } + return json.Marshal(objectMap) +} + +// AsCommandTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsCommandTileConfiguration() (*CommandTileConfiguration, bool) { + return nil, false +} + +// AsDataExplorerTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsDataExplorerTileConfiguration() (*DataExplorerTileConfiguration, bool) { + return nil, false +} + +// AsDeviceCountTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsDeviceCountTileConfiguration() (*DeviceCountTileConfiguration, bool) { + return nil, false +} + +// AsExternalContentTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsExternalContentTileConfiguration() (*ExternalContentTileConfiguration, bool) { + return nil, false +} + +// AsImageTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsImageTileConfiguration() (*ImageTileConfiguration, bool) { + return nil, false +} + +// AsLabelTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsLabelTileConfiguration() (*LabelTileConfiguration, bool) { + return nil, false +} + +// AsMarkdownTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsMarkdownTileConfiguration() (*MarkdownTileConfiguration, bool) { + return nil, false +} + +// AsTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsTileConfiguration() (*TileConfiguration, bool) { + return &tc, true +} + +// AsBasicTileConfiguration is the BasicTileConfiguration implementation for TileConfiguration. +func (tc TileConfiguration) AsBasicTileConfiguration() (BasicTileConfiguration, bool) { + return &tc, true +} + +// TimeQueryRangeConfiguration configuration specifying the time range and resolution of data to return for +// a tile. +type TimeQueryRangeConfiguration struct { + // Duration - The time range to use when querying data. Possible values include: 'TileTimeRangeDurationThreeZeroSpaceMinutes', 'TileTimeRangeDurationOneSpaceHour', 'TileTimeRangeDurationOneTwoSpaceHours', 'TileTimeRangeDurationOneSpaceDay', 'TileTimeRangeDurationOneSpaceWeek', 'TileTimeRangeDurationThreeZeroSpaceDays' + Duration TileTimeRangeDuration `json:"duration,omitempty"` + // Resolution - The resolution to aggregate data over. Possible values include: 'TileTimeRangeResolutionOneSpaceMinute', 'TileTimeRangeResolutionFiveSpaceMinutes', 'TileTimeRangeResolutionOneZeroSpaceMinutes', 'TileTimeRangeResolutionThreeZeroSpaceMinutes', 'TileTimeRangeResolutionOneSpaceHour', 'TileTimeRangeResolutionOneTwoSpaceHours', 'TileTimeRangeResolutionOneSpaceDay', 'TileTimeRangeResolutionOneSpaceWeek' + Resolution TileTimeRangeResolution `json:"resolution,omitempty"` + // Type - Possible values include: 'TypeBasicQueryRangeConfigurationTypeQueryRangeConfiguration', 'TypeBasicQueryRangeConfigurationTypeTime', 'TypeBasicQueryRangeConfigurationTypeCount' + Type TypeBasicQueryRangeConfiguration `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for TimeQueryRangeConfiguration. +func (tqrc TimeQueryRangeConfiguration) MarshalJSON() ([]byte, error) { + tqrc.Type = TypeBasicQueryRangeConfigurationTypeTime + objectMap := make(map[string]interface{}) + if tqrc.Duration != "" { + objectMap["duration"] = tqrc.Duration + } + if tqrc.Resolution != "" { + objectMap["resolution"] = tqrc.Resolution + } + if tqrc.Type != "" { + objectMap["type"] = tqrc.Type + } + return json.Marshal(objectMap) +} + +// AsTimeQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for TimeQueryRangeConfiguration. +func (tqrc TimeQueryRangeConfiguration) AsTimeQueryRangeConfiguration() (*TimeQueryRangeConfiguration, bool) { + return &tqrc, true +} + +// AsCountQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for TimeQueryRangeConfiguration. +func (tqrc TimeQueryRangeConfiguration) AsCountQueryRangeConfiguration() (*CountQueryRangeConfiguration, bool) { + return nil, false +} + +// AsQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for TimeQueryRangeConfiguration. +func (tqrc TimeQueryRangeConfiguration) AsQueryRangeConfiguration() (*QueryRangeConfiguration, bool) { + return nil, false +} + +// AsBasicQueryRangeConfiguration is the BasicQueryRangeConfiguration implementation for TimeQueryRangeConfiguration. +func (tqrc TimeQueryRangeConfiguration) AsBasicQueryRangeConfiguration() (BasicQueryRangeConfiguration, bool) { + return &tqrc, true +} + +// Tpm the trusted platform module definition. +type Tpm struct { + // EndorsementKey - The TPM endorsement key for this credential. + EndorsementKey *string `json:"endorsementKey,omitempty"` +} + +// TpmAttestation the TPM attestation definition. +type TpmAttestation struct { + // Tpm - The TPM credentials for this attestation. + Tpm *Tpm `json:"tpm,omitempty"` + // Type - Possible values include: 'TypeAttestation', 'TypeSymmetricKey', 'TypeTpm', 'TypeX509' + Type Type `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for TpmAttestation. +func (ta TpmAttestation) MarshalJSON() ([]byte, error) { + ta.Type = TypeTpm + objectMap := make(map[string]interface{}) + if ta.Tpm != nil { + objectMap["tpm"] = ta.Tpm + } + if ta.Type != "" { + objectMap["type"] = ta.Type + } + return json.Marshal(objectMap) +} + +// AsSymmetricKeyAttestation is the BasicAttestation implementation for TpmAttestation. +func (ta TpmAttestation) AsSymmetricKeyAttestation() (*SymmetricKeyAttestation, bool) { + return nil, false +} + +// AsTpmAttestation is the BasicAttestation implementation for TpmAttestation. +func (ta TpmAttestation) AsTpmAttestation() (*TpmAttestation, bool) { + return &ta, true +} + +// AsX509Attestation is the BasicAttestation implementation for TpmAttestation. +func (ta TpmAttestation) AsX509Attestation() (*X509Attestation, bool) { + return nil, false +} + +// AsAttestation is the BasicAttestation implementation for TpmAttestation. +func (ta TpmAttestation) AsAttestation() (*Attestation, bool) { + return nil, false +} + +// AsBasicAttestation is the BasicAttestation implementation for TpmAttestation. +func (ta TpmAttestation) AsBasicAttestation() (BasicAttestation, bool) { + return &ta, true +} + +// BasicUser the user definition. +type BasicUser interface { + AsADGroupUser() (*ADGroupUser, bool) + AsEmailUser() (*EmailUser, bool) + AsServicePrincipalUser() (*ServicePrincipalUser, bool) + AsUser() (*User, bool) +} + +// User the user definition. +type User struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; Unique ID of the user. + ID *string `json:"id,omitempty"` + // Type - Possible values include: 'TypeBasicUserTypeUser', 'TypeBasicUserTypeAdGroup', 'TypeBasicUserTypeEmail', 'TypeBasicUserTypeServicePrincipal' + Type TypeBasicUser `json:"type,omitempty"` + // Roles - List of role assignments that specify the permissions to access the application. + Roles *[]RoleAssignment `json:"roles,omitempty"` +} + +func unmarshalBasicUser(body []byte) (BasicUser, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicUserTypeAdGroup): + var agu ADGroupUser + err := json.Unmarshal(body, &agu) + return agu, err + case string(TypeBasicUserTypeEmail): + var eu EmailUser + err := json.Unmarshal(body, &eu) + return eu, err + case string(TypeBasicUserTypeServicePrincipal): + var spu ServicePrincipalUser + err := json.Unmarshal(body, &spu) + return spu, err + default: + var u User + err := json.Unmarshal(body, &u) + return u, err + } +} +func unmarshalBasicUserArray(body []byte) ([]BasicUser, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + uArray := make([]BasicUser, len(rawMessages)) + + for index, rawMessage := range rawMessages { + u, err := unmarshalBasicUser(*rawMessage) + if err != nil { + return nil, err + } + uArray[index] = u + } + return uArray, nil +} + +// MarshalJSON is the custom marshaler for User. +func (u User) MarshalJSON() ([]byte, error) { + u.Type = TypeBasicUserTypeUser + objectMap := make(map[string]interface{}) + if u.Type != "" { + objectMap["type"] = u.Type + } + if u.Roles != nil { + objectMap["roles"] = u.Roles + } + return json.Marshal(objectMap) +} + +// AsADGroupUser is the BasicUser implementation for User. +func (u User) AsADGroupUser() (*ADGroupUser, bool) { + return nil, false +} + +// AsEmailUser is the BasicUser implementation for User. +func (u User) AsEmailUser() (*EmailUser, bool) { + return nil, false +} + +// AsServicePrincipalUser is the BasicUser implementation for User. +func (u User) AsServicePrincipalUser() (*ServicePrincipalUser, bool) { + return nil, false +} + +// AsUser is the BasicUser implementation for User. +func (u User) AsUser() (*User, bool) { + return &u, true +} + +// AsBasicUser is the BasicUser implementation for User. +func (u User) AsBasicUser() (BasicUser, bool) { + return &u, true +} + +// UserCollection the paged results of users. +type UserCollection struct { + autorest.Response `json:"-"` + // Value - The collection of users. + Value *[]BasicUser `json:"value,omitempty"` + // NextLink - URL to get the next page of users. + NextLink *string `json:"nextLink,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for UserCollection struct. +func (uc *UserCollection) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "value": + if v != nil { + value, err := unmarshalBasicUserArray(*v) + if err != nil { + return err + } + uc.Value = &value + } + case "nextLink": + if v != nil { + var nextLink string + err = json.Unmarshal(*v, &nextLink) + if err != nil { + return err + } + uc.NextLink = &nextLink + } + } + } + + return nil +} + +// UserCollectionIterator provides access to a complete listing of User values. +type UserCollectionIterator struct { + i int + page UserCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *UserCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UserCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *UserCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter UserCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter UserCollectionIterator) Response() UserCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter UserCollectionIterator) Value() BasicUser { + if !iter.page.NotDone() { + return User{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the UserCollectionIterator type. +func NewUserCollectionIterator(page UserCollectionPage) UserCollectionIterator { + return UserCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (uc UserCollection) IsEmpty() bool { + return uc.Value == nil || len(*uc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (uc UserCollection) hasNextLink() bool { + return uc.NextLink != nil && len(*uc.NextLink) != 0 +} + +// userCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (uc UserCollection) userCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !uc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(uc.NextLink))) +} + +// UserCollectionPage contains a page of BasicUser values. +type UserCollectionPage struct { + fn func(context.Context, UserCollection) (UserCollection, error) + uc UserCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *UserCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UserCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.uc) + if err != nil { + return err + } + page.uc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *UserCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page UserCollectionPage) NotDone() bool { + return !page.uc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page UserCollectionPage) Response() UserCollection { + return page.uc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page UserCollectionPage) Values() []BasicUser { + if page.uc.IsEmpty() { + return nil + } + return *page.uc.Value +} + +// Creates a new instance of the UserCollectionPage type. +func NewUserCollectionPage(cur UserCollection, getNextPage func(context.Context, UserCollection) (UserCollection, error)) UserCollectionPage { + return UserCollectionPage{ + fn: getNextPage, + uc: cur, + } +} + +// UserModel ... +type UserModel struct { + autorest.Response `json:"-"` + Value BasicUser `json:"value,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for UserModel struct. +func (um *UserModel) UnmarshalJSON(body []byte) error { + u, err := unmarshalBasicUser(body) + if err != nil { + return err + } + um.Value = u + + return nil +} + +// WebhookV1Destination the webhook destination definition. +type WebhookV1Destination struct { + // URL - The URL to invoke when exporting data. + URL *string `json:"url,omitempty"` + // QueryCustomizations - Additional query parameters that should be added to each request. + QueryCustomizations map[string]*WebhookV1DestinationCustomization `json:"queryCustomizations"` + // HeaderCustomizations - Additional headers that should be added to each request. + HeaderCustomizations map[string]*WebhookV1DestinationCustomization `json:"headerCustomizations"` + Authorization BasicWebhookV1DestinationAuth `json:"authorization,omitempty"` + // ID - READ-ONLY; Unique ID of the destination. + ID *string `json:"id,omitempty"` + // DisplayName - Display name of the destination. + DisplayName *string `json:"displayName,omitempty"` + // Type - Possible values include: 'TypeBasicDestinationTypeDestination', 'TypeBasicDestinationTypeBlobstorageV1', 'TypeBasicDestinationTypeDataexplorerV1', 'TypeBasicDestinationTypeEventhubsV1', 'TypeBasicDestinationTypeExportDestination', 'TypeBasicDestinationTypeServicebusqueueV1', 'TypeBasicDestinationTypeServicebustopicV1', 'TypeBasicDestinationTypeWebhookV1' + Type TypeBasicDestination `json:"type,omitempty"` + // Status - READ-ONLY; Indication of the current health and operation of the export or destination. + Status *string `json:"status,omitempty"` + // Errors - READ-ONLY; Errors encountered by the export or destination. + Errors *[]DataExportError `json:"errors,omitempty"` + // LastExportTime - READ-ONLY; The timestamp of the last message that was sent to the export or destination. + LastExportTime *date.Time `json:"lastExportTime,omitempty"` +} + +// MarshalJSON is the custom marshaler for WebhookV1Destination. +func (wvd WebhookV1Destination) MarshalJSON() ([]byte, error) { + wvd.Type = TypeBasicDestinationTypeWebhookV1 + objectMap := make(map[string]interface{}) + if wvd.URL != nil { + objectMap["url"] = wvd.URL + } + if wvd.QueryCustomizations != nil { + objectMap["queryCustomizations"] = wvd.QueryCustomizations + } + if wvd.HeaderCustomizations != nil { + objectMap["headerCustomizations"] = wvd.HeaderCustomizations + } + objectMap["authorization"] = wvd.Authorization + if wvd.DisplayName != nil { + objectMap["displayName"] = wvd.DisplayName + } + if wvd.Type != "" { + objectMap["type"] = wvd.Type + } + return json.Marshal(objectMap) +} + +// AsBlobStorageV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsBlobStorageV1Destination() (*BlobStorageV1Destination, bool) { + return nil, false +} + +// AsDataExplorerV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsDataExplorerV1Destination() (*DataExplorerV1Destination, bool) { + return nil, false +} + +// AsEventHubsV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsEventHubsV1Destination() (*EventHubsV1Destination, bool) { + return nil, false +} + +// AsExportDestination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsExportDestination() (*ExportDestination, bool) { + return nil, false +} + +// AsServiceBusQueueV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsServiceBusQueueV1Destination() (*ServiceBusQueueV1Destination, bool) { + return nil, false +} + +// AsServiceBusTopicV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsServiceBusTopicV1Destination() (*ServiceBusTopicV1Destination, bool) { + return nil, false +} + +// AsWebhookV1Destination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsWebhookV1Destination() (*WebhookV1Destination, bool) { + return &wvd, true +} + +// AsDestination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsDestination() (*Destination, bool) { + return nil, false +} + +// AsBasicDestination is the BasicDestination implementation for WebhookV1Destination. +func (wvd WebhookV1Destination) AsBasicDestination() (BasicDestination, bool) { + return &wvd, true +} + +// UnmarshalJSON is the custom unmarshaler for WebhookV1Destination struct. +func (wvd *WebhookV1Destination) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "url": + if v != nil { + var URL string + err = json.Unmarshal(*v, &URL) + if err != nil { + return err + } + wvd.URL = &URL + } + case "queryCustomizations": + if v != nil { + var queryCustomizations map[string]*WebhookV1DestinationCustomization + err = json.Unmarshal(*v, &queryCustomizations) + if err != nil { + return err + } + wvd.QueryCustomizations = queryCustomizations + } + case "headerCustomizations": + if v != nil { + var headerCustomizations map[string]*WebhookV1DestinationCustomization + err = json.Unmarshal(*v, &headerCustomizations) + if err != nil { + return err + } + wvd.HeaderCustomizations = headerCustomizations + } + case "authorization": + if v != nil { + authorization, err := unmarshalBasicWebhookV1DestinationAuth(*v) + if err != nil { + return err + } + wvd.Authorization = authorization + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + wvd.ID = &ID + } + case "displayName": + if v != nil { + var displayName string + err = json.Unmarshal(*v, &displayName) + if err != nil { + return err + } + wvd.DisplayName = &displayName + } + case "type": + if v != nil { + var typeVar TypeBasicDestination + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + wvd.Type = typeVar + } + case "status": + if v != nil { + var status string + err = json.Unmarshal(*v, &status) + if err != nil { + return err + } + wvd.Status = &status + } + case "errors": + if v != nil { + var errorsVar []DataExportError + err = json.Unmarshal(*v, &errorsVar) + if err != nil { + return err + } + wvd.Errors = &errorsVar + } + case "lastExportTime": + if v != nil { + var lastExportTime date.Time + err = json.Unmarshal(*v, &lastExportTime) + if err != nil { + return err + } + wvd.LastExportTime = &lastExportTime + } + } + } + + return nil +} + +// BasicWebhookV1DestinationAuth the authentication definition for webhook destination. +type BasicWebhookV1DestinationAuth interface { + AsWebhookV1DestinationHeaderAuth() (*WebhookV1DestinationHeaderAuth, bool) + AsWebhookV1DestinationOAuthAuth() (*WebhookV1DestinationOAuthAuth, bool) + AsWebhookV1DestinationAuth() (*WebhookV1DestinationAuth, bool) +} + +// WebhookV1DestinationAuth the authentication definition for webhook destination. +type WebhookV1DestinationAuth struct { + // Type - Possible values include: 'TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth', 'TypeBasicWebhookV1DestinationAuthTypeHeader', 'TypeBasicWebhookV1DestinationAuthTypeOauth' + Type TypeBasicWebhookV1DestinationAuth `json:"type,omitempty"` +} + +func unmarshalBasicWebhookV1DestinationAuth(body []byte) (BasicWebhookV1DestinationAuth, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["type"] { + case string(TypeBasicWebhookV1DestinationAuthTypeHeader): + var wvdha WebhookV1DestinationHeaderAuth + err := json.Unmarshal(body, &wvdha) + return wvdha, err + case string(TypeBasicWebhookV1DestinationAuthTypeOauth): + var wvdoaa WebhookV1DestinationOAuthAuth + err := json.Unmarshal(body, &wvdoaa) + return wvdoaa, err + default: + var wvda WebhookV1DestinationAuth + err := json.Unmarshal(body, &wvda) + return wvda, err + } +} +func unmarshalBasicWebhookV1DestinationAuthArray(body []byte) ([]BasicWebhookV1DestinationAuth, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + wvdaArray := make([]BasicWebhookV1DestinationAuth, len(rawMessages)) + + for index, rawMessage := range rawMessages { + wvda, err := unmarshalBasicWebhookV1DestinationAuth(*rawMessage) + if err != nil { + return nil, err + } + wvdaArray[index] = wvda + } + return wvdaArray, nil +} + +// MarshalJSON is the custom marshaler for WebhookV1DestinationAuth. +func (wvda WebhookV1DestinationAuth) MarshalJSON() ([]byte, error) { + wvda.Type = TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth + objectMap := make(map[string]interface{}) + if wvda.Type != "" { + objectMap["type"] = wvda.Type + } + return json.Marshal(objectMap) +} + +// AsWebhookV1DestinationHeaderAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationAuth. +func (wvda WebhookV1DestinationAuth) AsWebhookV1DestinationHeaderAuth() (*WebhookV1DestinationHeaderAuth, bool) { + return nil, false +} + +// AsWebhookV1DestinationOAuthAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationAuth. +func (wvda WebhookV1DestinationAuth) AsWebhookV1DestinationOAuthAuth() (*WebhookV1DestinationOAuthAuth, bool) { + return nil, false +} + +// AsWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationAuth. +func (wvda WebhookV1DestinationAuth) AsWebhookV1DestinationAuth() (*WebhookV1DestinationAuth, bool) { + return &wvda, true +} + +// AsBasicWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationAuth. +func (wvda WebhookV1DestinationAuth) AsBasicWebhookV1DestinationAuth() (BasicWebhookV1DestinationAuth, bool) { + return &wvda, true +} + +// WebhookV1DestinationCustomization the customization definition for webhook destination. +type WebhookV1DestinationCustomization struct { + // Value - The value to use for this webhook customization. + Value *string `json:"value,omitempty"` + // Secret - Whether to consider the value to be a secret and hide it when retrieving the destination configuration. + Secret *bool `json:"secret,omitempty"` +} + +// WebhookV1DestinationHeaderAuth the authentication definition with header for webhook destination. +type WebhookV1DestinationHeaderAuth struct { + // Value - Value to use for the Authorization header when making requests. + Value *string `json:"value,omitempty"` + // Type - Possible values include: 'TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth', 'TypeBasicWebhookV1DestinationAuthTypeHeader', 'TypeBasicWebhookV1DestinationAuthTypeOauth' + Type TypeBasicWebhookV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for WebhookV1DestinationHeaderAuth. +func (wvdha WebhookV1DestinationHeaderAuth) MarshalJSON() ([]byte, error) { + wvdha.Type = TypeBasicWebhookV1DestinationAuthTypeHeader + objectMap := make(map[string]interface{}) + if wvdha.Value != nil { + objectMap["value"] = wvdha.Value + } + if wvdha.Type != "" { + objectMap["type"] = wvdha.Type + } + return json.Marshal(objectMap) +} + +// AsWebhookV1DestinationHeaderAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationHeaderAuth. +func (wvdha WebhookV1DestinationHeaderAuth) AsWebhookV1DestinationHeaderAuth() (*WebhookV1DestinationHeaderAuth, bool) { + return &wvdha, true +} + +// AsWebhookV1DestinationOAuthAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationHeaderAuth. +func (wvdha WebhookV1DestinationHeaderAuth) AsWebhookV1DestinationOAuthAuth() (*WebhookV1DestinationOAuthAuth, bool) { + return nil, false +} + +// AsWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationHeaderAuth. +func (wvdha WebhookV1DestinationHeaderAuth) AsWebhookV1DestinationAuth() (*WebhookV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationHeaderAuth. +func (wvdha WebhookV1DestinationHeaderAuth) AsBasicWebhookV1DestinationAuth() (BasicWebhookV1DestinationAuth, bool) { + return &wvdha, true +} + +// WebhookV1DestinationOAuthAuth the authentication definition with OAuth for webhook destination. +type WebhookV1DestinationOAuthAuth struct { + // TokenURL - URL where an access token can be retrieved. + TokenURL *string `json:"tokenUrl,omitempty"` + // ClientID - OAuth2 client ID used when retrieving the token. + ClientID *string `json:"clientId,omitempty"` + // ClientSecret - OAuth2 client secret used to retrieve the token. + ClientSecret *string `json:"clientSecret,omitempty"` + // Audience - OAuth2 audience. + Audience *string `json:"audience,omitempty"` + // Scope - OAuth2 scope. + Scope *string `json:"scope,omitempty"` + // RequestType - Content-Type for the token request. Possible values include: 'OAuthRequestTypeAuto', 'OAuthRequestTypeJSON', 'OAuthRequestTypeURLEncoded' + RequestType OAuthRequestType `json:"requestType,omitempty"` + // Type - Possible values include: 'TypeBasicWebhookV1DestinationAuthTypeWebhookV1DestinationAuth', 'TypeBasicWebhookV1DestinationAuthTypeHeader', 'TypeBasicWebhookV1DestinationAuthTypeOauth' + Type TypeBasicWebhookV1DestinationAuth `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for WebhookV1DestinationOAuthAuth. +func (wvdoaa WebhookV1DestinationOAuthAuth) MarshalJSON() ([]byte, error) { + wvdoaa.Type = TypeBasicWebhookV1DestinationAuthTypeOauth + objectMap := make(map[string]interface{}) + if wvdoaa.TokenURL != nil { + objectMap["tokenUrl"] = wvdoaa.TokenURL + } + if wvdoaa.ClientID != nil { + objectMap["clientId"] = wvdoaa.ClientID + } + if wvdoaa.ClientSecret != nil { + objectMap["clientSecret"] = wvdoaa.ClientSecret + } + if wvdoaa.Audience != nil { + objectMap["audience"] = wvdoaa.Audience + } + if wvdoaa.Scope != nil { + objectMap["scope"] = wvdoaa.Scope + } + if wvdoaa.RequestType != "" { + objectMap["requestType"] = wvdoaa.RequestType + } + if wvdoaa.Type != "" { + objectMap["type"] = wvdoaa.Type + } + return json.Marshal(objectMap) +} + +// AsWebhookV1DestinationHeaderAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationOAuthAuth. +func (wvdoaa WebhookV1DestinationOAuthAuth) AsWebhookV1DestinationHeaderAuth() (*WebhookV1DestinationHeaderAuth, bool) { + return nil, false +} + +// AsWebhookV1DestinationOAuthAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationOAuthAuth. +func (wvdoaa WebhookV1DestinationOAuthAuth) AsWebhookV1DestinationOAuthAuth() (*WebhookV1DestinationOAuthAuth, bool) { + return &wvdoaa, true +} + +// AsWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationOAuthAuth. +func (wvdoaa WebhookV1DestinationOAuthAuth) AsWebhookV1DestinationAuth() (*WebhookV1DestinationAuth, bool) { + return nil, false +} + +// AsBasicWebhookV1DestinationAuth is the BasicWebhookV1DestinationAuth implementation for WebhookV1DestinationOAuthAuth. +func (wvdoaa WebhookV1DestinationOAuthAuth) AsBasicWebhookV1DestinationAuth() (BasicWebhookV1DestinationAuth, bool) { + return &wvdoaa, true +} + +// X509 the X509 definition. +type X509 struct { + // ClientCertificates - The X.509 client certificates for this credential. + ClientCertificates *X509Certificates `json:"clientCertificates,omitempty"` +} + +// X509Attestation the X509 attestation definition. +type X509Attestation struct { + // X509 - The X.509 credentials for this attestation. + X509 *X509 `json:"x509,omitempty"` + // Type - Possible values include: 'TypeAttestation', 'TypeSymmetricKey', 'TypeTpm', 'TypeX509' + Type Type `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for X509Attestation. +func (xa X509Attestation) MarshalJSON() ([]byte, error) { + xa.Type = TypeX509 + objectMap := make(map[string]interface{}) + if xa.X509 != nil { + objectMap["x509"] = xa.X509 + } + if xa.Type != "" { + objectMap["type"] = xa.Type + } + return json.Marshal(objectMap) +} + +// AsSymmetricKeyAttestation is the BasicAttestation implementation for X509Attestation. +func (xa X509Attestation) AsSymmetricKeyAttestation() (*SymmetricKeyAttestation, bool) { + return nil, false +} + +// AsTpmAttestation is the BasicAttestation implementation for X509Attestation. +func (xa X509Attestation) AsTpmAttestation() (*TpmAttestation, bool) { + return nil, false +} + +// AsX509Attestation is the BasicAttestation implementation for X509Attestation. +func (xa X509Attestation) AsX509Attestation() (*X509Attestation, bool) { + return &xa, true +} + +// AsAttestation is the BasicAttestation implementation for X509Attestation. +func (xa X509Attestation) AsAttestation() (*Attestation, bool) { + return nil, false +} + +// AsBasicAttestation is the BasicAttestation implementation for X509Attestation. +func (xa X509Attestation) AsBasicAttestation() (BasicAttestation, bool) { + return &xa, true +} + +// X509Certificate the X509 certificate definition. +type X509Certificate struct { + // Certificate - The string representation of this certificate. + Certificate *string `json:"certificate,omitempty"` + // Info - READ-ONLY; Information about this certificate. + Info *X509CertificateInfo `json:"info,omitempty"` +} + +// MarshalJSON is the custom marshaler for X509Certificate. +func (xc X509Certificate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if xc.Certificate != nil { + objectMap["certificate"] = xc.Certificate + } + return json.Marshal(objectMap) +} + +// X509CertificateInfo the X509 certificate info. +type X509CertificateInfo struct { + // Sha1Thumbprint - The SHA-1 hash value of the certificate. + Sha1Thumbprint *string `json:"sha1Thumbprint,omitempty"` +} + +// X509Certificates the X509 certificates definition. +type X509Certificates struct { + // Primary - The primary X.509 certificate for this credential. + Primary *X509Certificate `json:"primary,omitempty"` + // Secondary - The secondary X.509 certificate for this credential. + Secondary *X509Certificate `json:"secondary,omitempty"` +} + +// X509VerificationCertificate the X509 verification certificate definition. +type X509VerificationCertificate struct { + // Certificate - The string representation of this certificate. + Certificate *string `json:"certificate,omitempty"` +} + +// X509VerificationCode the X509 certificate verification code. +type X509VerificationCode struct { + autorest.Response `json:"-"` + // VerificationCode - READ-ONLY; The X509 certificate verification code. + VerificationCode *string `json:"verificationCode,omitempty"` +} + +// MarshalJSON is the custom marshaler for X509VerificationCode. +func (xvc X509VerificationCode) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/organizations.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/organizations.go new file mode 100644 index 000000000000..e58677be6554 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/organizations.go @@ -0,0 +1,490 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// OrganizationsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your +// IoT devices at scale. +type OrganizationsClient struct { + BaseClient +} + +// NewOrganizationsClient creates an instance of the OrganizationsClient client. +func NewOrganizationsClient(subdomain string) OrganizationsClient { + return OrganizationsClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// organizationID - unique ID for the organization. +// body - organization body. +func (client OrganizationsClient) Create(ctx context.Context, organizationID string, body Organization) (result Organization, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: organizationID, + Constraints: []validation.Constraint{{Target: "organizationID", Name: validation.MaxLength, Rule: 48, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.OrganizationsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, organizationID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client OrganizationsClient) CreatePreparer(ctx context.Context, organizationID string, body Organization) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "organizationId": autorest.Encode("path", organizationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/organizations/{organizationId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client OrganizationsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client OrganizationsClient) CreateResponder(resp *http.Response) (result Organization, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// organizationID - unique ID for the organization. +func (client OrganizationsClient) Get(ctx context.Context, organizationID string) (result Organization, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: organizationID, + Constraints: []validation.Constraint{{Target: "organizationID", Name: validation.MaxLength, Rule: 48, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.OrganizationsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, organizationID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client OrganizationsClient) GetPreparer(ctx context.Context, organizationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "organizationId": autorest.Encode("path", organizationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/organizations/{organizationId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client OrganizationsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client OrganizationsClient) GetResponder(resp *http.Response) (result Organization, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client OrganizationsClient) List(ctx context.Context) (result OrganizationCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.List") + defer func() { + sc := -1 + if result.oc.Response.Response != nil { + sc = result.oc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.oc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "List", resp, "Failure sending request") + return + } + + result.oc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "List", resp, "Failure responding to request") + return + } + if result.oc.hasNextLink() && result.oc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client OrganizationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/organizations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OrganizationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OrganizationsClient) ListResponder(resp *http.Response) (result OrganizationCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OrganizationsClient) listNextResults(ctx context.Context, lastResults OrganizationCollection) (result OrganizationCollection, err error) { + req, err := lastResults.organizationCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OrganizationsClient) ListComplete(ctx context.Context) (result OrganizationCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} + +// Remove sends the remove request. +// Parameters: +// organizationID - unique ID for the organization. +func (client OrganizationsClient) Remove(ctx context.Context, organizationID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: organizationID, + Constraints: []validation.Constraint{{Target: "organizationID", Name: validation.MaxLength, Rule: 48, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.OrganizationsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, organizationID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client OrganizationsClient) RemovePreparer(ctx context.Context, organizationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "organizationId": autorest.Encode("path", organizationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/organizations/{organizationId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client OrganizationsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client OrganizationsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// organizationID - unique ID for the organization. +// body - organization patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client OrganizationsClient) Update(ctx context.Context, organizationID string, body interface{}, ifMatch string) (result Organization, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OrganizationsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: organizationID, + Constraints: []validation.Constraint{{Target: "organizationID", Name: validation.MaxLength, Rule: 48, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.OrganizationsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, organizationID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.OrganizationsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client OrganizationsClient) UpdatePreparer(ctx context.Context, organizationID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "organizationId": autorest.Encode("path", organizationID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/organizations/{organizationId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client OrganizationsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client OrganizationsClient) UpdateResponder(resp *http.Response) (result Organization, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/query.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/query.go new file mode 100644 index 000000000000..35cb43357054 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/query.go @@ -0,0 +1,110 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// QueryClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type QueryClient struct { + BaseClient +} + +// NewQueryClient creates an instance of the QueryClient client. +func NewQueryClient(subdomain string) QueryClient { + return QueryClient{New(subdomain)} +} + +// Run sends the run request. +// Parameters: +// body - query, more details on [IoT central query language](https://aka.ms/iotcql). +func (client QueryClient) Run(ctx context.Context, body QueryRequest) (result QueryResponse, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/QueryClient.Run") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Query", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.QueryClient", "Run", err.Error()) + } + + req, err := client.RunPreparer(ctx, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.QueryClient", "Run", nil, "Failure preparing request") + return + } + + resp, err := client.RunSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.QueryClient", "Run", resp, "Failure sending request") + return + } + + result, err = client.RunResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.QueryClient", "Run", resp, "Failure responding to request") + return + } + + return +} + +// RunPreparer prepares the Run request. +func (client QueryClient) RunPreparer(ctx context.Context, body QueryRequest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/query"), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RunSender sends the Run request. The method will close the +// http.Response Body if it receives an error. +func (client QueryClient) RunSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RunResponder handles the response to the Run request. The method always +// closes the http.Response Body. +func (client QueryClient) RunResponder(resp *http.Response) (result QueryResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/roles.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/roles.go new file mode 100644 index 000000000000..99bd4dbb5276 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/roles.go @@ -0,0 +1,219 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" +) + +// RolesClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type RolesClient struct { + BaseClient +} + +// NewRolesClient creates an instance of the RolesClient client. +func NewRolesClient(subdomain string) RolesClient { + return RolesClient{New(subdomain)} +} + +// Get sends the get request. +// Parameters: +// roleID - unique ID for the role. +func (client RolesClient) Get(ctx context.Context, roleID string) (result Role, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RolesClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, roleID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client RolesClient) GetPreparer(ctx context.Context, roleID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "roleId": autorest.Encode("path", roleID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/roles/{roleId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client RolesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client RolesClient) GetResponder(resp *http.Response) (result Role, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +func (client RolesClient) List(ctx context.Context) (result RoleCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RolesClient.List") + defer func() { + sc := -1 + if result.rc.Response.Response != nil { + sc = result.rc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.rc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "List", resp, "Failure sending request") + return + } + + result.rc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "List", resp, "Failure responding to request") + return + } + if result.rc.hasNextLink() && result.rc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client RolesClient) ListPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/roles"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client RolesClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client RolesClient) ListResponder(resp *http.Response) (result RoleCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client RolesClient) listNextResults(ctx context.Context, lastResults RoleCollection) (result RoleCollection, err error) { + req, err := lastResults.roleCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.RolesClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.RolesClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.RolesClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client RolesClient) ListComplete(ctx context.Context) (result RoleCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RolesClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/scheduledjobs.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/scheduledjobs.go new file mode 100644 index 000000000000..bfe238715c22 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/scheduledjobs.go @@ -0,0 +1,659 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// ScheduledJobsClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your +// IoT devices at scale. +type ScheduledJobsClient struct { + BaseClient +} + +// NewScheduledJobsClient creates an instance of the ScheduledJobsClient client. +func NewScheduledJobsClient(subdomain string) ScheduledJobsClient { + return ScheduledJobsClient{New(subdomain)} +} + +// Create create or update a scheduled job by ID. +// Parameters: +// scheduledJobID - unique ID of the scheduled job. +// body - scheduled job definition. +func (client ScheduledJobsClient) Create(ctx context.Context, scheduledJobID string, body ScheduledJob) (result ScheduledJob, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: scheduledJobID, + Constraints: []validation.Constraint{{Target: "scheduledJobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "scheduledJobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}, + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.Group", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.Batch", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Batch.Value", Name: validation.Null, Rule: true, Chain: nil}}}, + {Target: "body.CancellationThreshold", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.CancellationThreshold.Value", Name: validation.Null, Rule: true, Chain: nil}}}, + {Target: "body.Data", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.Data", Name: validation.MinItems, Rule: 1, Chain: nil}}}, + {Target: "body.Organizations", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.Organizations", Name: validation.MaxItems, Rule: 1, Chain: nil}, + {Target: "body.Organizations", Name: validation.MinItems, Rule: 1, Chain: nil}, + }}, + {Target: "body.Schedule", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.Schedule.Start", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, scheduledJobID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client ScheduledJobsClient) CreatePreparer(ctx context.Context, scheduledJobID string, body ScheduledJob) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "scheduledJobId": autorest.Encode("path", scheduledJobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + body.ID = nil + body.Completed = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/scheduledJobs/{scheduledJobId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) CreateResponder(resp *http.Response) (result ScheduledJob, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get details about a scheduled job by ID. +// Parameters: +// scheduledJobID - unique ID of the scheduled job. +func (client ScheduledJobsClient) Get(ctx context.Context, scheduledJobID string) (result ScheduledJob, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: scheduledJobID, + Constraints: []validation.Constraint{{Target: "scheduledJobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "scheduledJobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, scheduledJobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ScheduledJobsClient) GetPreparer(ctx context.Context, scheduledJobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "scheduledJobId": autorest.Encode("path", scheduledJobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/scheduledJobs/{scheduledJobId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) GetResponder(resp *http.Response) (result ScheduledJob, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// maxpagesize - the maximum number of resources to return from one response. +func (client ScheduledJobsClient) List(ctx context.Context, maxpagesize *int32) (result ScheduledJobCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.List") + defer func() { + sc := -1 + if result.sjc.Response.Response != nil { + sc = result.sjc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.sjc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "List", resp, "Failure sending request") + return + } + + result.sjc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "List", resp, "Failure responding to request") + return + } + if result.sjc.hasNextLink() && result.sjc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client ScheduledJobsClient) ListPreparer(ctx context.Context, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/scheduledJobs"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) ListResponder(resp *http.Response) (result ScheduledJobCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client ScheduledJobsClient) listNextResults(ctx context.Context, lastResults ScheduledJobCollection) (result ScheduledJobCollection, err error) { + req, err := lastResults.scheduledJobCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client ScheduledJobsClient) ListComplete(ctx context.Context, maxpagesize *int32) (result ScheduledJobCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, maxpagesize) + return +} + +// ListJobs sends the list jobs request. +// Parameters: +// scheduledJobID - unique ID of the scheduled job. +// maxpagesize - the maximum number of resources to return from one response. +func (client ScheduledJobsClient) ListJobs(ctx context.Context, scheduledJobID string, maxpagesize *int32) (result JobCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.ListJobs") + defer func() { + sc := -1 + if result.jc.Response.Response != nil { + sc = result.jc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: scheduledJobID, + Constraints: []validation.Constraint{{Target: "scheduledJobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "scheduledJobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}, + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "ListJobs", err.Error()) + } + + result.fn = client.listJobsNextResults + req, err := client.ListJobsPreparer(ctx, scheduledJobID, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "ListJobs", nil, "Failure preparing request") + return + } + + resp, err := client.ListJobsSender(req) + if err != nil { + result.jc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "ListJobs", resp, "Failure sending request") + return + } + + result.jc, err = client.ListJobsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "ListJobs", resp, "Failure responding to request") + return + } + if result.jc.hasNextLink() && result.jc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListJobsPreparer prepares the ListJobs request. +func (client ScheduledJobsClient) ListJobsPreparer(ctx context.Context, scheduledJobID string, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "scheduledJobId": autorest.Encode("path", scheduledJobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/scheduledJobs/{scheduledJobId}/jobs", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListJobsSender sends the ListJobs request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) ListJobsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListJobsResponder handles the response to the ListJobs request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) ListJobsResponder(resp *http.Response) (result JobCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listJobsNextResults retrieves the next set of results, if any. +func (client ScheduledJobsClient) listJobsNextResults(ctx context.Context, lastResults JobCollection) (result JobCollection, err error) { + req, err := lastResults.jobCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listJobsNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListJobsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listJobsNextResults", resp, "Failure sending next results request") + } + result, err = client.ListJobsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "listJobsNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListJobsComplete enumerates all values, automatically crossing page boundaries as required. +func (client ScheduledJobsClient) ListJobsComplete(ctx context.Context, scheduledJobID string, maxpagesize *int32) (result JobCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.ListJobs") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListJobs(ctx, scheduledJobID, maxpagesize) + return +} + +// Remove delete an existing scheduled job by ID. +// Parameters: +// scheduledJobID - unique ID of the scheduled job. +func (client ScheduledJobsClient) Remove(ctx context.Context, scheduledJobID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: scheduledJobID, + Constraints: []validation.Constraint{{Target: "scheduledJobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "scheduledJobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, scheduledJobID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client ScheduledJobsClient) RemovePreparer(ctx context.Context, scheduledJobID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "scheduledJobId": autorest.Encode("path", scheduledJobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/scheduledJobs/{scheduledJobId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update update an existing scheduled job by ID. +// Parameters: +// scheduledJobID - unique ID of the scheduled job. +// body - scheduled job patch. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client ScheduledJobsClient) Update(ctx context.Context, scheduledJobID string, body interface{}, ifMatch string) (result ScheduledJob, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ScheduledJobsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: scheduledJobID, + Constraints: []validation.Constraint{{Target: "scheduledJobID", Name: validation.MaxLength, Rule: 255, Chain: nil}, + {Target: "scheduledJobID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.ScheduledJobsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, scheduledJobID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.ScheduledJobsClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client ScheduledJobsClient) UpdatePreparer(ctx context.Context, scheduledJobID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "scheduledJobId": autorest.Encode("path", scheduledJobID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/merge-patch+json"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/scheduledJobs/{scheduledJobId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client ScheduledJobsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client ScheduledJobsClient) UpdateResponder(resp *http.Response) (result ScheduledJob, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/users.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/users.go new file mode 100644 index 000000000000..17426ea1ab70 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/users.go @@ -0,0 +1,507 @@ +package iotcentral + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" +) + +// UsersClient is the azure IoT Central is a service that makes it easy to connect, monitor, and manage your IoT +// devices at scale. +type UsersClient struct { + BaseClient +} + +// NewUsersClient creates an instance of the UsersClient client. +func NewUsersClient(subdomain string) UsersClient { + return UsersClient{New(subdomain)} +} + +// Create sends the create request. +// Parameters: +// userID - unique ID for the user. +// body - user body. +func (client UsersClient) Create(ctx context.Context, userID string, body BasicUser) (result UserModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: userID, + Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 48, Chain: nil}, + {Target: "userID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-_]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.UsersClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, userID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Create", resp, "Failure responding to request") + return + } + + return +} + +// CreatePreparer prepares the Create request. +func (client UsersClient) CreatePreparer(ctx context.Context, userID string, body BasicUser) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "userId": autorest.Encode("path", userID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/users/{userId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client UsersClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client UsersClient) CreateResponder(resp *http.Response) (result UserModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get sends the get request. +// Parameters: +// userID - unique ID for the user. +func (client UsersClient) Get(ctx context.Context, userID string) (result UserModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: userID, + Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 48, Chain: nil}, + {Target: "userID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-_]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.UsersClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, userID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client UsersClient) GetPreparer(ctx context.Context, userID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "userId": autorest.Encode("path", userID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/users/{userId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client UsersClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client UsersClient) GetResponder(resp *http.Response) (result UserModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// maxpagesize - the maximum number of resources to return from one response. +func (client UsersClient) List(ctx context.Context, maxpagesize *int32) (result UserCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.List") + defer func() { + sc := -1 + if result.uc.Response.Response != nil { + sc = result.uc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: maxpagesize, + Constraints: []validation.Constraint{{Target: "maxpagesize", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "maxpagesize", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil}, + {Target: "maxpagesize", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("iotcentral.UsersClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, maxpagesize) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.uc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "List", resp, "Failure sending request") + return + } + + result.uc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "List", resp, "Failure responding to request") + return + } + if result.uc.hasNextLink() && result.uc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client UsersClient) ListPreparer(ctx context.Context, maxpagesize *int32) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if maxpagesize != nil { + queryParameters["maxpagesize"] = autorest.Encode("query", *maxpagesize) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPath("/users"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client UsersClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client UsersClient) ListResponder(resp *http.Response) (result UserCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client UsersClient) listNextResults(ctx context.Context, lastResults UserCollection) (result UserCollection, err error) { + req, err := lastResults.userCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.UsersClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.UsersClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsersClient) ListComplete(ctx context.Context, maxpagesize *int32) (result UserCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, maxpagesize) + return +} + +// Remove sends the remove request. +// Parameters: +// userID - unique ID for the user. +func (client UsersClient) Remove(ctx context.Context, userID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Remove") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: userID, + Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 48, Chain: nil}, + {Target: "userID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-_]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.UsersClient", "Remove", err.Error()) + } + + req, err := client.RemovePreparer(ctx, userID) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Remove", nil, "Failure preparing request") + return + } + + resp, err := client.RemoveSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Remove", resp, "Failure sending request") + return + } + + result, err = client.RemoveResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Remove", resp, "Failure responding to request") + return + } + + return +} + +// RemovePreparer prepares the Remove request. +func (client UsersClient) RemovePreparer(ctx context.Context, userID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "userId": autorest.Encode("path", userID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/users/{userId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RemoveSender sends the Remove request. The method will close the +// http.Response Body if it receives an error. +func (client UsersClient) RemoveSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RemoveResponder handles the response to the Remove request. The method always +// closes the http.Response Body. +func (client UsersClient) RemoveResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// userID - unique ID for the user. +// body - user patch body. +// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is +// provided. +func (client UsersClient) Update(ctx context.Context, userID string, body interface{}, ifMatch string) (result UserModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: userID, + Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 48, Chain: nil}, + {Target: "userID", Name: validation.Pattern, Rule: `^[a-zA-Z0-9-_]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("iotcentral.UsersClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, userID, body, ifMatch) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.UsersClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client UsersClient) UpdatePreparer(ctx context.Context, userID string, body interface{}, ifMatch string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "baseDomain": client.BaseDomain, + "subdomain": autorest.Encode("path", client.Subdomain), + } + + pathParameters := map[string]interface{}{ + "userId": autorest.Encode("path", userID), + } + + const APIVersion = "2022-10-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("https://{subdomain}.{baseDomain}/api", urlParameters), + autorest.WithPathParameters("/users/{userId}", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + if len(ifMatch) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("If-Match", autorest.String(ifMatch))) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client UsersClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client UsersClient) UpdateResponder(resp *http.Response) (result UserModel, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/version.go b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/version.go new file mode 100644 index 000000000000..75b18be4c98a --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral/version.go @@ -0,0 +1,19 @@ +package iotcentral + +import "github.com/tombuildsstuff/kermit/version" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "tombuildsstuff/kermit/" + Version() + " iotcentral/2022-10-31-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a9ba632b679b..63ec46edd0a2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1267,6 +1267,7 @@ github.com/tombuildsstuff/kermit/sdk/batch/2022-01.15.0/batch github.com/tombuildsstuff/kermit/sdk/botservice/2021-05-01-preview/botservice github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute github.com/tombuildsstuff/kermit/sdk/datafactory/2018-06-01/datafactory +github.com/tombuildsstuff/kermit/sdk/iotcentral/2022-10-31-preview/iotcentral github.com/tombuildsstuff/kermit/sdk/iothub/2022-04-30-preview/iothub github.com/tombuildsstuff/kermit/sdk/keyvault/7.4/keyvault github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network diff --git a/website/docs/r/iotcentral_organization.html.markdown b/website/docs/r/iotcentral_organization.html.markdown new file mode 100644 index 000000000000..e83b2595dd15 --- /dev/null +++ b/website/docs/r/iotcentral_organization.html.markdown @@ -0,0 +1,81 @@ +--- +subcategory: "IoT Central" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_iotcentral_organization" +description: |- + Manages an IotCentral Organization +--- + +# azurerm_iotcentral_organization + +Manages an IoT Central Organization + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resource" + location = "West Europe" +} + +resource "azurerm_iotcentral_application" "example" { + name = "example-iotcentral-app" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + sub_domain = "example-iotcentral-app-subdomain" + display_name = "example-iotcentral-app-display-name" + sku = "ST1" + template = "iotc-default@1.0.0" + tags = { + Foo = "Bar" + } +} + +resource "azurerm_iotcentral_organization" "example_parent" { + iotcentral_application_id = azurerm_iotcentral_application.example.id + organization_id = "example-parent-organization-id" + display_name = "Org example parent" +} + +resource "azurerm_iotcentral_organization" "example" { + iotcentral_application_id = azurerm_iotcentral_application.example.id + organization_id = "example-child-organization-id" + display_name = "Org example" + parent_organization_id = azurerm_iotcentral_organization.example_parent.organization_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `iotcentral_application_id` - (Required) The application `id`. Changing this forces a new resource to be created. + +* `organization_id` - The ID of the organization. Changing this forces a new resource to be created. + +* `display_name` - (Required) Custom `display_name` for the organization. + +* `parent_organization_id` - (Optional) The `organization_id` of the parent organization. Changing this forces a new resource to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID reference of the organization, formated as `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.IoTCentral/iotApps/{application}/organizations/{organizationId}`. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the IoT Central Organization. +* `update` - (Defaults to 30 minutes) Used when updating the IoT Central Organization. +* `read` - (Defaults to 5 minutes) Used when retrieving the IoT Central Organization. +* `delete` - (Defaults to 30 minutes) Used when deleting the IoT Central Organization. + +## Import + +The IoT Central Organization can be imported using the `id`, e.g. + +```shell +terraform import azurerm_iotcentral_organization.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.IoTCentral/iotApps/example/organizations/example +```