package console import "context" // createClaimAppRow inserts a new app's SQL row through insert. Flag-off it is // insert on the store, exactly as before. // // Enabled, the armed gate refuses an apps row nobody holds a permit for, and a // permit is derived from canonical admission, so the order is reversed: the // bucket CAS reserves the canonical identity first (EnrollNewApp is idempotent // for an open admission, so a racer in this or another console converges on // the same app_id), then one app mutation of that identity inserts the row and // binds app_id in the same permitted view. A refused enrollment (a foreign // operation, a name that is not free) leaves no SQL row. A lost SQL race // reports created false and binds nothing; the open admission is the winner's. func (s *Server) createClaimAppRow(ctx context.Context, acct *Account, app string, insert func(*Store) (bool, error)) (bool, error) { if !s.cfg.HostClaim { return insert(s.store) } w, err := s.claimControl() if err != nil { return false, err } appID, err := w.EnrollNewApp(ctx, acct.Sqid, app) if err != nil { return false, err } ctx, err = s.claimEnrollmentContext(ctx, acct, app, appID) if err != nil { return false, err } created := false err = s.store.withAutoAppSQL(ctx, acct.ID, app, "sql.CreateApp", func(st *Store) error { var err error if created, err = insert(st); err != nil || !created { return err } return st.BindClaimAppIdentity(acct.ID, app, appID) }) if err != nil { return false, err } return created, nil }