2023-09-01 14:44:53 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
//go:build !consulent
|
|
|
|
|
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
2023-10-20 18:49:54 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
2023-10-27 13:55:02 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/oklog/ulid/v2"
|
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
|
|
|
2023-09-01 14:44:53 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2023-10-20 18:49:54 +00:00
|
|
|
"github.com/hashicorp/consul/internal/resource"
|
|
|
|
"github.com/hashicorp/consul/internal/storage"
|
|
|
|
"github.com/hashicorp/consul/internal/storage/inmem"
|
|
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
|
|
pbtenancy "github.com/hashicorp/consul/proto-public/pbtenancy/v2beta1"
|
2023-09-01 14:44:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func FillEntMeta(entMeta *acl.EnterpriseMeta) {
|
|
|
|
// nothing to to in CE.
|
|
|
|
}
|
|
|
|
|
|
|
|
func FillAuthorizerContext(authzContext *acl.AuthorizerContext) {
|
|
|
|
// nothing to to in CE.
|
|
|
|
}
|
2023-10-20 18:49:54 +00:00
|
|
|
|
2024-01-25 19:12:30 +00:00
|
|
|
// initTenancy creates the builtin v2 namespace resource only. The builtin
|
|
|
|
// v2 partition is not created because we're in CE.
|
2023-10-20 18:49:54 +00:00
|
|
|
func initTenancy(ctx context.Context, b *inmem.Backend) error {
|
|
|
|
nsData, err := anypb.New(&pbtenancy.Namespace{Description: "default namespace in default partition"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
nsID := &pbresource.ID{
|
|
|
|
Type: pbtenancy.NamespaceType,
|
|
|
|
Name: resource.DefaultNamespaceName,
|
|
|
|
Tenancy: resource.DefaultPartitionedTenancy(),
|
|
|
|
Uid: ulid.Make().String(),
|
|
|
|
}
|
|
|
|
read, err := b.Read(ctx, storage.StrongConsistency, nsID)
|
|
|
|
if err != nil && !errors.Is(err, storage.ErrNotFound) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if read == nil && errors.Is(err, storage.ErrNotFound) {
|
|
|
|
_, err = b.WriteCAS(ctx, &pbresource.Resource{
|
|
|
|
Id: nsID,
|
|
|
|
Generation: ulid.Make().String(),
|
|
|
|
Data: nsData,
|
|
|
|
Metadata: map[string]string{
|
|
|
|
"generated_at": time.Now().Format(time.RFC3339),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|