Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package boundary
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/api"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/api/groups"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/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
|
|
}
|