41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
// RemoteCurrentState captures discovered committed remote published current state for one session.
|
|
type RemoteCurrentState struct {
|
|
Bucket string
|
|
SessionPrefix string
|
|
RunID string
|
|
SessionID string
|
|
Campaign string
|
|
Commit *artifacts.RemoteCommitManifest
|
|
}
|
|
|
|
func discoverRemotePublication(ctx context.Context, cfg *config.Config, store storage.ObjectStore) (*RemoteCurrentState, error) {
|
|
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil || store == nil {
|
|
return nil, fmt.Errorf("resolved config and remote object store are required")
|
|
}
|
|
bucket := artifacts.ResolvePublishBucket(cfg, nil)
|
|
if strings.TrimSpace(bucket) == "" {
|
|
return nil, fmt.Errorf("publish bucket is required")
|
|
}
|
|
prefix, err := artifacts.ResolvePublishSessionPrefix(cfg, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("resolve publish session prefix: %w", err)
|
|
}
|
|
current, err := artifacts.LoadCurrentInventory(ctx, store, prefix, artifacts.CurrentStateValidation{ExpectedSessionID: cfg.Session.SessionID, ExpectedCampaign: cfg.Session.Campaign})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("remote %w", err)
|
|
}
|
|
return &RemoteCurrentState{Bucket: bucket, SessionPrefix: prefix, RunID: current.Commit.RunID, SessionID: current.Commit.SessionID, Campaign: current.Commit.Campaign, Commit: current.Commit}, nil
|
|
}
|