github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/noauth/new_block_storage_no_auth.go (about) 1 package noauth 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/opentelekomcloud/gophertelekomcloud" 8 ) 9 10 // EndpointOpts specifies a "noauth" Cinder Endpoint. 11 type EndpointOpts struct { 12 // CinderEndpoint [required] is currently only used with "noauth" Cinder. 13 // A cinder endpoint with "auth_strategy=noauth" is necessary, for example: 14 // http://example.com:8776/v2. 15 CinderEndpoint string 16 } 17 18 // NewClient prepares an unauthenticated ProviderClient instance. 19 func NewClient(options golangsdk.AuthOptions) (*golangsdk.ProviderClient, error) { 20 if options.Username == "" { 21 options.Username = "admin" 22 } 23 if options.TenantName == "" { 24 options.TenantName = "admin" 25 } 26 27 client := &golangsdk.ProviderClient{ 28 TokenID: fmt.Sprintf("%s:%s", options.Username, options.TenantName), 29 } 30 31 return client, nil 32 } 33 34 func NewBlockStorageNoAuth(client *golangsdk.ProviderClient, opts EndpointOpts) (*golangsdk.ServiceClient, error) { 35 sc := new(golangsdk.ServiceClient) 36 if opts.CinderEndpoint == "" { 37 return nil, fmt.Errorf("CinderEndpoint is required") 38 } 39 40 token := strings.Split(client.TokenID, ":") 41 if len(token) != 2 { 42 return nil, fmt.Errorf("Malformed noauth token") 43 } 44 45 sc.Endpoint = golangsdk.NormalizeURL(fmt.Sprintf("%s%s", golangsdk.NormalizeURL(opts.CinderEndpoint), token[1])) 46 sc.ProviderClient = client 47 return sc, nil 48 }