| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/hostguard" |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | ) |
| 10 | |
| 11 | func rootInstallationHostApp(guard hostguard.Guard, store release.Store) func(string) (string, string, error) { |
| 12 | return func(host string) (string, string, error) { |
| 13 | if guard.Root == nil || guard.Claims == nil || store == nil { |
| 14 | return "", "", os.ErrPermission |
| 15 | } |
| 16 | captured, err := guard.Capture(host) |
| 17 | if err != nil { |
| 18 | return "", "", err |
| 19 | } |
| 20 | in, err := guard.Root.Installation(context.Background(), host, captured) |
| 21 | if err != nil { |
| 22 | return "", "", err |
| 23 | } |
| 24 | observed, err := guard.Claims.Read(context.Background(), host) |
| 25 | if err != nil { |
| 26 | return "", "", err |
| 27 | } |
| 28 | if observed.Absent || observed.Host != host || observed.Claim == nil || observed.Claim.Holder == nil { |
| 29 | return "", "", os.ErrPermission |
| 30 | } |
| 31 | h := observed.Claim.Holder |
| 32 | if h.Incarnation != in.Incarnation || h.Stamp != in.Stamp || h.Account != in.Account || h.App != in.App || h.Key != in.Record { |
| 33 | return "", "", os.ErrPermission |
| 34 | } |
| 35 | rec, _, err := rootClaimRecord(context.Background(), store, observed.Claim, guard.DataDir) |
| 36 | if err != nil { |
| 37 | return "", "", err |
| 38 | } |
| 39 | if rec.Account != in.Account || rec.App != in.App { |
| 40 | return "", "", os.ErrPermission |
| 41 | } |
| 42 | |
| 43 | return in.Account, in.App, nil |
| 44 | } |
| 45 | } |
| 46 | |