|
| 1 | +package prometheusrulegroupresources |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" |
| 9 | + "github.com/hashicorp/go-azure-sdk/sdk/client" |
| 10 | + "github.com/hashicorp/go-azure-sdk/sdk/odata" |
| 11 | +) |
| 12 | + |
| 13 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 14 | +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. |
| 15 | + |
| 16 | +type PrometheusRuleGroupsListByResourceGroupOperationResponse struct { |
| 17 | + HttpResponse *http.Response |
| 18 | + OData *odata.OData |
| 19 | + Model *[]PrometheusRuleGroupResource |
| 20 | +} |
| 21 | + |
| 22 | +type PrometheusRuleGroupsListByResourceGroupCompleteResult struct { |
| 23 | + LatestHttpResponse *http.Response |
| 24 | + Items []PrometheusRuleGroupResource |
| 25 | +} |
| 26 | + |
| 27 | +type PrometheusRuleGroupsListByResourceGroupCustomPager struct { |
| 28 | + NextLink *odata.Link `json:"nextLink"` |
| 29 | +} |
| 30 | + |
| 31 | +func (p *PrometheusRuleGroupsListByResourceGroupCustomPager) NextPageLink() *odata.Link { |
| 32 | + defer func() { |
| 33 | + p.NextLink = nil |
| 34 | + }() |
| 35 | + |
| 36 | + return p.NextLink |
| 37 | +} |
| 38 | + |
| 39 | +// PrometheusRuleGroupsListByResourceGroup ... |
| 40 | +func (c PrometheusRuleGroupResourcesClient) PrometheusRuleGroupsListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result PrometheusRuleGroupsListByResourceGroupOperationResponse, err error) { |
| 41 | + opts := client.RequestOptions{ |
| 42 | + ContentType: "application/json; charset=utf-8", |
| 43 | + ExpectedStatusCodes: []int{ |
| 44 | + http.StatusOK, |
| 45 | + }, |
| 46 | + HttpMethod: http.MethodGet, |
| 47 | + Pager: &PrometheusRuleGroupsListByResourceGroupCustomPager{}, |
| 48 | + Path: fmt.Sprintf("%s/providers/Microsoft.AlertsManagement/prometheusRuleGroups", id.ID()), |
| 49 | + } |
| 50 | + |
| 51 | + req, err := c.Client.NewRequest(ctx, opts) |
| 52 | + if err != nil { |
| 53 | + return |
| 54 | + } |
| 55 | + |
| 56 | + var resp *client.Response |
| 57 | + resp, err = req.ExecutePaged(ctx) |
| 58 | + if resp != nil { |
| 59 | + result.OData = resp.OData |
| 60 | + result.HttpResponse = resp.Response |
| 61 | + } |
| 62 | + if err != nil { |
| 63 | + return |
| 64 | + } |
| 65 | + |
| 66 | + var values struct { |
| 67 | + Values *[]PrometheusRuleGroupResource `json:"value"` |
| 68 | + } |
| 69 | + if err = resp.Unmarshal(&values); err != nil { |
| 70 | + return |
| 71 | + } |
| 72 | + |
| 73 | + result.Model = values.Values |
| 74 | + |
| 75 | + return |
| 76 | +} |
| 77 | + |
| 78 | +// PrometheusRuleGroupsListByResourceGroupComplete retrieves all the results into a single object |
| 79 | +func (c PrometheusRuleGroupResourcesClient) PrometheusRuleGroupsListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (PrometheusRuleGroupsListByResourceGroupCompleteResult, error) { |
| 80 | + return c.PrometheusRuleGroupsListByResourceGroupCompleteMatchingPredicate(ctx, id, PrometheusRuleGroupResourceOperationPredicate{}) |
| 81 | +} |
| 82 | + |
| 83 | +// PrometheusRuleGroupsListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate |
| 84 | +func (c PrometheusRuleGroupResourcesClient) PrometheusRuleGroupsListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate PrometheusRuleGroupResourceOperationPredicate) (result PrometheusRuleGroupsListByResourceGroupCompleteResult, err error) { |
| 85 | + items := make([]PrometheusRuleGroupResource, 0) |
| 86 | + |
| 87 | + resp, err := c.PrometheusRuleGroupsListByResourceGroup(ctx, id) |
| 88 | + if err != nil { |
| 89 | + result.LatestHttpResponse = resp.HttpResponse |
| 90 | + err = fmt.Errorf("loading results: %+v", err) |
| 91 | + return |
| 92 | + } |
| 93 | + if resp.Model != nil { |
| 94 | + for _, v := range *resp.Model { |
| 95 | + if predicate.Matches(v) { |
| 96 | + items = append(items, v) |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + result = PrometheusRuleGroupsListByResourceGroupCompleteResult{ |
| 102 | + LatestHttpResponse: resp.HttpResponse, |
| 103 | + Items: items, |
| 104 | + } |
| 105 | + return |
| 106 | +} |
0 commit comments