1 package managementgroups
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/tracing"
14 "net/http"
15 )
16
17
18
19
20 type EntitiesClient struct {
21 BaseClient
22 }
23
24
25 func NewEntitiesClient() EntitiesClient {
26 return NewEntitiesClientWithBaseURI(DefaultBaseURI)
27 }
28
29
30
31 func NewEntitiesClientWithBaseURI(baseURI string) EntitiesClient {
32 return EntitiesClient{NewWithBaseURI(baseURI)}
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 func (client EntitiesClient) List(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (result EntityListResultPage, err error) {
70 if tracing.IsEnabled() {
71 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
72 defer func() {
73 sc := -1
74 if result.elr.Response.Response != nil {
75 sc = result.elr.Response.Response.StatusCode
76 }
77 tracing.EndSpan(ctx, sc, err)
78 }()
79 }
80 result.fn = client.listNextResults
81 req, err := client.ListPreparer(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
82 if err != nil {
83 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", nil, "Failure preparing request")
84 return
85 }
86
87 resp, err := client.ListSender(req)
88 if err != nil {
89 result.elr.Response = autorest.Response{Response: resp}
90 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure sending request")
91 return
92 }
93
94 result.elr, err = client.ListResponder(resp)
95 if err != nil {
96 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure responding to request")
97 return
98 }
99 if result.elr.hasNextLink() && result.elr.IsEmpty() {
100 err = result.NextWithContext(ctx)
101 return
102 }
103
104 return
105 }
106
107
108 func (client EntitiesClient) ListPreparer(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (*http.Request, error) {
109 const APIVersion = "2020-05-01"
110 queryParameters := map[string]interface{}{
111 "api-version": APIVersion,
112 }
113 if len(skiptoken) > 0 {
114 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
115 }
116 if skip != nil {
117 queryParameters["$skip"] = autorest.Encode("query", *skip)
118 }
119 if top != nil {
120 queryParameters["$top"] = autorest.Encode("query", *top)
121 }
122 if len(selectParameter) > 0 {
123 queryParameters["$select"] = autorest.Encode("query", selectParameter)
124 }
125 if len(string(search)) > 0 {
126 queryParameters["$search"] = autorest.Encode("query", search)
127 }
128 if len(filter) > 0 {
129 queryParameters["$filter"] = autorest.Encode("query", filter)
130 }
131 if len(string(view)) > 0 {
132 queryParameters["$view"] = autorest.Encode("query", view)
133 }
134 if len(groupName) > 0 {
135 queryParameters["groupName"] = autorest.Encode("query", groupName)
136 }
137
138 preparer := autorest.CreatePreparer(
139 autorest.AsPost(),
140 autorest.WithBaseURL(client.BaseURI),
141 autorest.WithPath("/providers/Microsoft.Management/getEntities"),
142 autorest.WithQueryParameters(queryParameters))
143 if len(cacheControl) > 0 {
144 preparer = autorest.DecoratePreparer(preparer,
145 autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
146 } else {
147 preparer = autorest.DecoratePreparer(preparer,
148 autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
149 }
150 return preparer.Prepare((&http.Request{}).WithContext(ctx))
151 }
152
153
154
155 func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) {
156 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
157 }
158
159
160
161 func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityListResult, err error) {
162 err = autorest.Respond(
163 resp,
164 azure.WithErrorUnlessStatusCode(http.StatusOK),
165 autorest.ByUnmarshallingJSON(&result),
166 autorest.ByClosing())
167 result.Response = autorest.Response{Response: resp}
168 return
169 }
170
171
172 func (client EntitiesClient) listNextResults(ctx context.Context, lastResults EntityListResult) (result EntityListResult, err error) {
173 req, err := lastResults.entityListResultPreparer(ctx)
174 if err != nil {
175 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", nil, "Failure preparing next results request")
176 }
177 if req == nil {
178 return
179 }
180 resp, err := client.ListSender(req)
181 if err != nil {
182 result.Response = autorest.Response{Response: resp}
183 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure sending next results request")
184 }
185 result, err = client.ListResponder(resp)
186 if err != nil {
187 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure responding to next results request")
188 }
189 return
190 }
191
192
193 func (client EntitiesClient) ListComplete(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (result EntityListResultIterator, err error) {
194 if tracing.IsEnabled() {
195 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
196 defer func() {
197 sc := -1
198 if result.Response().Response.Response != nil {
199 sc = result.page.Response().Response.Response.StatusCode
200 }
201 tracing.EndSpan(ctx, sc, err)
202 }()
203 }
204 result.page, err = client.List(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
205 return
206 }
207
View as plain text