Download this file
| 1 | package hostbox |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/hex" |
| 6 | "github.com/carlosframework/platform/internal/controlname" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | // ReplicaParkLeaseSet implements the data-bucket locks in claim section 6.2a. |
| 11 | // Generation parks also use their location's replica lock; the generation |
| 12 | // selector is in the chore, not an extra lock namespace. |
| 13 | func ReplicaParkLeaseSet(ctx context.Context, bucket, scope string) ([]string, error) { |
| 14 | if ctx == nil || bucket == "" { |
| 15 | return nil, ErrUnsupported |
| 16 | } |
| 17 | if err := ctx.Err(); err != nil { |
| 18 | return nil, err |
| 19 | } |
| 20 | p := strings.Split(scope, "/") |
| 21 | if len(p) < 2 || len(p) > 3 || !controlname.ValidHostShape(p[1]) { |
| 22 | return nil, ErrUnsupported |
| 23 | } |
| 24 | switch p[0] { |
| 25 | case "instances": |
| 26 | if len(p) == 3 { |
| 27 | if len(p[2]) != 64 || strings.ToLower(p[2]) != p[2] { |
| 28 | return nil, ErrUnsupported |
| 29 | } |
| 30 | if _, err := hex.DecodeString(p[2]); err != nil { |
| 31 | return nil, ErrUnsupported |
| 32 | } |
| 33 | } |
| 34 | case "moves": |
| 35 | if len(p) == 3 && (p[2] == "" || p[2] == "." || p[2] == ".." || strings.ContainsAny(p[2], "\\\x00:")) { |
| 36 | return nil, ErrUnsupported |
| 37 | } |
| 38 | default: |
| 39 | return nil, ErrUnsupported |
| 40 | } |
| 41 | return []string{scope}, nil |
| 42 | } |
| 43 | |