Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto PR: Regenerating the Go SDK (1373d8f9d831caca88b5c676e8dc8f5639c68cee) #911

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 15 additions & 7 deletions resource-manager/insights/2015-04-01/activitylogs/client.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package activitylogs

import "github.com/Azure/go-autorest/autorest"
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments"
)

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.

type ActivityLogsClient struct {
Client autorest.Client
baseUri string
Client *resourcemanager.Client
}

func NewActivityLogsClientWithBaseURI(endpoint string) ActivityLogsClient {
return ActivityLogsClient{
Client: autorest.NewClientWithUserAgent(userAgent()),
baseUri: endpoint,
func NewActivityLogsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActivityLogsClient, error) {
client, err := resourcemanager.NewResourceManagerClient(sdkApi, "activitylogs", defaultApiVersion)
if err != nil {
return nil, fmt.Errorf("instantiating ActivityLogsClient: %+v", err)
}

return &ActivityLogsClient{
Client: client,
}, nil
}
19 changes: 18 additions & 1 deletion resource-manager/insights/2015-04-01/activitylogs/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package activitylogs

import "strings"
import (
"encoding/json"
"fmt"
"strings"
)

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.
Expand All @@ -25,6 +29,19 @@ func PossibleValuesForEventLevel() []string {
}
}

func (s *EventLevel) UnmarshalJSON(bytes []byte) error {
var decoded string
if err := json.Unmarshal(bytes, &decoded); err != nil {
return fmt.Errorf("unmarshaling: %+v", err)
}
out, err := parseEventLevel(decoded)
if err != nil {
return fmt.Errorf("parsing %q: %+v", decoded, err)
}
*s = *out
return nil
}

func parseEventLevel(input string) (*EventLevel, error) {
vals := map[string]EventLevel{
"critical": EventLevelCritical,
Expand Down
124 changes: 124 additions & 0 deletions resource-manager/insights/2015-04-01/activitylogs/method_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package activitylogs

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.

type ListOperationResponse struct {
HttpResponse *http.Response
OData *odata.OData
Model *[]EventData
}

type ListCompleteResult struct {
LatestHttpResponse *http.Response
Items []EventData
}

type ListOperationOptions struct {
Filter *string
Select *string
}

func DefaultListOperationOptions() ListOperationOptions {
return ListOperationOptions{}
}

func (o ListOperationOptions) ToHeaders() *client.Headers {
out := client.Headers{}

return &out
}

func (o ListOperationOptions) ToOData() *odata.Query {
out := odata.Query{}
return &out
}

func (o ListOperationOptions) ToQuery() *client.QueryParams {
out := client.QueryParams{}
if o.Filter != nil {
out.Append("$filter", fmt.Sprintf("%v", *o.Filter))
}
if o.Select != nil {
out.Append("$select", fmt.Sprintf("%v", *o.Select))
}
return &out
}

// List ...
func (c ActivityLogsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodGet,
Path: fmt.Sprintf("%s/providers/Microsoft.Insights/eventtypes/management/values", id.ID()),
OptionsObject: options,
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
return
}

var resp *client.Response
resp, err = req.ExecutePaged(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

var values struct {
Values *[]EventData `json:"value"`
}
if err = resp.Unmarshal(&values); err != nil {
return
}

result.Model = values.Values

return
}

// ListComplete retrieves all the results into a single object
func (c ActivityLogsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) {
return c.ListCompleteMatchingPredicate(ctx, id, options, EventDataOperationPredicate{})
}

// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate
func (c ActivityLogsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate EventDataOperationPredicate) (result ListCompleteResult, err error) {
items := make([]EventData, 0)

resp, err := c.List(ctx, id, options)
if err != nil {
err = fmt.Errorf("loading results: %+v", err)
return
}
if resp.Model != nil {
for _, v := range *resp.Model {
if predicate.Matches(v) {
items = append(items, v)
}
}
}

result = ListCompleteResult{
LatestHttpResponse: resp.HttpResponse,
Items: items,
}
return
}
Loading
Loading