1 package dtl
2
3
4
5
6
7
8
9 import (
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
19 type CostsClient struct {
20 BaseClient
21 }
22
23
24 func NewCostsClient(subscriptionID string) CostsClient {
25 return NewCostsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewCostsClientWithBaseURI(baseURI string, subscriptionID string) CostsClient {
31 return CostsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client CostsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, labCost LabCost) (result LabCost, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/CostsClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.Response.Response != nil {
46 sc = result.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: labCost,
53 Constraints: []validation.Constraint{{Target: "labCost.LabCostProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
54 return result, validation.NewError("dtl.CostsClient", "CreateOrUpdate", err.Error())
55 }
56
57 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, labCost)
58 if err != nil {
59 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", nil, "Failure preparing request")
60 return
61 }
62
63 resp, err := client.CreateOrUpdateSender(req)
64 if err != nil {
65 result.Response = autorest.Response{Response: resp}
66 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", resp, "Failure sending request")
67 return
68 }
69
70 result, err = client.CreateOrUpdateResponder(resp)
71 if err != nil {
72 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "CreateOrUpdate", resp, "Failure responding to request")
73 return
74 }
75
76 return
77 }
78
79
80 func (client CostsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labCost LabCost) (*http.Request, error) {
81 pathParameters := map[string]interface{}{
82 "labName": autorest.Encode("path", labName),
83 "name": autorest.Encode("path", name),
84 "resourceGroupName": autorest.Encode("path", resourceGroupName),
85 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
86 }
87
88 const APIVersion = "2018-09-15"
89 queryParameters := map[string]interface{}{
90 "api-version": APIVersion,
91 }
92
93 preparer := autorest.CreatePreparer(
94 autorest.AsContentType("application/json; charset=utf-8"),
95 autorest.AsPut(),
96 autorest.WithBaseURL(client.BaseURI),
97 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}", pathParameters),
98 autorest.WithJSON(labCost),
99 autorest.WithQueryParameters(queryParameters))
100 return preparer.Prepare((&http.Request{}).WithContext(ctx))
101 }
102
103
104
105 func (client CostsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
106 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
107 }
108
109
110
111 func (client CostsClient) CreateOrUpdateResponder(resp *http.Response) (result LabCost, err error) {
112 err = autorest.Respond(
113 resp,
114 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
115 autorest.ByUnmarshallingJSON(&result),
116 autorest.ByClosing())
117 result.Response = autorest.Response{Response: resp}
118 return
119 }
120
121
122
123
124
125
126
127 func (client CostsClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result LabCost, err error) {
128 if tracing.IsEnabled() {
129 ctx = tracing.StartSpan(ctx, fqdn+"/CostsClient.Get")
130 defer func() {
131 sc := -1
132 if result.Response.Response != nil {
133 sc = result.Response.Response.StatusCode
134 }
135 tracing.EndSpan(ctx, sc, err)
136 }()
137 }
138 req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
139 if err != nil {
140 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", nil, "Failure preparing request")
141 return
142 }
143
144 resp, err := client.GetSender(req)
145 if err != nil {
146 result.Response = autorest.Response{Response: resp}
147 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", resp, "Failure sending request")
148 return
149 }
150
151 result, err = client.GetResponder(resp)
152 if err != nil {
153 err = autorest.NewErrorWithError(err, "dtl.CostsClient", "Get", resp, "Failure responding to request")
154 return
155 }
156
157 return
158 }
159
160
161 func (client CostsClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
162 pathParameters := map[string]interface{}{
163 "labName": autorest.Encode("path", labName),
164 "name": autorest.Encode("path", name),
165 "resourceGroupName": autorest.Encode("path", resourceGroupName),
166 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
167 }
168
169 const APIVersion = "2018-09-15"
170 queryParameters := map[string]interface{}{
171 "api-version": APIVersion,
172 }
173 if len(expand) > 0 {
174 queryParameters["$expand"] = autorest.Encode("query", expand)
175 }
176
177 preparer := autorest.CreatePreparer(
178 autorest.AsGet(),
179 autorest.WithBaseURL(client.BaseURI),
180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}", pathParameters),
181 autorest.WithQueryParameters(queryParameters))
182 return preparer.Prepare((&http.Request{}).WithContext(ctx))
183 }
184
185
186
187 func (client CostsClient) GetSender(req *http.Request) (*http.Response, error) {
188 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
189 }
190
191
192
193 func (client CostsClient) GetResponder(resp *http.Response) (result LabCost, err error) {
194 err = autorest.Respond(
195 resp,
196 azure.WithErrorUnlessStatusCode(http.StatusOK),
197 autorest.ByUnmarshallingJSON(&result),
198 autorest.ByClosing())
199 result.Response = autorest.Response{Response: resp}
200 return
201 }
202
View as plain text