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 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) {
67 if tracing.IsEnabled() {
68 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
69 defer func() {
70 sc := -1
71 if result.elr.Response.Response != nil {
72 sc = result.elr.Response.Response.StatusCode
73 }
74 tracing.EndSpan(ctx, sc, err)
75 }()
76 }
77 result.fn = client.listNextResults
78 req, err := client.ListPreparer(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
79 if err != nil {
80 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", nil, "Failure preparing request")
81 return
82 }
83
84 resp, err := client.ListSender(req)
85 if err != nil {
86 result.elr.Response = autorest.Response{Response: resp}
87 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure sending request")
88 return
89 }
90
91 result.elr, err = client.ListResponder(resp)
92 if err != nil {
93 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure responding to request")
94 return
95 }
96 if result.elr.hasNextLink() && result.elr.IsEmpty() {
97 err = result.NextWithContext(ctx)
98 return
99 }
100
101 return
102 }
103
104
105 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) {
106 const APIVersion = "2019-11-01"
107 queryParameters := map[string]interface{}{
108 "api-version": APIVersion,
109 }
110 if len(skiptoken) > 0 {
111 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
112 }
113 if skip != nil {
114 queryParameters["$skip"] = autorest.Encode("query", *skip)
115 }
116 if top != nil {
117 queryParameters["$top"] = autorest.Encode("query", *top)
118 }
119 if len(selectParameter) > 0 {
120 queryParameters["$select"] = autorest.Encode("query", selectParameter)
121 }
122 if len(string(search)) > 0 {
123 queryParameters["$search"] = autorest.Encode("query", search)
124 }
125 if len(filter) > 0 {
126 queryParameters["$filter"] = autorest.Encode("query", filter)
127 }
128 if len(string(view)) > 0 {
129 queryParameters["$view"] = autorest.Encode("query", view)
130 }
131 if len(groupName) > 0 {
132 queryParameters["groupName"] = autorest.Encode("query", groupName)
133 }
134
135 preparer := autorest.CreatePreparer(
136 autorest.AsPost(),
137 autorest.WithBaseURL(client.BaseURI),
138 autorest.WithPath("/providers/Microsoft.Management/getEntities"),
139 autorest.WithQueryParameters(queryParameters))
140 if len(cacheControl) > 0 {
141 preparer = autorest.DecoratePreparer(preparer,
142 autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
143 } else {
144 preparer = autorest.DecoratePreparer(preparer,
145 autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
146 }
147 return preparer.Prepare((&http.Request{}).WithContext(ctx))
148 }
149
150
151
152 func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) {
153 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
154 }
155
156
157
158 func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityListResult, err error) {
159 err = autorest.Respond(
160 resp,
161 azure.WithErrorUnlessStatusCode(http.StatusOK),
162 autorest.ByUnmarshallingJSON(&result),
163 autorest.ByClosing())
164 result.Response = autorest.Response{Response: resp}
165 return
166 }
167
168
169 func (client EntitiesClient) listNextResults(ctx context.Context, lastResults EntityListResult) (result EntityListResult, err error) {
170 req, err := lastResults.entityListResultPreparer(ctx)
171 if err != nil {
172 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", nil, "Failure preparing next results request")
173 }
174 if req == nil {
175 return
176 }
177 resp, err := client.ListSender(req)
178 if err != nil {
179 result.Response = autorest.Response{Response: resp}
180 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure sending next results request")
181 }
182 result, err = client.ListResponder(resp)
183 if err != nil {
184 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure responding to next results request")
185 }
186 return
187 }
188
189
190 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) {
191 if tracing.IsEnabled() {
192 ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
193 defer func() {
194 sc := -1
195 if result.Response().Response.Response != nil {
196 sc = result.page.Response().Response.Response.StatusCode
197 }
198 tracing.EndSpan(ctx, sc, err)
199 }()
200 }
201 result.page, err = client.List(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
202 return
203 }
204
View as plain text