feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -7,7 +7,6 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -37,7 +36,7 @@ type AutoPublicationChange struct {
|
||||
ImpactToken string `json:"impact_token"`
|
||||
}
|
||||
|
||||
func autoScope(ctx context.Context, tx *sql.Tx, domain, kind, id string) (string, error) {
|
||||
func (s *Store) autoScope(ctx context.Context, tx *sql.Tx, domain, kind, id string) (string, error) {
|
||||
if kind == "domain" {
|
||||
if id != domain {
|
||||
return "", ErrGovernanceInvalid
|
||||
@@ -49,11 +48,11 @@ func autoScope(ctx context.Context, tx *sql.Tx, domain, kind, id string) (string
|
||||
table = "spots"
|
||||
}
|
||||
var scope string
|
||||
err := tx.QueryRowContext(ctx, `SELECT path_prefix FROM `+table+` WHERE domain_uuid=? AND uuid=? AND state!='archived'`, domain, id).Scan(&scope)
|
||||
err := tx.QueryRowContext(ctx, `SELECT path_prefix FROM `+table+` WHERE domain_uuid=`+s.sqlParam(1)+` AND uuid=`+s.sqlParam(2)+` AND state!='archived'`, domain, id).Scan(&scope)
|
||||
return scope, err
|
||||
}
|
||||
func autoRules(ctx context.Context, tx *sql.Tx, domain string) ([]autoPublicationRule, error) {
|
||||
rows, err := tx.QueryContext(ctx, `SELECT node_kind,node_uuid,mode,scope_path,actor_uuid,version FROM locality_auto_publication WHERE domain_uuid=? ORDER BY node_kind,node_uuid LIMIT 129`, domain)
|
||||
func (s *Store) autoRules(ctx context.Context, tx *sql.Tx, domain string) ([]autoPublicationRule, error) {
|
||||
rows, err := tx.QueryContext(ctx, `SELECT node_kind,node_uuid,mode,scope_path,actor_uuid,version FROM locality_auto_publication WHERE domain_uuid=`+s.sqlParam(1)+` ORDER BY node_kind,node_uuid LIMIT 129`, domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -71,37 +70,45 @@ func autoRules(ctx context.Context, tx *sql.Tx, domain string) ([]autoPublicatio
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func requireManualPublication(ctx context.Context, tx *sql.Tx, domain, actor, kind, id string) error {
|
||||
scope, err := autoScope(ctx, tx, domain, kind, id)
|
||||
func (s *Store) requireManualPublication(ctx context.Context, tx *sql.Tx, domain, actor, kind, id string) error {
|
||||
scope, err := s.autoScope(ctx, tx, domain, kind, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO locality_auto_publication VALUES(?,?,?,'required',?,?,1) ON CONFLICT(domain_uuid,node_kind,node_uuid) DO UPDATE SET mode='required',scope_path=excluded.scope_path,actor_uuid=excluded.actor_uuid,version=version+1`, domain, kind, id, scope, actor)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO locality_auto_publication VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,'required',`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,1) ON CONFLICT(domain_uuid,node_kind,node_uuid) DO UPDATE SET mode='required',scope_path=excluded.scope_path,actor_uuid=excluded.actor_uuid,version=locality_auto_publication.version+1`, domain, kind, id, scope, actor)
|
||||
return err
|
||||
}
|
||||
func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id string, change *AutoPublicationChange) (AutoPublication, error) {
|
||||
func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id string, change *AutoPublicationChange) (_ AutoPublication, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("AutoPublication", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
state := AutoPublication{Mode: "inherit"}
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
options := s.policyReadOptions()
|
||||
if change != nil {
|
||||
options = &sql.TxOptions{Isolation: sql.LevelReadCommitted}
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, options)
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if change != nil {
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO city_governance_epochs VALUES(?,0) ON CONFLICT(domain_uuid) DO UPDATE SET version=version`, domain); err != nil {
|
||||
if err = s.lockPolicyWrite(ctx, tx); err != nil {
|
||||
return state, err
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO city_governance_epochs VALUES(`+s.sqlParam(1)+`,0) ON CONFLICT(domain_uuid) DO UPDATE SET version=city_governance_epochs.version`, domain); err != nil {
|
||||
return state, err
|
||||
}
|
||||
}
|
||||
g, err := governanceSnapshot(ctx, tx, domain, actor, kind, id)
|
||||
g, err := s.governanceSnapshot(ctx, tx, domain, actor, kind, id)
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
scope, err := autoScope(ctx, tx, domain, kind, id)
|
||||
scope, err := s.autoScope(ctx, tx, domain, kind, id)
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
rules, err := autoRules(ctx, tx, domain)
|
||||
rules, err := s.autoRules(ctx, tx, domain)
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
@@ -113,7 +120,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
state.Mode, state.Version = rule.Mode, rule.Version
|
||||
state.Active = rule.Mode == "automatic" && rule.Scope == scope
|
||||
if state.Active && rule.Actor != actor {
|
||||
_, e := governanceSnapshot(ctx, tx, domain, rule.Actor, kind, id)
|
||||
_, e := s.governanceSnapshot(ctx, tx, domain, rule.Actor, kind, id)
|
||||
if errors.Is(e, sql.ErrNoRows) || errors.Is(e, ErrAccessDenied) {
|
||||
state.Active = false
|
||||
} else if e != nil {
|
||||
@@ -122,7 +129,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
}
|
||||
}
|
||||
if rule.Mode == "required" && !(rule.Kind == kind && rule.ID == id) {
|
||||
parent, e := autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
parent, e := s.autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
if e != nil && !errors.Is(e, sql.ErrNoRows) {
|
||||
return state, e
|
||||
}
|
||||
@@ -139,7 +146,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
return state, ErrGovernanceConflict
|
||||
}
|
||||
if change == nil || change.Mode != "required" {
|
||||
state.Impact, err = publicationImpact(ctx, tx, domain, actor, kind, id, g)
|
||||
state.Impact, err = s.publicationImpact(ctx, tx, domain, actor, kind, id, g)
|
||||
if err != nil {
|
||||
if change == nil && errors.Is(err, ErrPublicationImpact) {
|
||||
state.CanAutomatic = false
|
||||
@@ -184,7 +191,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
if !change.Confirm || change.ImpactToken == "" || change.ImpactToken != state.Impact.ImpactToken {
|
||||
return state, ErrPublicationImpact
|
||||
}
|
||||
if err = installPublicationGuards(ctx, tx); err != nil {
|
||||
if err = s.installPublicationGuards(ctx, tx); err != nil {
|
||||
return state, err
|
||||
}
|
||||
}
|
||||
@@ -192,7 +199,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
return state, ErrPublicationImpact
|
||||
}
|
||||
before, _ := json.Marshal(state)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO locality_auto_publication VALUES(?,?,?,?,?,?,1) ON CONFLICT(domain_uuid,node_kind,node_uuid) DO UPDATE SET mode=excluded.mode,scope_path=excluded.scope_path,actor_uuid=excluded.actor_uuid,version=version+1`, domain, kind, id, change.Mode, scope, actor)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO locality_auto_publication VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`,1) ON CONFLICT(domain_uuid,node_kind,node_uuid) DO UPDATE SET mode=excluded.mode,scope_path=excluded.scope_path,actor_uuid=excluded.actor_uuid,version=locality_auto_publication.version+1`, domain, kind, id, change.Mode, scope, actor)
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
@@ -201,7 +208,7 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
state.Active = change.Mode == "automatic"
|
||||
state.Impact.ImpactToken = ""
|
||||
after, _ := json.Marshal(state)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO city_governance_events(domain_uuid,epoch,actor_uuid,node_kind,node_uuid,before_json,after_json,created_at_ms) VALUES(?,?,?,?,?,?,?,?)`, domain, g.Epoch, actor, kind, id, string(before), string(after), time.Now().UnixMilli())
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO city_governance_events(domain_uuid,epoch,actor_uuid,node_kind,node_uuid,before_json,after_json,created_at_ms) VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`,`+s.sqlParam(7)+`,`+s.sqlParam(8)+`)`, domain, g.Epoch, actor, kind, id, string(before), string(after), time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
@@ -211,26 +218,31 @@ func (s *Store) AutoPublication(ctx context.Context, domain, actor, kind, id str
|
||||
// Evaluate live heads, audience, publisher authority and literal Path boundaries
|
||||
// in one read transaction. No request mutates approval manifests or source content.
|
||||
func (s *Store) automaticPublicPages(ctx context.Context, domain, onlyPath string) ([]PublishedNavigationPage, error) {
|
||||
tx, err := s.DB.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
tx, err := s.DB.BeginTx(ctx, s.policyReadOptions())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
return s.automaticPublicPagesTx(ctx, tx, domain, onlyPath)
|
||||
}
|
||||
|
||||
func (s *Store) automaticPublicPagesTx(ctx context.Context, tx *sql.Tx, domain, onlyPath string) ([]PublishedNavigationPage, error) {
|
||||
var err error
|
||||
var live bool
|
||||
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM domains d JOIN campuses c ON c.uuid=d.campus_uuid JOIN config cfg ON cfg.domain_uuid=d.uuid AND cfg.key='authorization_mode' AND cfg.value='enforcing' WHERE d.uuid=? AND d.enabled=1 AND c.enabled=1)`, domain).Scan(&live); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM domains d JOIN campuses c ON c.uuid=d.campus_uuid JOIN config cfg ON cfg.domain_uuid=d.uuid AND cfg.key='authorization_mode' AND cfg.value='enforcing' WHERE d.uuid=`+s.sqlParam(1)+` AND d.enabled=1 AND c.enabled=1)`, domain).Scan(&live); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !live {
|
||||
return nil, nil
|
||||
}
|
||||
rules, err := autoRules(ctx, tx, domain)
|
||||
rules, err := s.autoRules(ctx, tx, domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blocked := []string{}
|
||||
for _, rule := range rules {
|
||||
if rule.Mode == "required" {
|
||||
scope, e := autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
scope, e := s.autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
if errors.Is(e, sql.ErrNoRows) {
|
||||
continue
|
||||
}
|
||||
@@ -259,21 +271,21 @@ func (s *Store) automaticPublicPages(ctx context.Context, domain, onlyPath strin
|
||||
if onlyPath != "" && !autoContains(rule.Scope, onlyPath) {
|
||||
continue
|
||||
}
|
||||
g, e := governanceSnapshot(ctx, tx, domain, rule.Actor, rule.Kind, rule.ID)
|
||||
g, e := s.governanceSnapshot(ctx, tx, domain, rule.Actor, rule.Kind, rule.ID)
|
||||
if errors.Is(e, sql.ErrNoRows) || errors.Is(e, ErrAccessDenied) || errors.Is(e, ErrGovernanceInvalid) {
|
||||
continue
|
||||
}
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
current, e := autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
current, e := s.autoScope(ctx, tx, domain, rule.Kind, rule.ID)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if current != rule.Scope || !g.DraftEffectivePublic || deny(current) {
|
||||
continue
|
||||
}
|
||||
p, e := publicationImpactBounded(ctx, tx, domain, rule.Actor, rule.Kind, rule.ID, g, MaxNavigationEntries, onlyPath)
|
||||
p, e := s.publicationImpactBounded(ctx, tx, domain, rule.Actor, rule.Kind, rule.ID, g, MaxNavigationEntries, onlyPath)
|
||||
if errors.Is(e, ErrAccessDenied) {
|
||||
continue
|
||||
}
|
||||
@@ -296,7 +308,7 @@ func (s *Store) automaticPublicPages(ctx context.Context, domain, onlyPath strin
|
||||
for id := range entries {
|
||||
args = append(args, id)
|
||||
}
|
||||
rows, err := tx.QueryContext(ctx, `SELECT uuid,object_uuid,document_hash,COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),created_at_ms FROM revisions WHERE uuid IN (`+strings.TrimSuffix(strings.Repeat("?,", len(args)), ",")+`) ORDER BY created_at_ms DESC,uuid`, args...)
|
||||
rows, err := tx.QueryContext(ctx, `SELECT uuid,object_uuid,document_hash,COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),created_at_ms FROM revisions WHERE uuid IN (`+s.sqlValues(len(args))+`) ORDER BY created_at_ms DESC,uuid`, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user