Created
August 17, 2018 14:36
-
-
Save TheoBrigitte/9d1fadca91c69c337f6ff467599db848 to your computer and use it in GitHub Desktop.
Program used to Azure API $filter query parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" | |
"github.com/Azure/go-autorest/autorest" | |
"github.com/Azure/go-autorest/autorest/adal" | |
"github.com/Azure/go-autorest/autorest/azure" | |
) | |
const ( | |
azureClientID = "<your azure client id>" | |
azureClientSecret = "<your azure secret key>" | |
azureSubscriptionID = "<your azure subscription id>" | |
azureTenantID = "<your azure tenant id>" | |
) | |
func NewGroupsClient() (*resources.GroupsClient, error) { | |
env := azure.PublicCloud | |
oauthConfig, err := adal.NewOAuthConfig(env.ActiveDirectoryEndpoint, azureTenantID) | |
if err != nil { | |
return nil, err | |
} | |
token, err := adal.NewServicePrincipalToken(*oauthConfig, azureClientID, azureClientSecret, env.ServiceManagementEndpoint) | |
if err != nil { | |
return nil, err | |
} | |
client := resources.NewGroupsClient(azureSubscriptionID) | |
client.Authorizer = autorest.NewBearerAuthorizer(token) | |
return &client, nil | |
} | |
func main() { | |
log.Println("start") | |
groupsClient, err := NewGroupsClient() | |
if err != nil { | |
panic(err) | |
} | |
ctx := context.Background() | |
list, err := groupsClient.List(ctx, "name eq 'foo'", nil) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("name\n") | |
for ; list.NotDone(); list.Next() { | |
for _, group := range list.Values() { | |
fmt.Printf("%s\n", *group.Name) | |
} | |
} | |
log.Println("end") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download this file and replace Azure credentials at the top.
Then run
It should panic with a similar error