Debian Codegraph @

example/azuread-auth/main.go

raw symbols SCIP
1 package mainscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/
2
3 import (
4 "contextscip-go gomod github.com/golang/go/src go1.13 context/"
5 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
6 "logscip-go gomod github.com/golang/go/src go1.13 log/"
7 "net/httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/"
8 "osscip-go gomod github.com/golang/go/src go1.13 os/"
9
10 "github.com/Azure/go-autorest/autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/"
11 "github.com/hashicorp/go-azure-helpers/authenticationscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/"
12 "github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/"
13 )
14
15 func mainscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/main().() {
16 logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] Started..")
17
18 // NOTE: fill this in
19 storageAccountName := "example"
20
21 logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] Building Client..")
22 client, err := buildClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/buildClient().()
23 if err != nil {
24 panic(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error building client: %s", err))
25 }
26
27 ctx := contextscip-go gomod github.com/golang/go/src go1.13 context/.TODOscip-go gomod github.com/golang/go/src go1.13 context/TODO().()
28 containerName := "armauth"
29 input := containersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/.CreateInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/CreateInput#{
30 AccessLevelscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/CreateInput#AccessLevel.: containersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/.Privatescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/Private.,
31 MetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/CreateInput#MetaData.: map[string]string{
32 "hello": "world",
33 },
34 }
35 logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] Creating Container..")
36 if _, err := client.ContainersClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#ContainersClient..Createscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/Client#Create().(ctx, storageAccountName, containerName, input); err != nil {
37 panic(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error creating container: %s", err))
38 }
39
40 logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] Retrieving Container..")
41 container, err := client.ContainersClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#ContainersClient..GetPropertiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/Client#GetProperties().(ctx, storageAccountName, containerName)
42 if err != nil {
43 panic(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error reading properties for container: %s", err))
44 }
45
46 logscip-go gomod github.com/golang/go/src go1.13 log/.Printfscip-go gomod github.com/golang/go/src go1.13 log/Printf().("[DEBUG] MetaData: %+v", container.MetaDatascip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/ContainerProperties#MetaData.)
47 }
48
49 type Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client# struct {
50 ContainersClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#ContainersClient. containersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/Client#
51 }
52
53 func buildClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/buildClient().() (*Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#, error) {
54 // we're using github.com/hashicorp/go-azure-helpers since it makes this simpler
55 // but you can use an Authorizer from github.com/Azure/go-autorest directly too
56 builder := &authenticationscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/.Builderscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#{
57 SubscriptionIDscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#SubscriptionID.: osscip-go gomod github.com/golang/go/src go1.13 os/.Getenvscip-go gomod github.com/golang/go/src go1.13 os/Getenv().("ARM_SUBSCRIPTION_ID"),
58 ClientIDscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#ClientID.: osscip-go gomod github.com/golang/go/src go1.13 os/.Getenvscip-go gomod github.com/golang/go/src go1.13 os/Getenv().("ARM_CLIENT_ID"),
59 ClientSecretscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#ClientSecret.: osscip-go gomod github.com/golang/go/src go1.13 os/.Getenvscip-go gomod github.com/golang/go/src go1.13 os/Getenv().("ARM_CLIENT_SECRET"),
60 TenantIDscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#TenantID.: osscip-go gomod github.com/golang/go/src go1.13 os/.Getenvscip-go gomod github.com/golang/go/src go1.13 os/Getenv().("ARM_TENANT_ID"),
61 Environmentscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#Environment.: osscip-go gomod github.com/golang/go/src go1.13 os/.Getenvscip-go gomod github.com/golang/go/src go1.13 os/Getenv().("ARM_ENVIRONMENT"),
62
63 // Feature Toggles
64 SupportsClientSecretAuthscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#SupportsClientSecretAuth.: true,
65 SupportsAzureCliTokenscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#SupportsAzureCliToken.: true,
66 }
67
68 config, err := builder.Buildscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Builder#Build().()
69 if err != nil {
70 return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error building AzureRM Client: %s", err)
71 }
72
73 env, err := authenticationscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/.DetermineEnvironmentscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/DetermineEnvironment().(config.Environmentscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Config#Environment.)
74 if err != nil {
75 return nil, err
76 }
77
78 oauthConfig, err := config.BuildOAuthConfigscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Config#BuildOAuthConfig().(env.ActiveDirectoryEndpointscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest/azure`/Environment#ActiveDirectoryEndpoint.)
79 if err != nil {
80 return nil, err
81 }
82
83 // OAuthConfigForTenant returns a pointer, which can be nil.
84 if oauthConfig == nil {
85 return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unable to configure OAuthConfig for tenant %s", config.TenantIDscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Config#TenantID.)
86 }
87
88 // support for HTTP Proxies
89 sender := autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.DecorateSenderscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/DecorateSender().(&httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.13 `net/http`/Client#{
90 Transportscip-go gomod github.com/golang/go/src go1.13 `net/http`/Client#Transport.: &httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Transportscip-go gomod github.com/golang/go/src go1.13 `net/http`/Transport#{
91 Proxyscip-go gomod github.com/golang/go/src go1.13 `net/http`/Transport#Proxy.: httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.ProxyFromEnvironmentscip-go gomod github.com/golang/go/src go1.13 `net/http`/ProxyFromEnvironment().,
92 },
93 })
94
95 storageAuth, err := config.GetAuthorizationTokenscip-go gomod github.com/hashicorp/go-azure-helpers v0.12.0 `github.com/hashicorp/go-azure-helpers/authentication`/Config#GetAuthorizationToken().(sender, oauthConfig, "https://storage.azure.com/")
96 if err != nil {
97 return nil, err
98 }
99
100 containersClient := containersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/.Newscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/New().()
101 containersClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers`/Client#Client..Authorizerscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/Client#Authorizer. = storageAuth
102
103 result := &Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#{
104 ContainersClientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/example/azuread-auth`/Client#ContainersClient.: containersClient,
105 }
106
107 return result, nil
108 }