68 lines
2.3 KiB
Go
68 lines
2.3 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"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
)
|
|
|
|
// RemoteCurrentState captures discovered committed remote published current state for one session.
|
|
type RemoteCurrentState struct {
|
|
Bucket string
|
|
SessionPrefix string
|
|
CurrentRunIDKey string
|
|
CurrentManifestKey string
|
|
RunID string
|
|
SessionID string
|
|
Campaign string
|
|
Manifest *manifest.Manifest
|
|
ManifestData []byte
|
|
Commit *artifacts.RemoteCommitManifest
|
|
}
|
|
|
|
func discoverRemoteCurrentState(ctx context.Context, cfg *config.Config, store storage.ObjectStore) (*RemoteCurrentState, error) {
|
|
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil {
|
|
return nil, fmt.Errorf("resolved config with pipeline/session is required")
|
|
}
|
|
if store == nil {
|
|
return nil, fmt.Errorf("remote object store is required")
|
|
}
|
|
|
|
bucket := artifacts.ResolvePublishBucket(cfg, nil)
|
|
if strings.TrimSpace(bucket) == "" {
|
|
return nil, fmt.Errorf("publish bucket is required")
|
|
}
|
|
sessionPrefix, err := artifacts.ResolvePublishSessionPrefix(cfg, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("resolve publish session prefix: %w", err)
|
|
}
|
|
requestedSession := strings.TrimSpace(cfg.Session.SessionID)
|
|
requestedCampaign := strings.TrimSpace(cfg.Session.Campaign)
|
|
current, err := artifacts.LoadCurrentState(ctx, store, sessionPrefix, artifacts.CurrentStateValidation{
|
|
ExpectedSessionID: requestedSession,
|
|
ExpectedCampaign: requestedCampaign,
|
|
ValidateRunID: true,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("remote %w", err)
|
|
}
|
|
|
|
return &RemoteCurrentState{
|
|
Bucket: bucket,
|
|
SessionPrefix: sessionPrefix,
|
|
CurrentRunIDKey: current.CurrentRunIDKey,
|
|
CurrentManifestKey: current.CurrentManifestKey,
|
|
RunID: current.RunID,
|
|
SessionID: strings.TrimSpace(current.Manifest.SessionID),
|
|
Campaign: strings.TrimSpace(current.Manifest.Campaign),
|
|
Manifest: current.Manifest,
|
|
ManifestData: append([]byte(nil), current.ManifestData...),
|
|
Commit: current.Commit,
|
|
}, nil
|
|
}
|