Exemplo n.º 1
0
func TestAuthenticate(t *testing.T) {
	ao := v2AuthOptions(t)
	service := unauthenticatedClient(t)

	// Authenticated!
	result := tokens2.Create(service, tokens2.WrapOptions(ao))

	// Extract and print the token.
	token, err := result.ExtractToken()
	th.AssertNoErr(t, err)

	t.Logf("Acquired token: [%s]", token.ID)
	t.Logf("The token will expire at: [%s]", token.ExpiresAt.String())
	t.Logf("The token is valid for tenant: [%#v]", token.Tenant)

	// Extract and print the service catalog.
	catalog, err := result.ExtractServiceCatalog()
	th.AssertNoErr(t, err)

	t.Logf("Acquired service catalog listing [%d] services", len(catalog.Entries))
	for i, entry := range catalog.Entries {
		t.Logf("[%02d]: name=[%s], type=[%s]", i, entry.Name, entry.Type)
		for _, endpoint := range entry.Endpoints {
			t.Logf("      - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL)
		}
	}
}
Exemplo n.º 2
0
func CreateToken(a gophercloud.AuthOptions, c *gophercloud.ServiceClient) (*tokens.Token, error) {
	opts := tokens.WrapOptions(a)

	// Create a new token
	token, err := tokens.Create(c, opts).ExtractToken()
	if err != nil {
		return nil, err
	}

	return token, nil
}
Exemplo n.º 3
0
func TestAuthenticateAndValidate(t *testing.T) {
	// 1. TestAuthenticate
	ao := v2AuthOptions(t)
	service := unauthenticatedClient(t)

	// Authenticated!
	result := tokens2.Create(service, tokens2.WrapOptions(ao))

	// Extract and print the token.
	token, err := result.ExtractToken()
	th.AssertNoErr(t, err)

	t.Logf("Acquired token: [%s]", token.ID)
	t.Logf("The token will expire at: [%s]", token.ExpiresAt.String())
	t.Logf("The token is valid for tenant: [%#v]", token.Tenant)

	// Extract and print the service catalog.
	catalog, err := result.ExtractServiceCatalog()
	th.AssertNoErr(t, err)

	t.Logf("Acquired service catalog listing [%d] services", len(catalog.Entries))
	for i, entry := range catalog.Entries {
		t.Logf("[%02d]: name=[%s], type=[%s]", i, entry.Name, entry.Type)
		for _, endpoint := range entry.Endpoints {
			t.Logf("      - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL)
		}
	}

	// 2. TestValidate
	client := authenticatedClient(t)

	// Validate Token!
	getResult := tokens2.Get(client, token.ID)

	// Extract and print the user.
	user, err := getResult.ExtractUser()
	th.AssertNoErr(t, err)

	t.Logf("Acquired User: [%s]", user.Name)
	t.Logf("The User id: [%s]", user.ID)
	t.Logf("The User username: [%s]", user.UserName)
	t.Logf("The User roles: [%#v]", user.Roles)
}
Exemplo n.º 4
0
// WrapOptions embeds a root AuthOptions struct in a package-specific one.
func WrapOptions(original gophercloud.AuthOptions) AuthOptions {
	return AuthOptions{AuthOptions: os.WrapOptions(original)}
}