Skip to content

Commit

Permalink
Add SetSaxCellACL to Go client.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 689098735
Change-Id: Ie639546d71eea53fa59d8f6968c4145f8afd39fd
  • Loading branch information
Sax Authors authored and copybara-github committed Oct 23, 2024
1 parent 6b85e1a commit 6d147fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions saxml/client/go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ go_library(
name = "saxadmin",
srcs = ["admin.go"],
deps = [
"//saxml/admin:validator",
"//saxml/common:addr",
"//saxml/common:config",
"//saxml/common:errors",
Expand All @@ -101,6 +102,7 @@ go_library(
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
"@org_golang_google_protobuf//proto",
],
)

Expand Down
32 changes: 32 additions & 0 deletions saxml/client/go/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"saxml/admin/validator"
"saxml/common/addr"
"saxml/common/config"
"saxml/common/errors"
Expand Down Expand Up @@ -267,6 +269,36 @@ func (a *Admin) GetSaxCellACL(ctx context.Context, saxCell string) (string, erro
return cfg.GetAdminAcl(), nil
}

// SetSaxCellACL sets the ACL for the sax cell.
func (a *Admin) SetSaxCellACL(ctx context.Context, saxCell string, acl string) error {
_, err := naming.NewCellFullName(saxCell)
if err != nil {
log.ErrorContextf(ctx, "Invalid sax cell: %v", err)
return err
}

cfg, err := config.Load(ctx, saxCell)
if err != nil {
log.ErrorContextf(ctx, "Failed to load config: %v", err)
return err
}
log.InfoContextf(ctx, "Current config definition:\n%v", cfg)

change := proto.Clone(cfg).(*pb.Config)
change.AdminAcl = acl
log.InfoContextf(ctx, "Updated config definition:\n%v", change)

if err := validator.ValidateConfigUpdate(cfg, change); err != nil {
log.ErrorContextf(ctx, "Invalid config update: %v", err)
return err
}
if err := config.Save(ctx, change, saxCell, acl); err != nil {
log.ErrorContextf(ctx, "Failed to save config: %v", err)
return err
}
return nil
}

// addrReplica maintains a set of server addresses for a model.
type addrReplica struct {
modelID string
Expand Down

0 comments on commit 6d147fc

Please sign in to comment.