1package storagesync
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// WorkflowsClient is the microsoft Storage Sync Service API
19type WorkflowsClient struct {
20	BaseClient
21}
22
23// NewWorkflowsClient creates an instance of the WorkflowsClient client.
24func NewWorkflowsClient(subscriptionID string) WorkflowsClient {
25	return NewWorkflowsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewWorkflowsClientWithBaseURI creates an instance of the WorkflowsClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewWorkflowsClientWithBaseURI(baseURI string, subscriptionID string) WorkflowsClient {
31	return WorkflowsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Abort abort the given workflow.
35// Parameters:
36// resourceGroupName - the name of the resource group. The name is case insensitive.
37// storageSyncServiceName - name of Storage Sync Service resource.
38// workflowID - workflow Id
39func (client WorkflowsClient) Abort(ctx context.Context, resourceGroupName string, storageSyncServiceName string, workflowID string) (result autorest.Response, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/WorkflowsClient.Abort")
42		defer func() {
43			sc := -1
44			if result.Response != nil {
45				sc = result.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: client.SubscriptionID,
52			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
53		{TargetValue: resourceGroupName,
54			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
55				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("storagesync.WorkflowsClient", "Abort", err.Error())
58	}
59
60	req, err := client.AbortPreparer(ctx, resourceGroupName, storageSyncServiceName, workflowID)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Abort", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.AbortSender(req)
67	if err != nil {
68		result.Response = resp
69		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Abort", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.AbortResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Abort", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// AbortPreparer prepares the Abort request.
83func (client WorkflowsClient) AbortPreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, workflowID string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
86		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
87		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
88		"workflowId":             autorest.Encode("path", workflowID),
89	}
90
91	const APIVersion = "2019-10-01"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsPost(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/workflows/{workflowId}/abort", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// AbortSender sends the Abort request. The method will close the
105// http.Response Body if it receives an error.
106func (client WorkflowsClient) AbortSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// AbortResponder handles the response to the Abort request. The method always
111// closes the http.Response Body.
112func (client WorkflowsClient) AbortResponder(resp *http.Response) (result autorest.Response, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByClosing())
117	result.Response = resp
118	return
119}
120
121// Get get Workflows resource
122// Parameters:
123// resourceGroupName - the name of the resource group. The name is case insensitive.
124// storageSyncServiceName - name of Storage Sync Service resource.
125// workflowID - workflow Id
126func (client WorkflowsClient) Get(ctx context.Context, resourceGroupName string, storageSyncServiceName string, workflowID string) (result Workflow, err error) {
127	if tracing.IsEnabled() {
128		ctx = tracing.StartSpan(ctx, fqdn+"/WorkflowsClient.Get")
129		defer func() {
130			sc := -1
131			if result.Response.Response != nil {
132				sc = result.Response.Response.StatusCode
133			}
134			tracing.EndSpan(ctx, sc, err)
135		}()
136	}
137	if err := validation.Validate([]validation.Validation{
138		{TargetValue: client.SubscriptionID,
139			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
140		{TargetValue: resourceGroupName,
141			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
142				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
143				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
144		return result, validation.NewError("storagesync.WorkflowsClient", "Get", err.Error())
145	}
146
147	req, err := client.GetPreparer(ctx, resourceGroupName, storageSyncServiceName, workflowID)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Get", nil, "Failure preparing request")
150		return
151	}
152
153	resp, err := client.GetSender(req)
154	if err != nil {
155		result.Response = autorest.Response{Response: resp}
156		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Get", resp, "Failure sending request")
157		return
158	}
159
160	result, err = client.GetResponder(resp)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "Get", resp, "Failure responding to request")
163		return
164	}
165
166	return
167}
168
169// GetPreparer prepares the Get request.
170func (client WorkflowsClient) GetPreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string, workflowID string) (*http.Request, error) {
171	pathParameters := map[string]interface{}{
172		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
173		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
174		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
175		"workflowId":             autorest.Encode("path", workflowID),
176	}
177
178	const APIVersion = "2019-10-01"
179	queryParameters := map[string]interface{}{
180		"api-version": APIVersion,
181	}
182
183	preparer := autorest.CreatePreparer(
184		autorest.AsGet(),
185		autorest.WithBaseURL(client.BaseURI),
186		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/workflows/{workflowId}", pathParameters),
187		autorest.WithQueryParameters(queryParameters))
188	return preparer.Prepare((&http.Request{}).WithContext(ctx))
189}
190
191// GetSender sends the Get request. The method will close the
192// http.Response Body if it receives an error.
193func (client WorkflowsClient) GetSender(req *http.Request) (*http.Response, error) {
194	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
195}
196
197// GetResponder handles the response to the Get request. The method always
198// closes the http.Response Body.
199func (client WorkflowsClient) GetResponder(resp *http.Response) (result Workflow, err error) {
200	err = autorest.Respond(
201		resp,
202		azure.WithErrorUnlessStatusCode(http.StatusOK),
203		autorest.ByUnmarshallingJSON(&result),
204		autorest.ByClosing())
205	result.Response = autorest.Response{Response: resp}
206	return
207}
208
209// ListByStorageSyncService get a Workflow List
210// Parameters:
211// resourceGroupName - the name of the resource group. The name is case insensitive.
212// storageSyncServiceName - name of Storage Sync Service resource.
213func (client WorkflowsClient) ListByStorageSyncService(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (result WorkflowArray, err error) {
214	if tracing.IsEnabled() {
215		ctx = tracing.StartSpan(ctx, fqdn+"/WorkflowsClient.ListByStorageSyncService")
216		defer func() {
217			sc := -1
218			if result.Response.Response != nil {
219				sc = result.Response.Response.StatusCode
220			}
221			tracing.EndSpan(ctx, sc, err)
222		}()
223	}
224	if err := validation.Validate([]validation.Validation{
225		{TargetValue: client.SubscriptionID,
226			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
227		{TargetValue: resourceGroupName,
228			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
229				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
230				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
231		return result, validation.NewError("storagesync.WorkflowsClient", "ListByStorageSyncService", err.Error())
232	}
233
234	req, err := client.ListByStorageSyncServicePreparer(ctx, resourceGroupName, storageSyncServiceName)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "ListByStorageSyncService", nil, "Failure preparing request")
237		return
238	}
239
240	resp, err := client.ListByStorageSyncServiceSender(req)
241	if err != nil {
242		result.Response = autorest.Response{Response: resp}
243		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "ListByStorageSyncService", resp, "Failure sending request")
244		return
245	}
246
247	result, err = client.ListByStorageSyncServiceResponder(resp)
248	if err != nil {
249		err = autorest.NewErrorWithError(err, "storagesync.WorkflowsClient", "ListByStorageSyncService", resp, "Failure responding to request")
250		return
251	}
252
253	return
254}
255
256// ListByStorageSyncServicePreparer prepares the ListByStorageSyncService request.
257func (client WorkflowsClient) ListByStorageSyncServicePreparer(ctx context.Context, resourceGroupName string, storageSyncServiceName string) (*http.Request, error) {
258	pathParameters := map[string]interface{}{
259		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
260		"storageSyncServiceName": autorest.Encode("path", storageSyncServiceName),
261		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
262	}
263
264	const APIVersion = "2019-10-01"
265	queryParameters := map[string]interface{}{
266		"api-version": APIVersion,
267	}
268
269	preparer := autorest.CreatePreparer(
270		autorest.AsGet(),
271		autorest.WithBaseURL(client.BaseURI),
272		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageSync/storageSyncServices/{storageSyncServiceName}/workflows", pathParameters),
273		autorest.WithQueryParameters(queryParameters))
274	return preparer.Prepare((&http.Request{}).WithContext(ctx))
275}
276
277// ListByStorageSyncServiceSender sends the ListByStorageSyncService request. The method will close the
278// http.Response Body if it receives an error.
279func (client WorkflowsClient) ListByStorageSyncServiceSender(req *http.Request) (*http.Response, error) {
280	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
281}
282
283// ListByStorageSyncServiceResponder handles the response to the ListByStorageSyncService request. The method always
284// closes the http.Response Body.
285func (client WorkflowsClient) ListByStorageSyncServiceResponder(resp *http.Response) (result WorkflowArray, err error) {
286	err = autorest.Respond(
287		resp,
288		azure.WithErrorUnlessStatusCode(http.StatusOK),
289		autorest.ByUnmarshallingJSON(&result),
290		autorest.ByClosing())
291	result.Response = autorest.Response{Response: resp}
292	return
293}
294