feat(api): return remote storage states for worker
This commit is contained in:
1 parent
11272b6c2a
commit
c0cf5c4e1b
13 files changed
+787
-108
No files matched your search
@@ -77,6 +77,13 @@ func (r *Repository) LookupWorkerByName(ctx context.Context, name string) (*Work
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if w == nil {
|
||||
return nil, nil
|
||||
}
|
||||
w.RemoteStorageStates, err = r.ListWorkerStorageBucketCredentialState(ctx, w.GetPublicId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
@@ -138,6 +145,13 @@ func (r *Repository) LookupWorker(ctx context.Context, publicId string, _ ...Opt
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if w == nil {
|
||||
return nil, nil
|
||||
}
|
||||
w.RemoteStorageStates, err = r.ListWorkerStorageBucketCredentialState(ctx, w.GetPublicId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
@@ -555,6 +569,10 @@ func (r *Repository) UpdateWorker(ctx context.Context, worker *Worker, version u
|
||||
if ret, err = wAgg.toWorker(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ret.RemoteStorageStates, err = r.ListWorkerStorageBucketCredentialState(ctx, ret.GetPublicId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/server/store"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/plugin"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
@@ -126,6 +127,9 @@ type Worker struct {
|
||||
|
||||
// This is used to pass the token back to the calling function
|
||||
ControllerGeneratedActivationToken string `gorm:"-"`
|
||||
|
||||
// RemoteStorageStates is a map of storage buckets and their storage bucket credential states
|
||||
RemoteStorageStates map[string]*plugin.StorageBucketCredentialState `gorm:"-"`
|
||||
}
|
||||
|
||||
// NewWorker returns a new Worker. Valid options are WithName, WithDescription
|
||||
@@ -284,6 +288,7 @@ func (a *workerAggregate) toWorker(ctx context.Context) (*Worker, error) {
|
||||
LocalStorageState: a.LocalStorageState,
|
||||
},
|
||||
activeConnectionCount: a.ActiveConnectionCount,
|
||||
RemoteStorageStates: map[string]*plugin.StorageBucketCredentialState{},
|
||||
}
|
||||
tags, err := tagsFromAggregatedTagString(ctx, a.ApiTags)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
|
||||
)
|
||||
|
||||
type RemoteStorageState string
|
||||
|
||||
const (
|
||||
RemoteStorageStateAvailable RemoteStorageState = "available"
|
||||
RemoteStorageStateError RemoteStorageState = "error"
|
||||
RemoteStorageStateUnknown RemoteStorageState = "unknown"
|
||||
)
|
||||
|
||||
func (t RemoteStorageState) String() string {
|
||||
switch t {
|
||||
case RemoteStorageStateAvailable, RemoteStorageStateError:
|
||||
return string(t)
|
||||
}
|
||||
return string(RemoteStorageStateUnknown)
|
||||
}
|
||||
|
||||
type StorageBucketCredentialPermissionType string
|
||||
|
||||
func (s StorageBucketCredentialPermissionType) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
type StorageBucketCredentialPermissionState string
|
||||
|
||||
func (s StorageBucketCredentialPermissionState) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// ParseStateType converts the string value of a storage bucket credential
|
||||
// state value and converts it into a integer type.
|
||||
func ParseStateType(s string) (plgpb.StateType, error) {
|
||||
switch s {
|
||||
case PermissionStateOk.String():
|
||||
return plgpb.StateType_STATE_TYPE_OK, nil
|
||||
case PermissionStateError.String():
|
||||
return plgpb.StateType_STATE_TYPE_ERROR, nil
|
||||
case PermissionStateUnknown.String():
|
||||
return plgpb.StateType_STATE_TYPE_UNKNOWN, nil
|
||||
default:
|
||||
return plgpb.StateType_STATE_TYPE_UNSPECIFIED, fmt.Errorf("undefined state value")
|
||||
}
|
||||
}
|
||||
|
||||
// ParsePermissionState converts the state type value into a string value.
|
||||
func ParsePermissionState(s plgpb.StateType) (string, error) {
|
||||
switch s {
|
||||
case plgpb.StateType_STATE_TYPE_OK:
|
||||
return PermissionStateOk.String(), nil
|
||||
case plgpb.StateType_STATE_TYPE_ERROR:
|
||||
return PermissionStateError.String(), nil
|
||||
case plgpb.StateType_STATE_TYPE_UNKNOWN:
|
||||
return PermissionStateUnknown.String(), nil
|
||||
default:
|
||||
return "", fmt.Errorf("undefined state type")
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
PermissionTypeWrite StorageBucketCredentialPermissionType = "write"
|
||||
PermissionTypeRead StorageBucketCredentialPermissionType = "read"
|
||||
PermissionTypeDelete StorageBucketCredentialPermissionType = "delete"
|
||||
PermissionStateOk StorageBucketCredentialPermissionState = "ok"
|
||||
PermissionStateError StorageBucketCredentialPermissionState = "error"
|
||||
PermissionStateUnknown StorageBucketCredentialPermissionState = "unknown"
|
||||
)
|
||||
Reference in new issue
Block a user