* refact(e2e): Add err to CreateOrgApi * refact(e2e): Add err to CreateProjectApi * refact(e2e): Add err to CreateOrgCli * refact(e2e): Add err to CreateProjectCli * refact(e2e): Add err to CreateHostCatalogApi * refact(e2e): Add err to CreateHostSetApi * refact(e2e): Add err to CreateHostApi * refact(e2e): Add err to AddHostToHostSetApi * refact(e2e): Add err to CreateHostCatalogCli * refact(e2e): Add err to CreateHostSetCli * refact(e2e): Add err to CreateHostCli * refact(e2e): Add err to AddHostToHostSetCli * refact(e2e): Add err to CreateAwsHostCatalogCli * refact(e2e): Add err to CreateAwsHostSetCli * refact(e2e): Add err to CreateTargetApi * refact(e2e): Add err to AddHostSourceToTargetApi * refact(e2e): Add err to CreateTargetCli * refact(e2e): Add err to AddHostSourceToTargetCli * refact(e2e): Add err to SetHostSourceToTargetCli * refact(e2e): Add err to RemoveHostSourceFromTargetCli * refact(e2e): Add err to AddBrokeredCredentialSourceToTargetCli * refact(e2e): Add err to RemoveBrokeredCredentialSourceFromTargetCli * refact(e2e): Add err to CreateUserApi * refact(e2e): Add err to CreateUserCli * refact(e2e): Add err to SetAccountToUserCli * refact(e2e): Add err to CreateRoleApi * refact(e2e): Add err to CreateRoleCli * refact(e2e): Add err to AddGrantToRoleCli * refact(e2e): Add err to AddPrincipalToRoleCli * refact(e2e): Add err to CreateManagedGroupApi * refact(e2e): Add err to CreateGroupApi * refact(e2e): Add err to CreateGroupCli * refact(e2e): Add err to AddUserToGroup * refact(e2e): Add err to CreateCredentialStoreStaticApi * refact(e2e): Add err to CreateCredentialStoreVaultApi * refact(e2e): Add err to CreateCredentialStoreVaultCli * refact(e2e): Add err to CreateCredentialStoreStaticCli * refact(e2e): Add err to CreateVaultGenericCredentialLibraryCli * refact(e2e): Add err to CreateStaticCredentialPrivateKeyCli * refact(e2e): Add err to CreateStaticCredentialPasswordCli * refact(e2e): Add err to CreateStaticCredentialJsonCli * refact(e2e): Add err to CreateStaticCredentialPasswordApi * refact(e2e): Add err to CreateAuthMethodApi * refact(e2e): Add err to CreateOidcAuthMethodApi * refact(e2e): Add err to CreateAccountApi * refact(e2e): Add err to CreateAccountCli
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package boundary
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
"github.com/hashicorp/boundary/api/groups"
|
|
"github.com/hashicorp/boundary/testing/internal/e2e"
|
|
"github.com/hashicorp/go-secure-stdlib/base62"
|
|
)
|
|
|
|
// CreateGroupApi uses the API to create a new group.
|
|
// Returns the id of the new group.
|
|
func CreateGroupApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
|
|
name, err := base62.Random(16)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
gClient := groups.NewClient(client)
|
|
newGroup, err := gClient.Create(ctx, scopeId, groups.WithName(fmt.Sprintf("e2e Group %s", name)))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
groupId := newGroup.Item.Id
|
|
t.Logf("Created Group: %s", groupId)
|
|
return groupId, nil
|
|
}
|
|
|
|
// CreateGroupCli uses the cli to create a new group.
|
|
// Returns the id of the new group.
|
|
func CreateGroupCli(t testing.TB, ctx context.Context, scopeId string) (string, error) {
|
|
name, err := base62.Random(16)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs(
|
|
"groups", "create",
|
|
"-scope-id", "global",
|
|
"-name", fmt.Sprintf("e2e Group %s", name),
|
|
"-description", "e2e",
|
|
"-format", "json",
|
|
),
|
|
)
|
|
if output.Err != nil {
|
|
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
|
|
}
|
|
|
|
var createGroupResult groups.GroupCreateResult
|
|
err = json.Unmarshal(output.Stdout, &createGroupResult)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
groupId := createGroupResult.Item.Id
|
|
t.Logf("Created Group: %s", groupId)
|
|
return groupId, nil
|
|
}
|
|
|
|
// AddUserToGroup uses the cli to add a user to a group
|
|
func AddUserToGroup(t testing.TB, ctx context.Context, userId string, groupId string) error {
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs(
|
|
"groups", "add-members",
|
|
"-id", groupId,
|
|
"-member", userId,
|
|
),
|
|
)
|
|
if output.Err != nil {
|
|
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
|
|
}
|
|
|
|
return nil
|
|
}
|