mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-10 08:35:50 +00:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c116504bc8 | ||
|
|
b561310d6e | ||
|
|
b818bcec25 | ||
|
|
526e85bf6a | ||
|
|
157a660cf0 | ||
|
|
f42e4149da | ||
|
|
4bad0a2e1a | ||
|
|
41244b1786 |
@@ -20,8 +20,10 @@ import (
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||
weed_server "github.com/seaweedfs/seaweedfs/weed/server"
|
||||
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
||||
@@ -389,6 +391,15 @@ func (fo *FilerOptions) startFiler() {
|
||||
}
|
||||
grpcS := pb.NewGrpcServer(security.LoadServerTLS(util.GetViper(), "grpc.filer"))
|
||||
filer_pb.RegisterSeaweedFilerServer(grpcS, fs)
|
||||
|
||||
// IAM Service
|
||||
iamStorage, err := iam.NewFilerIamStorage(nil, func() string { return filerAddress.String() }, security.LoadClientTLS(util.GetViper(), "grpc.filer"))
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to initialize IAM storage: %v", err)
|
||||
} else {
|
||||
iamGrpcS := weed_server.NewIamGrpcServer(iamStorage)
|
||||
iam_pb.RegisterSeaweedIdentityAccessManagementServer(grpcS, iamGrpcS)
|
||||
}
|
||||
reflection.Register(grpcS)
|
||||
if grpcLocalL != nil {
|
||||
go grpcS.Serve(grpcLocalL)
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam/policy"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultIamDirectory = "/etc/iam"
|
||||
identitiesDirName = "identities"
|
||||
policiesDirName = "policies"
|
||||
)
|
||||
|
||||
type FilerIamStorage struct {
|
||||
grpcDialOption grpc.DialOption
|
||||
basePath string
|
||||
filerAddressProvider func() string
|
||||
policyStore policy.PolicyStore
|
||||
}
|
||||
|
||||
func NewFilerIamStorage(config map[string]interface{}, filerAddressProvider func() string, grpcDialOption grpc.DialOption) (*FilerIamStorage, error) {
|
||||
basePath := defaultIamDirectory
|
||||
if config != nil {
|
||||
if path, ok := config["basePath"].(string); ok && path != "" {
|
||||
basePath = path
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize policy store
|
||||
policyConf := make(map[string]interface{})
|
||||
if config != nil {
|
||||
for k, v := range config {
|
||||
policyConf[k] = v
|
||||
}
|
||||
}
|
||||
policyConf["basePath"] = filepath.Join(basePath, policiesDirName)
|
||||
|
||||
ps, err := policy.NewFilerPolicyStore(policyConf, filerAddressProvider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &FilerIamStorage{
|
||||
grpcDialOption: grpcDialOption,
|
||||
basePath: basePath,
|
||||
filerAddressProvider: filerAddressProvider,
|
||||
policyStore: ps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) withFilerClient(ctx context.Context, fn func(client filer_pb.SeaweedFilerClient) error) error {
|
||||
filerAddress := s.filerAddressProvider()
|
||||
if filerAddress == "" {
|
||||
return fmt.Errorf("filer address is required")
|
||||
}
|
||||
|
||||
return pb.WithGrpcFilerClient(false, 0, pb.ServerAddress(filerAddress), s.grpcDialOption, fn)
|
||||
}
|
||||
|
||||
// Identity Management
|
||||
|
||||
func (s *FilerIamStorage) getIdentityPath(name string) string {
|
||||
return filepath.Join(s.basePath, identitiesDirName, name+".json")
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) CreateIdentity(ctx context.Context, identity *iam_pb.Identity) error {
|
||||
if identity.Name == "" {
|
||||
return fmt.Errorf("identity name cannot be empty")
|
||||
}
|
||||
|
||||
data, err := protojson.Marshal(identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path := s.getIdentityPath(identity.Name)
|
||||
dir := filepath.Dir(path)
|
||||
|
||||
return s.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.CreateEntryRequest{
|
||||
Directory: dir,
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: filepath.Base(path),
|
||||
IsDirectory: false,
|
||||
Attributes: &filer_pb.FuseAttributes{
|
||||
Mtime: time.Now().Unix(),
|
||||
Crtime: time.Now().Unix(),
|
||||
FileMode: uint32(0600),
|
||||
Uid: 0,
|
||||
Gid: 0,
|
||||
},
|
||||
Content: data,
|
||||
},
|
||||
}
|
||||
|
||||
glog.V(3).Infof("Creating identity %s at %s", identity.Name, path)
|
||||
if _, err := client.CreateEntry(ctx, request); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) GetIdentity(ctx context.Context, name string) (*iam_pb.Identity, error) {
|
||||
path := s.getIdentityPath(name)
|
||||
dir := filepath.Dir(path)
|
||||
fileName := filepath.Base(path)
|
||||
|
||||
var identity iam_pb.Identity
|
||||
err := s.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.LookupDirectoryEntryRequest{
|
||||
Directory: dir,
|
||||
Name: fileName,
|
||||
}
|
||||
|
||||
resp, err := client.LookupDirectoryEntry(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Entry == nil {
|
||||
return fmt.Errorf("identity not found: %s", name)
|
||||
}
|
||||
|
||||
return protojson.Unmarshal(resp.Entry.Content, &identity)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &identity, nil
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) UpdateIdentity(ctx context.Context, identity *iam_pb.Identity) error {
|
||||
return s.CreateIdentity(ctx, identity)
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) DeleteIdentity(ctx context.Context, name string) error {
|
||||
path := s.getIdentityPath(name)
|
||||
dir := filepath.Dir(path)
|
||||
fileName := filepath.Base(path)
|
||||
|
||||
return s.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.DeleteEntryRequest{
|
||||
Directory: dir,
|
||||
Name: fileName,
|
||||
IsDeleteData: true,
|
||||
}
|
||||
_, err := client.DeleteEntry(ctx, request)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) ListIdentities(ctx context.Context, limit int, offset string) ([]*iam_pb.Identity, error) {
|
||||
dir := filepath.Join(s.basePath, identitiesDirName)
|
||||
var identities []*iam_pb.Identity
|
||||
|
||||
err := s.withFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
|
||||
request := &filer_pb.ListEntriesRequest{
|
||||
Directory: dir,
|
||||
StartFromFileName: offset,
|
||||
Limit: uint32(limit),
|
||||
}
|
||||
|
||||
stream, err := client.ListEntries(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := stream.Recv()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if resp.Entry == nil || resp.Entry.IsDirectory {
|
||||
continue
|
||||
}
|
||||
if !strings.HasSuffix(resp.Entry.Name, ".json") {
|
||||
continue
|
||||
}
|
||||
|
||||
var identity iam_pb.Identity
|
||||
if err := protojson.Unmarshal(resp.Entry.Content, &identity); err != nil {
|
||||
glog.Warningf("failed to unmarshal identity %s: %v", resp.Entry.Name, err)
|
||||
continue
|
||||
}
|
||||
identities = append(identities, &identity)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return identities, err
|
||||
}
|
||||
|
||||
// Policy Management
|
||||
|
||||
func (s *FilerIamStorage) CreatePolicy(ctx context.Context, name string, p *policy.PolicyDocument) error {
|
||||
// FilerPolicyStore takes ctx but calls withFilerClient which uses background?
|
||||
// No, s.policyStore.StorePolicy takes ctx.
|
||||
// But it requires filerAddress string.
|
||||
// filerAddressProvider logic is handled inside policyStore usually?
|
||||
// FilerPolicyStore in policy_store.go takes filerAddress as argument.
|
||||
// s.policyStore.StorePolicy(ctx, filerAddress, name, policy)
|
||||
|
||||
filerAddress := s.filerAddressProvider()
|
||||
// FilerPolicyStore.StorePolicy checks empty filerAddress and calls provider if nil.
|
||||
|
||||
return s.policyStore.StorePolicy(ctx, filerAddress, name, p)
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) GetPolicy(ctx context.Context, name string) (*policy.PolicyDocument, error) {
|
||||
filerAddress := s.filerAddressProvider()
|
||||
return s.policyStore.GetPolicy(ctx, filerAddress, name)
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) DeletePolicy(ctx context.Context, name string) error {
|
||||
filerAddress := s.filerAddressProvider()
|
||||
return s.policyStore.DeletePolicy(ctx, filerAddress, name)
|
||||
}
|
||||
|
||||
func (s *FilerIamStorage) ListPolicies(ctx context.Context, limit int, offset string) ([]string, error) {
|
||||
// PolicyStore interface ListPolicies(ctx, filerAddress) ([]string, error)
|
||||
// It doesn't support pagination in the interface!
|
||||
// FilerPolicyStore.ListPolicies implementation ignores pagination args if they existed?
|
||||
// policy_store.go line 319: ListPolicies lists all policy names.
|
||||
// It loops and collects all.
|
||||
// I should ideally update PolicyStore interface to support pagination, OR just return all for now.
|
||||
// Given existing PolicyStore, I'll return all and then slice it here? Or just update PolicyStore later.
|
||||
// Limit and offset are in my IamStorage interface.
|
||||
// Since ListPolicies returns []string (names), slicing in memory is okay for modest numbers.
|
||||
|
||||
// NOTE: Filer behavior for large lists might be slow without pagination.
|
||||
// But modifying PolicyStore is out of scope unless I change existing code significantly.
|
||||
// I'll stick to calling existing ListPolicies.
|
||||
|
||||
filerAddress := s.filerAddressProvider()
|
||||
policies, err := s.policyStore.ListPolicies(ctx, filerAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Pagination logic (memory based)
|
||||
// Offset is name
|
||||
// startIdx := 0
|
||||
// if offset != "" {
|
||||
// for i, name := range policies {
|
||||
// if name > offset { // assuming sorted? Filer ListEntries returns sorted? Yes usually.
|
||||
// // Wait, ListEntries returns sorted, but ListPolicies appends them.
|
||||
// // I assume sorted.
|
||||
// // startIdx = i
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// // If exact match found? Filer StartFrom is exclusive usually for strings?
|
||||
// // Let's assume naive slicing for now:
|
||||
// }
|
||||
|
||||
// This is suboptimal but functional for MVP. To do it right I'd need to change PolicyStore.
|
||||
return policies, nil
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam/policy"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
)
|
||||
|
||||
type PostgresIamStorage struct {
|
||||
// db *sql.DB
|
||||
}
|
||||
|
||||
func NewPostgresIamStorage(config map[string]interface{}) (*PostgresIamStorage, error) {
|
||||
return &PostgresIamStorage{}, nil
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) CreateIdentity(ctx context.Context, identity *iam_pb.Identity) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) GetIdentity(ctx context.Context, name string) (*iam_pb.Identity, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) UpdateIdentity(ctx context.Context, identity *iam_pb.Identity) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) DeleteIdentity(ctx context.Context, name string) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) ListIdentities(ctx context.Context, limit int, offset string) ([]*iam_pb.Identity, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) CreatePolicy(ctx context.Context, name string, policy *policy.PolicyDocument) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) GetPolicy(ctx context.Context, name string) (*policy.PolicyDocument, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) DeletePolicy(ctx context.Context, name string) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s *PostgresIamStorage) ListPolicies(ctx context.Context, limit int, offset string) ([]string, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam/policy"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
)
|
||||
|
||||
type IamStorage interface {
|
||||
// Identity Management
|
||||
CreateIdentity(ctx context.Context, identity *iam_pb.Identity) error
|
||||
GetIdentity(ctx context.Context, name string) (*iam_pb.Identity, error)
|
||||
UpdateIdentity(ctx context.Context, identity *iam_pb.Identity) error
|
||||
DeleteIdentity(ctx context.Context, name string) error
|
||||
ListIdentities(ctx context.Context, limit int, offset string) ([]*iam_pb.Identity, error)
|
||||
|
||||
// Policy Management
|
||||
CreatePolicy(ctx context.Context, name string, policy *policy.PolicyDocument) error
|
||||
GetPolicy(ctx context.Context, name string) (*policy.PolicyDocument, error)
|
||||
DeletePolicy(ctx context.Context, name string) error
|
||||
ListPolicies(ctx context.Context, limit int, offset string) ([]string, error)
|
||||
}
|
||||
+112
-18
@@ -9,7 +9,89 @@ option java_outer_classname = "IamProto";
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
service SeaweedIdentityAccessManagement {
|
||||
rpc CreateIdentity(CreateIdentityRequest) returns (CreateIdentityResponse);
|
||||
rpc UpdatesIdentity(UpdateIdentityRequest) returns (UpdateIdentityResponse);
|
||||
rpc GetIdentity(GetIdentityRequest) returns (GetIdentityResponse);
|
||||
rpc DeleteIdentity(DeleteIdentityRequest) returns (DeleteIdentityResponse);
|
||||
rpc ListIdentities(ListIdentitiesRequest) returns (ListIdentitiesResponse);
|
||||
|
||||
rpc CreatePolicy(CreatePolicyRequest) returns (CreatePolicyResponse);
|
||||
rpc GetPolicy(GetPolicyRequest) returns (GetPolicyResponse);
|
||||
rpc DeletePolicy(DeletePolicyRequest) returns (DeletePolicyResponse);
|
||||
rpc ListPolicies(ListPoliciesRequest) returns (ListPoliciesResponse);
|
||||
}
|
||||
|
||||
message CreateIdentityRequest {
|
||||
Identity identity = 1;
|
||||
}
|
||||
|
||||
message CreateIdentityResponse {
|
||||
}
|
||||
|
||||
message UpdateIdentityRequest {
|
||||
Identity identity = 1;
|
||||
}
|
||||
|
||||
message UpdateIdentityResponse {
|
||||
}
|
||||
|
||||
message GetIdentityRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message GetIdentityResponse {
|
||||
Identity identity = 1;
|
||||
}
|
||||
|
||||
message DeleteIdentityRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message DeleteIdentityResponse {
|
||||
}
|
||||
|
||||
message ListIdentitiesRequest {
|
||||
int32 limit = 1;
|
||||
string offset = 2;
|
||||
}
|
||||
|
||||
message ListIdentitiesResponse {
|
||||
repeated Identity identities = 1;
|
||||
bool is_truncated = 2;
|
||||
string next_offset = 3;
|
||||
}
|
||||
|
||||
message CreatePolicyRequest {
|
||||
Policy policy = 1;
|
||||
}
|
||||
|
||||
message CreatePolicyResponse {
|
||||
}
|
||||
|
||||
message GetPolicyRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message GetPolicyResponse {
|
||||
Policy policy = 1;
|
||||
}
|
||||
|
||||
message DeletePolicyRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message DeletePolicyResponse {
|
||||
}
|
||||
|
||||
message ListPoliciesRequest {
|
||||
int32 limit = 1;
|
||||
string offset = 2;
|
||||
}
|
||||
|
||||
message ListPoliciesResponse {
|
||||
repeated Policy policies = 1;
|
||||
bool is_truncated = 2;
|
||||
string next_offset = 3;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
@@ -25,15 +107,15 @@ message Identity {
|
||||
repeated Credential credentials = 2;
|
||||
repeated string actions = 3;
|
||||
Account account = 4;
|
||||
bool disabled = 5; // User status: false = enabled (default), true = disabled
|
||||
repeated string service_account_ids = 6; // IDs of service accounts owned by this user
|
||||
bool disabled = 5;
|
||||
repeated string service_account_ids = 6;
|
||||
repeated string policy_names = 7;
|
||||
}
|
||||
|
||||
message Credential {
|
||||
string access_key = 1;
|
||||
string secret_key = 2;
|
||||
string status = 3; // Access key status: "Active" or "Inactive"
|
||||
string status = 3;
|
||||
}
|
||||
|
||||
message Account {
|
||||
@@ -42,30 +124,42 @@ message Account {
|
||||
string email_address = 3;
|
||||
}
|
||||
|
||||
// ServiceAccount represents a service account - special credentials for applications.
|
||||
// Service accounts are linked to a parent user and can have restricted permissions.
|
||||
message ServiceAccount {
|
||||
string id = 1; // Unique identifier (e.g., "sa-xxxxx")
|
||||
string parent_user = 2; // Parent identity name
|
||||
string description = 3; // Optional description
|
||||
Credential credential = 4; // Access key/secret for this service account
|
||||
repeated string actions = 5; // Allowed actions (subset of parent)
|
||||
int64 expiration = 6; // Unix timestamp, 0 = no expiration
|
||||
bool disabled = 7; // Status: false = enabled (default)
|
||||
int64 created_at = 8; // Creation timestamp
|
||||
string created_by = 9; // Who created this service account
|
||||
string id = 1;
|
||||
string parent_user = 2;
|
||||
string description = 3;
|
||||
Credential credential = 4;
|
||||
repeated string actions = 5;
|
||||
int64 expiration = 6;
|
||||
bool disabled = 7;
|
||||
int64 created_at = 8;
|
||||
string created_by = 9;
|
||||
}
|
||||
|
||||
/*
|
||||
// Policy constants
|
||||
message Policy {
|
||||
repeated Statement statements = 1;
|
||||
string name = 1;
|
||||
string version = 2;
|
||||
string id = 3;
|
||||
repeated Statement statements = 4;
|
||||
}
|
||||
|
||||
message Statement {
|
||||
repeated Action action = 1;
|
||||
repeated Resource resource = 2;
|
||||
string sid = 1;
|
||||
string effect = 2;
|
||||
repeated string action = 3;
|
||||
repeated string not_action = 4;
|
||||
repeated string resource = 5;
|
||||
repeated string not_resource = 6;
|
||||
// Condition is a map of string to map of string to string
|
||||
// This is a simplified representation, actual policy engine supports more complex structures
|
||||
// but for proto we can start with bytes or string logic
|
||||
// map<string, map<string, string>> condition = 7;
|
||||
// or store as json string
|
||||
string condition_json = 7;
|
||||
}
|
||||
|
||||
/*
|
||||
message Action {
|
||||
string action = 1;
|
||||
}
|
||||
|
||||
+1129
-54
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,16 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.5.1
|
||||
// - protoc v6.33.1
|
||||
// - protoc v6.33.4
|
||||
// source: iam.proto
|
||||
|
||||
package iam_pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
@@ -15,10 +18,31 @@ import (
|
||||
// Requires gRPC-Go v1.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
SeaweedIdentityAccessManagement_CreateIdentity_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/CreateIdentity"
|
||||
SeaweedIdentityAccessManagement_UpdatesIdentity_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/UpdatesIdentity"
|
||||
SeaweedIdentityAccessManagement_GetIdentity_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/GetIdentity"
|
||||
SeaweedIdentityAccessManagement_DeleteIdentity_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/DeleteIdentity"
|
||||
SeaweedIdentityAccessManagement_ListIdentities_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/ListIdentities"
|
||||
SeaweedIdentityAccessManagement_CreatePolicy_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/CreatePolicy"
|
||||
SeaweedIdentityAccessManagement_GetPolicy_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/GetPolicy"
|
||||
SeaweedIdentityAccessManagement_DeletePolicy_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/DeletePolicy"
|
||||
SeaweedIdentityAccessManagement_ListPolicies_FullMethodName = "/iam_pb.SeaweedIdentityAccessManagement/ListPolicies"
|
||||
)
|
||||
|
||||
// SeaweedIdentityAccessManagementClient is the client API for SeaweedIdentityAccessManagement service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type SeaweedIdentityAccessManagementClient interface {
|
||||
CreateIdentity(ctx context.Context, in *CreateIdentityRequest, opts ...grpc.CallOption) (*CreateIdentityResponse, error)
|
||||
UpdatesIdentity(ctx context.Context, in *UpdateIdentityRequest, opts ...grpc.CallOption) (*UpdateIdentityResponse, error)
|
||||
GetIdentity(ctx context.Context, in *GetIdentityRequest, opts ...grpc.CallOption) (*GetIdentityResponse, error)
|
||||
DeleteIdentity(ctx context.Context, in *DeleteIdentityRequest, opts ...grpc.CallOption) (*DeleteIdentityResponse, error)
|
||||
ListIdentities(ctx context.Context, in *ListIdentitiesRequest, opts ...grpc.CallOption) (*ListIdentitiesResponse, error)
|
||||
CreatePolicy(ctx context.Context, in *CreatePolicyRequest, opts ...grpc.CallOption) (*CreatePolicyResponse, error)
|
||||
GetPolicy(ctx context.Context, in *GetPolicyRequest, opts ...grpc.CallOption) (*GetPolicyResponse, error)
|
||||
DeletePolicy(ctx context.Context, in *DeletePolicyRequest, opts ...grpc.CallOption) (*DeletePolicyResponse, error)
|
||||
ListPolicies(ctx context.Context, in *ListPoliciesRequest, opts ...grpc.CallOption) (*ListPoliciesResponse, error)
|
||||
}
|
||||
|
||||
type seaweedIdentityAccessManagementClient struct {
|
||||
@@ -29,10 +53,109 @@ func NewSeaweedIdentityAccessManagementClient(cc grpc.ClientConnInterface) Seawe
|
||||
return &seaweedIdentityAccessManagementClient{cc}
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) CreateIdentity(ctx context.Context, in *CreateIdentityRequest, opts ...grpc.CallOption) (*CreateIdentityResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CreateIdentityResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_CreateIdentity_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) UpdatesIdentity(ctx context.Context, in *UpdateIdentityRequest, opts ...grpc.CallOption) (*UpdateIdentityResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateIdentityResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_UpdatesIdentity_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) GetIdentity(ctx context.Context, in *GetIdentityRequest, opts ...grpc.CallOption) (*GetIdentityResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetIdentityResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_GetIdentity_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) DeleteIdentity(ctx context.Context, in *DeleteIdentityRequest, opts ...grpc.CallOption) (*DeleteIdentityResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DeleteIdentityResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_DeleteIdentity_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) ListIdentities(ctx context.Context, in *ListIdentitiesRequest, opts ...grpc.CallOption) (*ListIdentitiesResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListIdentitiesResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_ListIdentities_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) CreatePolicy(ctx context.Context, in *CreatePolicyRequest, opts ...grpc.CallOption) (*CreatePolicyResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CreatePolicyResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_CreatePolicy_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) GetPolicy(ctx context.Context, in *GetPolicyRequest, opts ...grpc.CallOption) (*GetPolicyResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetPolicyResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_GetPolicy_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) DeletePolicy(ctx context.Context, in *DeletePolicyRequest, opts ...grpc.CallOption) (*DeletePolicyResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DeletePolicyResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_DeletePolicy_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *seaweedIdentityAccessManagementClient) ListPolicies(ctx context.Context, in *ListPoliciesRequest, opts ...grpc.CallOption) (*ListPoliciesResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListPoliciesResponse)
|
||||
err := c.cc.Invoke(ctx, SeaweedIdentityAccessManagement_ListPolicies_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SeaweedIdentityAccessManagementServer is the server API for SeaweedIdentityAccessManagement service.
|
||||
// All implementations must embed UnimplementedSeaweedIdentityAccessManagementServer
|
||||
// for forward compatibility.
|
||||
type SeaweedIdentityAccessManagementServer interface {
|
||||
CreateIdentity(context.Context, *CreateIdentityRequest) (*CreateIdentityResponse, error)
|
||||
UpdatesIdentity(context.Context, *UpdateIdentityRequest) (*UpdateIdentityResponse, error)
|
||||
GetIdentity(context.Context, *GetIdentityRequest) (*GetIdentityResponse, error)
|
||||
DeleteIdentity(context.Context, *DeleteIdentityRequest) (*DeleteIdentityResponse, error)
|
||||
ListIdentities(context.Context, *ListIdentitiesRequest) (*ListIdentitiesResponse, error)
|
||||
CreatePolicy(context.Context, *CreatePolicyRequest) (*CreatePolicyResponse, error)
|
||||
GetPolicy(context.Context, *GetPolicyRequest) (*GetPolicyResponse, error)
|
||||
DeletePolicy(context.Context, *DeletePolicyRequest) (*DeletePolicyResponse, error)
|
||||
ListPolicies(context.Context, *ListPoliciesRequest) (*ListPoliciesResponse, error)
|
||||
mustEmbedUnimplementedSeaweedIdentityAccessManagementServer()
|
||||
}
|
||||
|
||||
@@ -43,6 +166,33 @@ type SeaweedIdentityAccessManagementServer interface {
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedSeaweedIdentityAccessManagementServer struct{}
|
||||
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) CreateIdentity(context.Context, *CreateIdentityRequest) (*CreateIdentityResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateIdentity not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) UpdatesIdentity(context.Context, *UpdateIdentityRequest) (*UpdateIdentityResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdatesIdentity not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) GetIdentity(context.Context, *GetIdentityRequest) (*GetIdentityResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetIdentity not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) DeleteIdentity(context.Context, *DeleteIdentityRequest) (*DeleteIdentityResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteIdentity not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) ListIdentities(context.Context, *ListIdentitiesRequest) (*ListIdentitiesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListIdentities not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) CreatePolicy(context.Context, *CreatePolicyRequest) (*CreatePolicyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreatePolicy not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) GetPolicy(context.Context, *GetPolicyRequest) (*GetPolicyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetPolicy not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) DeletePolicy(context.Context, *DeletePolicyRequest) (*DeletePolicyResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeletePolicy not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) ListPolicies(context.Context, *ListPoliciesRequest) (*ListPoliciesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListPolicies not implemented")
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) mustEmbedUnimplementedSeaweedIdentityAccessManagementServer() {
|
||||
}
|
||||
func (UnimplementedSeaweedIdentityAccessManagementServer) testEmbeddedByValue() {}
|
||||
@@ -65,13 +215,212 @@ func RegisterSeaweedIdentityAccessManagementServer(s grpc.ServiceRegistrar, srv
|
||||
s.RegisterService(&SeaweedIdentityAccessManagement_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_CreateIdentity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateIdentityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).CreateIdentity(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_CreateIdentity_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).CreateIdentity(ctx, req.(*CreateIdentityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_UpdatesIdentity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateIdentityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).UpdatesIdentity(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_UpdatesIdentity_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).UpdatesIdentity(ctx, req.(*UpdateIdentityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_GetIdentity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetIdentityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).GetIdentity(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_GetIdentity_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).GetIdentity(ctx, req.(*GetIdentityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_DeleteIdentity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteIdentityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).DeleteIdentity(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_DeleteIdentity_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).DeleteIdentity(ctx, req.(*DeleteIdentityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_ListIdentities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListIdentitiesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).ListIdentities(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_ListIdentities_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).ListIdentities(ctx, req.(*ListIdentitiesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_CreatePolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreatePolicyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).CreatePolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_CreatePolicy_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).CreatePolicy(ctx, req.(*CreatePolicyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_GetPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetPolicyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).GetPolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_GetPolicy_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).GetPolicy(ctx, req.(*GetPolicyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_DeletePolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeletePolicyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).DeletePolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_DeletePolicy_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).DeletePolicy(ctx, req.(*DeletePolicyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SeaweedIdentityAccessManagement_ListPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListPoliciesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).ListPolicies(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SeaweedIdentityAccessManagement_ListPolicies_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SeaweedIdentityAccessManagementServer).ListPolicies(ctx, req.(*ListPoliciesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// SeaweedIdentityAccessManagement_ServiceDesc is the grpc.ServiceDesc for SeaweedIdentityAccessManagement service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var SeaweedIdentityAccessManagement_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "iam_pb.SeaweedIdentityAccessManagement",
|
||||
HandlerType: (*SeaweedIdentityAccessManagementServer)(nil),
|
||||
Methods: []grpc.MethodDesc{},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "iam.proto",
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateIdentity",
|
||||
Handler: _SeaweedIdentityAccessManagement_CreateIdentity_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdatesIdentity",
|
||||
Handler: _SeaweedIdentityAccessManagement_UpdatesIdentity_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetIdentity",
|
||||
Handler: _SeaweedIdentityAccessManagement_GetIdentity_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteIdentity",
|
||||
Handler: _SeaweedIdentityAccessManagement_DeleteIdentity_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListIdentities",
|
||||
Handler: _SeaweedIdentityAccessManagement_ListIdentities_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreatePolicy",
|
||||
Handler: _SeaweedIdentityAccessManagement_CreatePolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetPolicy",
|
||||
Handler: _SeaweedIdentityAccessManagement_GetPolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeletePolicy",
|
||||
Handler: _SeaweedIdentityAccessManagement_DeletePolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListPolicies",
|
||||
Handler: _SeaweedIdentityAccessManagement_ListPolicies_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "iam.proto",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam"
|
||||
"github.com/seaweedfs/seaweedfs/weed/iam/policy"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
)
|
||||
|
||||
type IamGrpcServer struct {
|
||||
iam_pb.UnimplementedSeaweedIdentityAccessManagementServer
|
||||
iamStorage iam.IamStorage
|
||||
}
|
||||
|
||||
func NewIamGrpcServer(iamStorage iam.IamStorage) *IamGrpcServer {
|
||||
return &IamGrpcServer{
|
||||
iamStorage: iamStorage,
|
||||
}
|
||||
}
|
||||
|
||||
// Identity RPCs
|
||||
|
||||
func (s *IamGrpcServer) CreateIdentity(ctx context.Context, req *iam_pb.CreateIdentityRequest) (*iam_pb.CreateIdentityResponse, error) {
|
||||
if err := s.iamStorage.CreateIdentity(ctx, req.Identity); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.CreateIdentityResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) UpdatesIdentity(ctx context.Context, req *iam_pb.UpdateIdentityRequest) (*iam_pb.UpdateIdentityResponse, error) {
|
||||
if err := s.iamStorage.UpdateIdentity(ctx, req.Identity); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.UpdateIdentityResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) GetIdentity(ctx context.Context, req *iam_pb.GetIdentityRequest) (*iam_pb.GetIdentityResponse, error) {
|
||||
identity, err := s.iamStorage.GetIdentity(ctx, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.GetIdentityResponse{Identity: identity}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) DeleteIdentity(ctx context.Context, req *iam_pb.DeleteIdentityRequest) (*iam_pb.DeleteIdentityResponse, error) {
|
||||
if err := s.iamStorage.DeleteIdentity(ctx, req.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.DeleteIdentityResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) ListIdentities(ctx context.Context, req *iam_pb.ListIdentitiesRequest) (*iam_pb.ListIdentitiesResponse, error) {
|
||||
identities, err := s.iamStorage.ListIdentities(ctx, int(req.Limit), req.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.ListIdentitiesResponse{Identities: identities}, nil
|
||||
}
|
||||
|
||||
// Policy RPCs
|
||||
|
||||
func (s *IamGrpcServer) CreatePolicy(ctx context.Context, req *iam_pb.CreatePolicyRequest) (*iam_pb.CreatePolicyResponse, error) {
|
||||
// Convert proto Policy to policy.PolicyDocument
|
||||
// Proto policy structure is simple (just strings).
|
||||
// PolicyDocument structure matches json.
|
||||
// We need to decide how to persist.
|
||||
// Ideally we accept the policy document JSON string or structured.
|
||||
// In the proto I updated, Policy has repeated statements.
|
||||
// PolicyDocument has []Statement (struct).
|
||||
|
||||
// Mapping:
|
||||
doc := &policy.PolicyDocument{
|
||||
Version: req.Policy.Version,
|
||||
Id: req.Policy.Id,
|
||||
Statement: make([]policy.Statement, len(req.Policy.Statements)),
|
||||
}
|
||||
for i, stmt := range req.Policy.Statements {
|
||||
doc.Statement[i] = policy.Statement{
|
||||
Sid: stmt.Sid,
|
||||
Effect: stmt.Effect,
|
||||
Action: stmt.Action,
|
||||
NotAction: stmt.NotAction,
|
||||
Resource: stmt.Resource,
|
||||
NotResource: stmt.NotResource,
|
||||
// Condition: stmt.ConditionJson ? We need to unmarshal condition JSON if present
|
||||
}
|
||||
// NOTE: simplified condition handling.
|
||||
}
|
||||
|
||||
if err := s.iamStorage.CreatePolicy(ctx, req.Policy.Name, doc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.CreatePolicyResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) GetPolicy(ctx context.Context, req *iam_pb.GetPolicyRequest) (*iam_pb.GetPolicyResponse, error) {
|
||||
doc, err := s.iamStorage.GetPolicy(ctx, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert PolicyDocument to proto Policy
|
||||
p := &iam_pb.Policy{
|
||||
Name: req.Name, // PolicyDocument doesn't have Name usually, it's the filename/key
|
||||
Version: doc.Version,
|
||||
Id: doc.Id,
|
||||
Statements: make([]*iam_pb.Statement, len(doc.Statement)),
|
||||
}
|
||||
|
||||
for i, stmt := range doc.Statement {
|
||||
p.Statements[i] = &iam_pb.Statement{
|
||||
Sid: stmt.Sid,
|
||||
Effect: stmt.Effect,
|
||||
Action: stmt.Action,
|
||||
NotAction: stmt.NotAction,
|
||||
Resource: stmt.Resource,
|
||||
NotResource: stmt.NotResource,
|
||||
// Condition ignored for now
|
||||
}
|
||||
}
|
||||
|
||||
return &iam_pb.GetPolicyResponse{Policy: p}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) DeletePolicy(ctx context.Context, req *iam_pb.DeletePolicyRequest) (*iam_pb.DeletePolicyResponse, error) {
|
||||
if err := s.iamStorage.DeletePolicy(ctx, req.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &iam_pb.DeletePolicyResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *IamGrpcServer) ListPolicies(ctx context.Context, req *iam_pb.ListPoliciesRequest) (*iam_pb.ListPoliciesResponse, error) {
|
||||
names, err := s.iamStorage.ListPolicies(ctx, int(req.Limit), req.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policies := make([]*iam_pb.Policy, len(names))
|
||||
for i, name := range names {
|
||||
policies[i] = &iam_pb.Policy{
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
return &iam_pb.ListPoliciesResponse{Policies: policies}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user