github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/azure/internal/azureauth/utils.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package azureauth 5 6 import ( 7 "net/url" 8 "strings" 9 ) 10 11 // ResourceManagerResourceId returns the resource ID for the 12 // Azure Resource Manager application to use in auth requests, 13 // based on the given core endpoint URI (e.g. https://core.windows.net). 14 // 15 // The core endpoint URI is the same as given in "storage-endpoint" 16 // in Azure cloud definitions, which serves as the suffix for blob 17 // storage URLs. 18 func ResourceManagerResourceId(coreEndpointURI string) (string, error) { 19 u, err := url.Parse(coreEndpointURI) 20 if err != nil { 21 return "", err 22 } 23 u.Host = "management." + u.Host 24 return TokenResource(u.String()), nil 25 } 26 27 // TokenResource returns a resource value suitable for auth tokens, based on 28 // an endpoint URI. 29 func TokenResource(uri string) string { 30 resource := uri 31 if !strings.HasSuffix(resource, "/") { 32 resource += "/" 33 } 34 return resource 35 }