Documentation
¶
Overview ¶
Package project holds the state of an ifc7 managed project and defines command line operations that can be performed on it.
Index ¶
- Constants
- Variables
- func DetectSpecificationType(data []byte) (client.InterfaceType, error)
- func FormatStatusReport(statuses []InterfaceStatus) string
- func LocalRuleset(ctx context.Context, path string, doer client.HttpRequestDoer) (check.Policy, error)
- type AddParams
- type BaselineInfo
- type CheckOptions
- type CheckReport
- type CheckTarget
- type CheckoutParams
- type CommitParams
- type CompareResult
- type Config
- type FetchParams
- type InterfaceStatus
- type InterfaceStatusKind
- type LintResult
- type Manifest
- type ManifestInterface
- type Option
- type Owned
- type PolicyInfo
- type PolicySource
- type Project
- func (p *Project) Add(ctx context.Context, params AddParams) error
- func (p *Project) Check(ctx context.Context, t CheckTarget, local check.Policy, ...) *CheckReport
- func (p *Project) Checkout(ctx context.Context, params CheckoutParams) ([]string, error)
- func (p *Project) Commit(ctx context.Context, params CommitParams) error
- func (p *Project) DiffOwned(target string) (string, error)
- func (p *Project) Fetch(ctx context.Context, params FetchParams) error
- func (p *Project) FindUntrackedSpecs(root string) ([]ScanCandidate, error)
- func (p *Project) Initialize() error
- func (p *Project) Push(ctx context.Context, params PushParams) (*PushReport, error)
- func (p *Project) ResolveCheckTargets(targets []string) ([]CheckTarget, error)
- func (p *Project) ResolveComparePath(target string) (string, error)
- func (p *Project) ResolveLintTargets(targets []string) ([]string, error)
- func (p *Project) Scan(ctx context.Context, root string) ([]string, error)
- func (p *Project) Status(ctx context.Context) ([]InterfaceStatus, error)
- func (p *Project) Use(ctx context.Context, params UseParams) error
- func (p *Project) Write() error
- type PushParams
- type PushReport
- type PushResult
- type PushStatus
- type ScanCandidate
- type UseParams
- type Used
Constants ¶
const BaselineNone = "none"
BaselineNone turns the baseline off: nothing is compared.
Variables ¶
var ( ErrInvalidConfig = fmt.Errorf("invalid config") ErrRefExists = fmt.Errorf("reference already exists") ErrRefNotFound = fmt.Errorf("reference not found") ErrNameExists = fmt.Errorf("name already exists") ErrPathExists = fmt.Errorf("path already exists") ErrPathRequired = fmt.Errorf("path is required for owned interfaces") ErrNameRequired = fmt.Errorf("name is required for owned interfaces") ErrNameNotFound = fmt.Errorf("name not found") )
var ( ErrProjectExists = fmt.Errorf("project already exists") ErrInvalidRef = fmt.Errorf("invalid reference") ErrInvalidSpecification = spec.ErrInvalidSpecification )
var ErrGateBlocked = errors.New("governance gate failed")
ErrGateBlocked is returned when a gate blocks a checked interface.
var (
ErrInvalidManifest = fmt.Errorf("invalid manifest")
)
Functions ¶
func DetectSpecificationType ¶
func DetectSpecificationType(data []byte) (client.InterfaceType, error)
DetectSpecificationType reports whether data is a valid OpenAPI or JSON Schema document. Detection and validation are delegated to pkg/spec so the CLI and the hub accept the same documents.
func FormatStatusReport ¶
func FormatStatusReport(statuses []InterfaceStatus) string
FormatStatusReport renders a human-readable status report.
func LocalRuleset ¶ added in v0.0.3
func LocalRuleset(ctx context.Context, path string, doer client.HttpRequestDoer) (check.Policy, error)
LocalRuleset reads a ruleset file and resolves it into an effective ruleset, fetching ifc7 ruleset references from the hub.
Types ¶
type AddParams ¶
type AddParams struct {
Name string
Path string
// NonInteractive fails instead of offering to create a missing file.
NonInteractive bool
}
AddParams holds parameters that can be passed to the Add method
type BaselineInfo ¶ added in v0.0.3
type BaselineInfo struct {
// Source is release (the hub's latest release) or file.
Source string `json:"source"`
Version string `json:"version,omitempty"`
Path string `json:"path,omitempty"`
}
BaselineInfo describes what a check compared against.
type CheckOptions ¶ added in v0.0.3
type CheckOptions struct {
// Hub uses each interface's effective policy from the hub: its ruleset,
// weights, inline-ignore setting, change-scoped rules and waivers.
Hub bool
// Stage evaluates the hub's gates at this stage. It implies Hub.
Stage policy.Stage
// Ruleset is a local OpenLint ruleset file. ifc7 ruleset references in
// its extends are fetched from the hub. Not with Hub.
Ruleset string
// Baseline is a specification file to compare against, BaselineNone,
// or empty for the default with Hub, as on the hub: the latest release
// at push, and the highest release below Version at release. Without
// Hub the default is nothing.
Baseline string
// BaselineVersion is the version of a Baseline file, for
// breaking: requireMajor.
BaselineVersion string
// Version is the version being released, for breaking: requireMajor.
Version string
// Gates are extra gates from the command line. They run at Stage, or at
// push when Stage is empty.
Gates []policy.Gate
}
CheckOptions selects the policy, baseline and gates of a governance check.
type CheckReport ¶ added in v0.0.3
type CheckReport struct {
Name string `json:"name,omitempty"`
Ref string `json:"ref,omitempty"`
Path string `json:"path"`
Policy *PolicyInfo `json:"policy,omitempty"`
Baseline *BaselineInfo `json:"baseline,omitempty"`
*check.Result
Error string `json:"error,omitempty"`
}
CheckReport is one interface's governance check.
func (*CheckReport) Blocked ¶ added in v0.0.3
func (r *CheckReport) Blocked(strict bool) bool
Blocked reports whether a blocking gate failed, or with strict any gate.
type CheckTarget ¶ added in v0.0.3
CheckTarget is a specification to check: a file, and the owned interface it belongs to.
type CheckoutParams ¶
type CheckoutParams struct {
// Targets are owned interface names or slugs. Empty means all owned interfaces.
Targets []string
// Force overwrites local files that differ from the manifest latest revision.
Force bool
}
CheckoutParams holds parameters for Checkout.
type CommitParams ¶
type CommitParams struct {
Ref string
// Notes, when set, are used for every revision this commit creates instead of prompting.
Notes *string
// NonInteractive never prompts: notes default to empty and owned interfaces
// without a ref are skipped with a warning.
NonInteractive bool
// Warn receives warnings such as skipped interfaces. Nil discards them.
Warn func(message string)
}
CommitParams holds parameters that can be passed to the Commit method
type CompareResult ¶
type CompareResult struct {
Before string
After string
PluginID string
Output contract.CompareOutput
}
CompareResult is the outcome of running a compare plugin on two specifications.
func CompareFiles ¶
func CompareFiles(beforePath, afterPath string) (CompareResult, error)
CompareFiles runs the default change detector on two specification files.
type Config ¶
Config represents a project configuration file This file holds references to interfaces that are tracked by the project.
func ReadConfig ¶
ReadConfig reads the project configuration file from disk
type FetchParams ¶
type FetchParams struct {
Ref string
// Owned fetches only owned interfaces that have a ref, skipping the use list.
Owned bool
}
FetchParams holds parameters that can be passed to the Fetch method
type InterfaceStatus ¶
type InterfaceStatus struct {
Name string
Slug string
Path string
Ref string
Kind InterfaceStatusKind
Detail string
}
InterfaceStatus is the working-tree status of one owned interface.
type InterfaceStatusKind ¶
type InterfaceStatusKind string
InterfaceStatusKind describes how an owned interface compares to the local manifest.
const ( StatusClean InterfaceStatusKind = "clean" StatusModified InterfaceStatusKind = "modified" StatusNew InterfaceStatusKind = "new" StatusMissing InterfaceStatusKind = "missing" StatusError InterfaceStatusKind = "error" )
type LintResult ¶
type LintResult struct {
Target string
PluginID string
Output contract.LintOutput
}
LintResult is the outcome of running a lint plugin on a local specification.
func LintFile ¶
func LintFile(path string) (LintResult, error)
LintFile runs the default linter for a specification file.
type Manifest ¶
type Manifest struct {
// Interfaces maps canonicalUrl (e.g. "/i/@user/slug") to interface data.
// Before an interface is created on the server it may be temporarily keyed by
// its local name (or interface ID, for legacy manifests).
Interfaces map[string]*ManifestInterface `json:"interfaces"`
}
Manifest is the structure of the local project manifest file (manifest.json) This holds local copies and version history of all the interfaces tracked by the project.
func ReadManifest ¶
ReadManifest reads the manifest from a file
type ManifestInterface ¶
type ManifestInterface struct {
client.Interface
Revisions map[string]*client.InterfaceRevision `json:"revisions"` // map of revision ID to revision data
Releases map[string]*client.InterfaceRelease `json:"releases"` // map of release version to release data
}
ManifestInterface holds the state of a single interface in the project manifest.
type Option ¶
type Option func(*Project)
Option is a function that configures a Project
func WithClient ¶ added in v0.0.2
func WithClient(c client.ClientWithResponsesIfc) Option
WithClient sets the hub client instead of creating one from the environment.
type Owned ¶
type Owned struct {
Name string `json:"name" yaml:"name"`
Ref string `json:"ref" yaml:"ref"`
Path string `json:"path" yaml:"path"`
}
Owned holds a reference to a local interface that is managed by the project.
type PolicyInfo ¶ added in v0.0.3
type PolicyInfo struct {
Source PolicySource `json:"source"`
RulesetSHA256 string `json:"rulesetSha256"`
Ruleset string `json:"ruleset,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
HasInterfaceLayer bool `json:"hasInterfaceLayer,omitempty"`
GroupID string `json:"groupId,omitempty"`
Waivers int `json:"waivers"`
Gates int `json:"gates"`
}
PolicyInfo describes the policy a check used.
type PolicySource ¶ added in v0.0.3
type PolicySource string
PolicySource says where a check's policy came from.
const ( // PolicyDefault is the built-in default ruleset with no gates of its own. PolicyDefault PolicySource = "default" // PolicyLocal is a ruleset file given with --ruleset. PolicyLocal PolicySource = "local" // PolicyHub is the interface's effective policy on the hub. PolicyHub PolicySource = "hub" )
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
Project holds the state of an ifc7 managed project
func Load ¶
Load loads a project from local files. ifc.yaml must exist. A missing .ifc/manifest.json is treated as an empty manifest (as on a fresh checkout, where .ifc/ is gitignored); a malformed one is an error.
func (*Project) Add ¶
Add adds a local interface to the project's "own" list in (ifc.yaml). If the file at Path does not exist, the user is asked to create it (including any missing parent directories).
func (*Project) Check ¶ added in v0.0.3
func (p *Project) Check(ctx context.Context, t CheckTarget, local check.Policy, localSource PolicySource, opts CheckOptions) *CheckReport
Check runs a governance check on one target. local is the policy to use when opts selects no hub policy (the zero Policy is the built-in default). Errors that concern only this target are returned in the report.
func (*Project) Checkout ¶
Checkout writes owned interface working-tree files from the latest revision in the local manifest. It does not contact the remote hub.
Missing files are created. Files that already match the manifest are left unchanged. Files with local modifications are skipped unless Force is set.
func (*Project) Commit ¶
func (p *Project) Commit(ctx context.Context, params CommitParams) error
Commit adds local changes to owned interfaces to the manifest
func (*Project) DiffOwned ¶
DiffOwned returns a unified diff of an owned interface's working-tree file against the latest revision stored in the local manifest. An empty string means there are no differences. target may be an owned interface name or its manifest slug. It does not contact the remote hub.
func (*Project) Fetch ¶
func (p *Project) Fetch(ctx context.Context, params FetchParams) error
Fetch fetches remote copies of interfaces tracked by the project
func (*Project) FindUntrackedSpecs ¶
func (p *Project) FindUntrackedSpecs(root string) ([]ScanCandidate, error)
FindUntrackedSpecs walks root for valid OpenAPI / JSON Schema files not already tracked as owned interfaces in ifc.yaml. Returned paths are relative to the current working directory so they can be passed directly to Add.
func (*Project) Initialize ¶
Initialize creates the necessary folders and files for a project if they do not exist in the current folder
func (*Project) Push ¶
func (p *Project) Push(ctx context.Context, params PushParams) (*PushReport, error)
Push pushes local changes to the remote server. Push stops at the first interface that fails; that one is reported as failed and the rest as not attempted. The report is always non-nil and reflects partial progress when err is not nil.
func (*Project) ResolveCheckTargets ¶ added in v0.0.3
func (p *Project) ResolveCheckTargets(targets []string) ([]CheckTarget, error)
ResolveCheckTargets resolves lint arguments like ResolveLintTargets, and also returns the owned interface each one belongs to. A file path matches an owned interface with the same path.
func (*Project) ResolveComparePath ¶
ResolveComparePath resolves a CLI target (owned name or file path) to a file path.
func (*Project) ResolveLintTargets ¶
ResolveLintTargets resolves CLI targets to file paths. Empty targets means all owned interfaces. Named targets match owned names or file paths.
func (*Project) Scan ¶
Scan recursively searches root for valid OpenAPI / JSON Schema documents that are not already listed in ifc.yaml, presents them in a TUI, and adds selected files using the same logic as Add. root defaults to the current directory.
func (*Project) Status ¶
func (p *Project) Status(ctx context.Context) ([]InterfaceStatus, error)
Status compares each owned interface on disk against the local manifest. It does not contact the remote hub.
type PushParams ¶
type PushParams struct {
Name string
// NonInteractive never prompts: owned interfaces without a ref are skipped.
NonInteractive bool
}
PushParams holds parameters that can be passed to the Push method
type PushReport ¶ added in v0.0.2
type PushReport struct {
Interfaces []PushResult `json:"interfaces"`
Messages []string `json:"-"`
}
PushReport is the outcome of a Push: one result per targeted owned interface, in ifc.yaml order, plus user-facing status messages. It is the shape of push --json.
func NewPushReport ¶ added in v0.0.2
func NewPushReport() *PushReport
NewPushReport returns an empty report whose JSON form lists no interfaces.
type PushResult ¶ added in v0.0.2
type PushResult struct {
Name string `json:"name"`
Ref string `json:"ref,omitempty"`
Path string `json:"path"`
Status PushStatus `json:"status"`
RevisionIDs []string `json:"revisionIds,omitempty"`
Reason string `json:"reason,omitempty"`
Error string `json:"error,omitempty"`
}
PushResult reports what Push did with one owned interface.
type PushStatus ¶ added in v0.0.2
type PushStatus string
PushStatus is the outcome of pushing one owned interface.
const ( PushStatusPushed PushStatus = "pushed" PushStatusUpToDate PushStatus = "up_to_date" PushStatusSkipped PushStatus = "skipped" PushStatusFailed PushStatus = "failed" PushStatusNotAttempted PushStatus = "not_attempted" )
type ScanCandidate ¶
type ScanCandidate struct {
Path string
Type client.InterfaceType
}
ScanCandidate is an untracked OpenAPI or JSON Schema file discovered by Scan.