flexo

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flexo drives a running Flexo MMS stack — the Layer 1 service and the SysML v2 API in front of it — so a project branch can be read and written as a model's repository: `sysml -sync-diff` and `-sync-apply` sync element-wise, `sysml -convert` reads a branch URL as notation or pushes a whole Turtle graph to it.

The standard API — projects, branches, commits, elements — is package sysmlapi's; this package adds what only Flexo has: the Layer 1 org a project lives under, its Turtle graph store, and the SPARQL read of a commit's graph. What a running stack makes of this project's RDF is measured by tools/referee/flexo over this client.

Index

Constants

View Source
const (
	EnvLayer1URL  = "FLEXO_LAYER1_URL"
	EnvSysMLV2URL = sysmlapi.EnvBaseURL
	EnvToken      = sysmlapi.EnvToken
	EnvOrg        = "FLEXO_SYSMLV2_ORG"
	EnvPlainHTTP  = sysmlapi.EnvPlainHTTP
	EnvTimeout    = "FLEXO_TIMEOUT"
)

Environment variables read by ConfigFromEnv.

View Source
const (
	DefaultLayer1URL  = "http://localhost:8080"
	DefaultSysMLV2URL = sysmlapi.DefaultBaseURL
	DefaultOrg        = "sysmlv2"
	DefaultTimeout    = sysmlapi.DefaultTimeout
)

Defaults matching flexo-mms-sysmlv2/docker-compose/docker-compose.yml, so a stack brought up from that file needs no configuration beyond the token.

Variables

View Source
var ErrBlankNode = errors.New("the graph holds a blank node, which no element id can address")

ErrBlankNode is a blank node in a graph read back from the stack; elements are IRIs, so a sync has no way to key one.

Functions

func SameEndpoint

func SameEndpoint(a, b string) bool

SameEndpoint reports whether two URLs name the same endpoint: scheme, host and effective port equal, path equal once trailing slashes are trimmed.

func Status

func Status(err error) int

Status returns the HTTP status of a failed request, or 0 if err is not one.

Types

type BranchRef

type BranchRef struct {
	SysMLV2URL string
	Project    string
	Branch     string
}

BranchRef is one project branch as a command-line URL names it; SysMLV2URL is the endpoint the URL spelled out, empty for the configured default.

func ParseBranchURL

func ParseBranchURL(raw string) (ref BranchRef, ok bool, err error)

ParseBranchURL resolves the branch URL forms a command line accepts, and reports ok=false for a string that is a file path rather than a URL:

http(s)://host[:port][/base]/projects/{project}/branches/{branch}
flexo://{project}/{branch}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to one stack: the standard API through a sysmlapi client, Layer 1 directly. It is safe for sequential use by one caller.

func New

func New(cfg Config) *Client

New returns a client for cfg.

func (*Client) API added in v0.10.0

func (c *Client) API() *sysmlapi.Client

API is the standard SysML v2 API client the stack is driven through; Layer 1 requests go through its Do with the same token.

func (*Client) BranchETag

func (c *Client) BranchETag(ctx context.Context, project, branch string) (string, error)

BranchETag reads the etag Layer 1's branch resource carries — the entity tag a conditional graph write quotes as its If-Match.

func (*Client) CommitGraph

func (c *Client) CommitGraph(ctx context.Context, project, commit string) (*rdf.Graph, error)

CommitGraph reads the model graph as one commit left it, through Layer 1's SPARQL endpoint, in the typed form the store holds rather than Turtle's shorthand.

func (*Client) Config

func (c *Client) Config() Config

Config returns the configuration the client was built with.

func (*Client) PutGraph

func (c *Client) PutGraph(ctx context.Context, project, branch string, turtle []byte, message, ifMatch string) (PutResult, error)

PutGraph replaces a branch's model graph, conditional on ifMatch ("*" = any). 412 also answers a committed write, so the response headers are returned either way.

func (*Client) Repository

func (c *Client) Repository(project, branch string) *Repository

Repository addresses one project branch for a sync.

type Config

type Config struct {
	Layer1URL  string        // Layer 1 service, which owns orgs, repos, branches and graphs
	SysMLV2URL string        // SysML v2 API, which owns projects, commits and elements
	Token      string        // bearer token accepted by both services
	Org        string        // Layer 1 org the SysML v2 service keeps its projects under
	Timeout    time.Duration // bound on one request; a whole-graph write of a large model needs more than the default
}

Config addresses one running stack.

func ConfigFromEnv

func ConfigFromEnv() (Config, error)

ConfigFromEnv reads the stack's addresses from the environment, defaulting to the published compose file's ports, and the request bound from FLEXO_TIMEOUT (a Go duration, 60s unless set). The token has no default: it is a credential and is never written to the repository.

func (Config) CheckTransport

func (cfg Config) CheckTransport() error

CheckTransport refuses a token over plaintext to anything but a loopback host, unless the environment opts in with FLEXO_ALLOW_PLAIN_HTTP=1.

type PlaintextError

type PlaintextError = sysmlapi.PlaintextError

PlaintextError is a bearer token about to cross the network unencrypted: an http:// URL whose host is not this machine.

type PutResult

type PutResult struct {
	Commit   string
	Location string
}

PutResult is the ETag and Location a graph write's response carries; a committed write has both, a refused 412 neither.

type Repository

type Repository struct {
	*sysmlapi.Repository
	// contains filtered or unexported fields
}

Repository is one project branch as a sync's repository: read as a graph through Layer 1, written through the service's commit path so every element keeps its id, or replaced whole by a Turtle push. It remembers the head its last read stood at and refuses to commit past a head that has since moved.

func (*Repository) Graph

func (r *Repository) Graph(ctx context.Context) (*rdf.Graph, error)

Graph reads the branch as its head commit left it, so the read is of one commit rather than of a branch that may move under it.

func (*Repository) GraphAt

func (r *Repository) GraphAt(ctx context.Context, commit string) (*rdf.Graph, error)

GraphAt reads the branch as one earlier commit left it, through Layer 1's SPARQL endpoint: the last-seen graph a diff needs to tell a repository change from its own.

func (*Repository) Head

func (r *Repository) Head(ctx context.Context) (string, error)

Head is the branch's current head commit; a branch naming none is an error, as every Flexo branch stands at a commit.

func (*Repository) Push

func (r *Repository) Push(ctx context.Context, turtle []byte, message string) (string, error)

Push replaces the branch's whole model graph with the given Turtle and returns the commit made; a head that moved past what was seen is refused.

type Representation

type Representation = sysmlapi.Representation

Representation is what the service stores of a posted graph: sysml: properties only, values as JSON spells them. A diff under it converges with an apply.

type StaleBranchError

type StaleBranchError = sysmlapi.StaleBranchError

StaleBranchError is a branch whose head moved between the read a change set was computed against and the commit that would have written it; nothing was written, and the change set has to be recomputed against the new head.

type SupersededPushError

type SupersededPushError struct {
	Project, Branch, Commit, Head string
}

SupersededPushError is a committed graph write, named by its Location, whose branch head has since moved on; the baseline must come from reading the branch again.

func (*SupersededPushError) Error

func (e *SupersededPushError) Error() string

type UnrecordedPushError

type UnrecordedPushError struct {
	Project, Branch string
}

UnrecordedPushError is a graph write the branch accepted but whose response named no commit; a later head read could be another writer's, so none is recorded.

func (*UnrecordedPushError) Error

func (e *UnrecordedPushError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL