Files
threshold/testing/internal/e2e/boundary/authtoken.go
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

37 lines
1.0 KiB
Go

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: BUSL-1.1
package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/hashicorp/boundary/api/authtokens"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
)
// GetAuthenticationTokenIdByTokenNameCli uses the CLI to get an auth-token ID by its name
// The operation is performed by the user associated with the auth-token
func GetAuthenticationTokenIdByTokenNameCli(t testing.TB, ctx context.Context, tokenName string) string {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-tokens", "list",
"-token-name", tokenName,
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var authTokenListResult authtokens.AuthTokenListResult
err := json.Unmarshal(output.Stdout, &authTokenListResult)
require.NoError(t, err)
userAuthTokenID := fmt.Sprint(authTokenListResult.Items[0].Id)
t.Logf("Retrieved Auth-Token: %s", userAuthTokenID)
return userAuthTokenID
}