| 1 | package release |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | ) |
| 7 | |
| 8 | // The signed-pointer and ship entry points below run as one app mutation: |
| 9 | // on an enabled console store the whole read, authorize and conditional |
| 10 | // write sequence shares one admitted operation, and a nested call (a ladder |
| 11 | // promote that cuts a tag, a pending execution that promotes) reuses the |
| 12 | // permitted context it was handed. The ordinary bucket implementations do |
| 13 | // not implement AppMutationRunner, so with host claims off each call runs |
| 14 | // its original body unchanged. |
| 15 | |
| 16 | // Ship is claimRawShip under the app mutation of the manifest's app. |
| 17 | func Ship(ctx context.Context, s Store, acct string, m Manifest, files map[string][]byte) error { |
| 18 | return WithAppMutation(ctx, s, acct, m.App, "release.Ship", func(ctx context.Context) error { |
| 19 | return claimRawShip(ctx, s, acct, m, files) |
| 20 | }) |
| 21 | } |
| 22 | |
| 23 | // ShipSpooled is claimRawShipSpooled under the app mutation of the |
| 24 | // manifest's app: Ship for artifacts on disk (paths maps each artifact key to |
| 25 | // a local file), each streamed into the bucket rather than held in memory. |
| 26 | func ShipSpooled(ctx context.Context, s Store, acct string, m Manifest, paths map[string]string) error { |
| 27 | return WithAppMutation(ctx, s, acct, m.App, "release.ShipSpooled", func(ctx context.Context) error { |
| 28 | return claimRawShipSpooled(ctx, s, acct, m, paths) |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | func (sg Signer) promote(ctx context.Context, s Store, acct, app, channel, version string, authorize func(*Pipeline) error, expectVersion string, rec ...Promotion) error { |
| 33 | return WithAppMutation(ctx, s, acct, app, "release.Promote", func(ctx context.Context) error { |
| 34 | return sg.claimRawPromote(ctx, s, acct, app, channel, version, authorize, expectVersion, rec...) |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | // PromoteOnLadder is claimRawPromoteOnLadder under one app mutation, so the |
| 39 | // pointer write and the stable tag it may cut are a single admitted effect. |
| 40 | func (sg Signer) PromoteOnLadder(ctx context.Context, s Store, acct, app, channel, version string, opt PromoteOptions) (PromoteResult, error) { |
| 41 | var res PromoteResult |
| 42 | err := WithAppMutation(ctx, s, acct, app, "release.PromoteOnLadder", func(ctx context.Context) error { |
| 43 | var err error |
| 44 | res, err = sg.claimRawPromoteOnLadder(ctx, s, acct, app, channel, version, opt) |
| 45 | return err |
| 46 | }) |
| 47 | return res, err |
| 48 | } |
| 49 | |
| 50 | // RollbackAuthorized is claimRawRollbackAuthorized under one app mutation. |
| 51 | func (sg Signer) RollbackAuthorized(ctx context.Context, s Store, acct, app, channel string, authorize func(*Pipeline) error) error { |
| 52 | return WithAppMutation(ctx, s, acct, app, "release.Rollback", func(ctx context.Context) error { |
| 53 | return sg.claimRawRollbackAuthorized(ctx, s, acct, app, channel, authorize) |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | // Resign is ResignAuthorized with no authority hook. |
| 58 | func (sg Signer) Resign(ctx context.Context, s Store, plan *ResignPlan, actor string) error { |
| 59 | return sg.ResignAuthorized(ctx, s, plan, actor, nil) |
| 60 | } |
| 61 | |
| 62 | // ResignAuthorized is claimRawResign under one app mutation, with authorize |
| 63 | // (nil = no hook) asked of the pipeline inside it, as RollbackAuthorized does. |
| 64 | func (sg Signer) ResignAuthorized(ctx context.Context, s Store, plan *ResignPlan, actor string, authorize func(*Pipeline) error) error { |
| 65 | if plan == nil { |
| 66 | return errors.New("resign: no plan to sign") |
| 67 | } |
| 68 | return WithAppMutation(ctx, s, plan.Account, plan.App, "release.Resign", func(ctx context.Context) error { |
| 69 | return sg.claimRawResign(ctx, s, plan, actor, authorize) |
| 70 | }) |
| 71 | } |
| 72 | |
| 73 | // Authorize is claimRawAuthorize under one app mutation. |
| 74 | func (sg Signer) Authorize(ctx context.Context, s Store, plan *AuthorizePlan, actor string) (already bool, err error) { |
| 75 | if plan == nil { |
| 76 | return false, errors.New("authorize: no plan to sign") |
| 77 | } |
| 78 | err = WithAppMutation(ctx, s, plan.Account, plan.App, "release.Authorize", func(ctx context.Context) error { |
| 79 | var err error |
| 80 | already, err = sg.claimRawAuthorize(ctx, s, plan, actor) |
| 81 | return err |
| 82 | }) |
| 83 | return already, err |
| 84 | } |
| 85 | |