diff --git a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/connector.go b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/connector.go new file mode 100644 index 000000000000..d61f52e5fec3 --- /dev/null +++ b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/connector.go @@ -0,0 +1,113 @@ +package costmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ConnectorClient is the client for the Connector methods of the Costmanagement service. +type ConnectorClient struct { + BaseClient +} + +// NewConnectorClient creates an instance of the ConnectorClient client. +func NewConnectorClient(subscriptionID string) ConnectorClient { + return NewConnectorClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConnectorClientWithBaseURI creates an instance of the ConnectorClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewConnectorClientWithBaseURI(baseURI string, subscriptionID string) ConnectorClient { + return ConnectorClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CheckEligibility check if a connector already exists and return it's definition +// Parameters: +// connectorCredentials - connector credentials +func (client ConnectorClient) CheckEligibility(ctx context.Context, connectorCredentials CheckEligibilityDefinition) (result ConnectorDefinition, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConnectorClient.CheckEligibility") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CheckEligibilityPreparer(ctx, connectorCredentials) + if err != nil { + err = autorest.NewErrorWithError(err, "costmanagement.ConnectorClient", "CheckEligibility", nil, "Failure preparing request") + return + } + + resp, err := client.CheckEligibilitySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "costmanagement.ConnectorClient", "CheckEligibility", resp, "Failure sending request") + return + } + + result, err = client.CheckEligibilityResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "costmanagement.ConnectorClient", "CheckEligibility", resp, "Failure responding to request") + } + + return +} + +// CheckEligibilityPreparer prepares the CheckEligibility request. +func (client ConnectorClient) CheckEligibilityPreparer(ctx context.Context, connectorCredentials CheckEligibilityDefinition) (*http.Request, error) { + const APIVersion = "2019-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.CostManagement/checkConnectorEligibility"), + autorest.WithJSON(connectorCredentials), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckEligibilitySender sends the CheckEligibility request. The method will close the +// http.Response Body if it receives an error. +func (client ConnectorClient) CheckEligibilitySender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CheckEligibilityResponder handles the response to the CheckEligibility request. The method always +// closes the http.Response Body. +func (client ConnectorClient) CheckEligibilityResponder(resp *http.Response) (result ConnectorDefinition, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/costmanagementapi/interfaces.go b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/costmanagementapi/interfaces.go index 76abb2f64835..3a244a5c3bb4 100644 --- a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/costmanagementapi/interfaces.go +++ b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/costmanagementapi/interfaces.go @@ -71,6 +71,13 @@ type CloudConnectorClientAPI interface { var _ CloudConnectorClientAPI = (*costmanagement.CloudConnectorClient)(nil) +// ConnectorClientAPI contains the set of methods on the ConnectorClient type. +type ConnectorClientAPI interface { + CheckEligibility(ctx context.Context, connectorCredentials costmanagement.CheckEligibilityDefinition) (result costmanagement.ConnectorDefinition, err error) +} + +var _ ConnectorClientAPI = (*costmanagement.ConnectorClient)(nil) + // ExternalBillingAccountClientAPI contains the set of methods on the ExternalBillingAccountClient type. type ExternalBillingAccountClientAPI interface { Get(ctx context.Context, externalBillingAccountName string, expand string) (result costmanagement.ExternalBillingAccountDefinition, err error) diff --git a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/models.go b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/models.go index 65cd06482699..33e7e1f537c8 100644 --- a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/models.go +++ b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/models.go @@ -215,6 +215,18 @@ func PossibleTimeframeTypeValues() []TimeframeType { return []TimeframeType{Custom, MonthToDate, WeekToDate, YearToDate} } +// CheckEligibilityDefinition the check eligibility Connector credentials definition +type CheckEligibilityDefinition struct { + // Kind - Connector kind (eg aws) + Kind *string `json:"kind,omitempty"` + // CredentialsKey - Credentials authentication key (eg AWS ARN) + CredentialsKey *string `json:"credentialsKey,omitempty"` + // CredentialsSecret - Credentials secret (eg AWS ExternalId) + CredentialsSecret *string `json:"credentialsSecret,omitempty"` + // ReportID - Identifying source report. (For AWS this is a CUR report name, defined with Daily and with Resources) + ReportID *string `json:"reportId,omitempty"` +} + // ConnectorCollectionErrorInfo details of any error encountered on last collection attempt type ConnectorCollectionErrorInfo struct { // ErrorMessage - READ-ONLY; Detailed error message diff --git a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/version.go b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/version.go index 2e14d0bd0044..39b7b7442a4a 100644 --- a/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/version.go +++ b/services/preview/costmanagement/mgmt/2019-03-01/costmanagement/version.go @@ -21,7 +21,7 @@ import "github.com/Azure/azure-sdk-for-go/version" // UserAgent returns the UserAgent string to use when sending http.Requests. func UserAgent() string { - return "Azure-SDK-For-Go/" + version.Number + " costmanagement/2019-03-01-preview" + return "Azure-SDK-For-Go/" + Version() + " costmanagement/2019-03-01-preview" } // Version returns the semantic version (see http://semver.org) of the client.