fix(openshell): short random sandbox names the gateway accepts (#1864)
This commit is contained in:
1 file changed
+16
-1
@@ -5,6 +5,8 @@ package openshell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
@@ -151,7 +153,10 @@ func (s *Sandbox) ExitDetail() string {
|
||||
// Acquire creates a sandbox running the agent l describes, and waits until it
|
||||
// is ready.
|
||||
func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) {
|
||||
name := fmt.Sprintf("%s-agent-%d", r.instance, time.Now().UnixNano())
|
||||
name, err := sandboxName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spec, err := r.spec(l)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -170,6 +175,16 @@ func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// sandboxName is a short random name: the gateway rejects names much longer
|
||||
// than 19 characters, and the instance is carried by the sandbox's label.
|
||||
func sandboxName() (string, error) {
|
||||
var b [6]byte
|
||||
if _, err := rand.Read(b[:]); err != nil {
|
||||
return "", fmt.Errorf("name sandbox: %w", err)
|
||||
}
|
||||
return "archie-" + hex.EncodeToString(b[:]), nil
|
||||
}
|
||||
|
||||
// Release stops watching s and removes its sandbox.
|
||||
func (r *Runtime) Release(ctx context.Context, s *Sandbox) {
|
||||
if s == nil {
|
||||
|
||||
Reference in new issue
Block a user