Documentation
¶
Overview ¶
Package sysmlapi drives any server speaking the standard SysML v2 API: the projects, branches, commits and elements resources the OMG pilot's SysML-v2-API-Services and Flexo MMS alike serve. It knows nothing of a server's extras — Flexo's Layer 1, orgs and Turtle graph writes live in package flexo, which builds on this client.
Index ¶
- Constants
- Variables
- func CheckURL(raw string) error
- func CommitRequest(changes []reposync.ElementChange, message string) ([]byte, error)
- func ElementsGraph(elements []Element) (*rdf.Graph, error)
- func Loopback(host string) bool
- func Status(err error) int
- type Branch
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Branch(ctx context.Context, project, branch string) (Branch, error)
- func (c *Client) Branches(ctx context.Context, project string) ([]Branch, error)
- func (c *Client) Commits(ctx context.Context, project string) ([]Commit, error)
- func (c *Client) Config() Config
- func (c *Client) CreateProject(ctx context.Context, id, name, branch string) (Project, error)
- func (c *Client) Do(ctx context.Context, method, target string, body []byte, contentType string, ...) ([]byte, http.Header, error)
- func (c *Client) ElementByID(ctx context.Context, project, commit, id string) (Element, error)
- func (c *Client) Elements(ctx context.Context, project, commit string, size int) (Listing, error)
- func (c *Client) PostChanges(ctx context.Context, project, branch string, changes []byte) (Commit, error)
- func (c *Client) Project(ctx context.Context, id string) (Project, error)
- func (c *Client) Projects(ctx context.Context) ([]Project, error)
- func (c *Client) Reachable(ctx context.Context) error
- func (c *Client) Repository(project, branch string) *Repository
- func (c *Client) Roots(ctx context.Context, project, commit string) ([]Element, error)
- type Commit
- type Config
- type Element
- type Listing
- type PlaintextError
- type Project
- type Ref
- type Repository
- func (r *Repository) Branch() string
- func (r *Repository) Client() *Client
- func (r *Repository) Commit(ctx context.Context, changes []reposync.ElementChange, message string) (string, error)
- func (r *Repository) Graph(ctx context.Context) (*rdf.Graph, error)
- func (r *Repository) GraphAt(ctx context.Context, commit string) (*rdf.Graph, error)
- func (r *Repository) Head(ctx context.Context) (string, error)
- func (r *Repository) Project() string
- func (r *Repository) Resume(commit string)
- func (r *Repository) Seen() string
- type Representation
- type StaleBranchError
- type StatusError
- type UnreachableError
- type UnrepresentableError
Constants ¶
const ( EnvBaseURL = "FLEXO_SYSMLV2_URL" EnvToken = "FLEXO_INTEROP_TOKEN" // #nosec G101 -- a variable name, not a credential EnvPlainHTTP = "FLEXO_ALLOW_PLAIN_HTTP" )
Environment variables a client is configured from. The base URL and the token are the ones `sysml -sync` reads, so a REPL and the command line address one server the same way; the token is optional, as the pilot's server takes none.
const DefaultBaseURL = "http://localhost:8083"
DefaultBaseURL is the SysML v2 API port of flexo-mms-sysmlv2's compose file.
const DefaultTimeout = 60 * time.Second
DefaultTimeout bounds one request when the configuration names none.
Variables ¶
var ErrUntyped = errors.New("the element has no single SysML metaclass")
ErrUntyped is an element with no single sysml: metaclass, which the API's payload cannot state.
Functions ¶
func CheckURL ¶
CheckURL refuses a plaintext URL to anything but a loopback host, unless the environment opts in with FLEXO_ALLOW_PLAIN_HTTP=1, and any URL that is not http(s).
func CommitRequest ¶
func CommitRequest(changes []reposync.ElementChange, message string) ([]byte, error)
CommitRequest encodes a batch of element changes as the API's CommitRequest: creates and updates send the element whole under its identity, deletes send a null payload.
func ElementsGraph ¶
ElementsGraph reads a commit's elements as the RDF graph their API JSON spells, the inverse of what a commit's payloads were written from.
Types ¶
type Branch ¶
Branch is one branch as the API describes it: its id, its name and the commit at its head.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one server. It is safe for sequential use.
func (*Client) CreateProject ¶
CreateProject creates a project. An id names the project when the server honours client ids, as Flexo does; a default branch names the branch the server creates with it. Either empty leaves the choice to the server.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, target string, body []byte, contentType string, headers map[string]string) ([]byte, http.Header, error)
Do performs one request, authorized when the configuration holds a token, and returns the response body and headers, failing on any status outside 2xx.
func (*Client) ElementByID ¶
ElementByID reads one element directly. A non-2xx answer is returned as the error, with Status(err) carrying the code.
func (*Client) Elements ¶
Elements reads a commit's elements a page at a time. A page that overruns size or repeats an element is a server ignoring paging; the repeat is dropped rather than counted twice.
func (*Client) PostChanges ¶
func (c *Client) PostChanges(ctx context.Context, project, branch string, changes []byte) (Commit, error)
PostChanges commits a CommitRequest body through the server's commit path and returns the commit it made. An empty branch takes the default one.
func (*Client) Reachable ¶
Reachable reports whether the server answers: the project list is the cheapest read every server has.
func (*Client) Repository ¶
func (c *Client) Repository(project, branch string) *Repository
Repository addresses one project branch for a sync.
type Config ¶
type Config struct {
BaseURL string // the API's base path, without a trailing slash
Token string // bearer token, sent only when set
Timeout time.Duration // per-request bound; DefaultTimeout when zero
}
Config addresses one SysML v2 API server.
func ConfigFromEnv ¶
func ConfigFromEnv() Config
ConfigFromEnv reads the base URL and the token from the environment; the URL defaults to the compose file's port, the token to none.
type Element ¶
type Element map[string]json.RawMessage
Element is one element as the API delivers it: property name to raw JSON value, kept raw so a value's shape — reference, literal, array — is observable rather than normalized away by decoding into a Go type.
type Listing ¶
Listing is one element listing: the elements it delivered, the number of responses it took, and whether the server ignored the paging parameters.
type PlaintextError ¶
type PlaintextError struct {
URL string
}
PlaintextError is a bearer token about to cross the network unencrypted: an http:// URL whose host is not this machine.
func (*PlaintextError) Error ¶
func (e *PlaintextError) Error() string
type Project ¶
type Project struct {
ID string `json:"@id"`
Name string `json:"name"`
DefaultBranch Ref `json:"defaultBranch"`
}
Project is one project as the API describes it.
type Ref ¶
type Ref struct {
ID string `json:"@id"`
}
Ref is a reference to another resource, as the API spells it.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is one project branch as a sync's repository: read as the graph its elements spell, written through the commit path so every element keeps its id. It remembers the head its last read stood at — empty for a branch read before its first commit — and refuses to commit past a head that has since moved.
func (*Repository) Branch ¶
func (r *Repository) Branch() string
Branch is the id of the branch the repository reads and writes.
func (*Repository) Client ¶
func (r *Repository) Client() *Client
Client is the client the repository reads and writes through.
func (*Repository) Commit ¶
func (r *Repository) Commit(ctx context.Context, changes []reposync.ElementChange, message string) (string, error)
Commit writes one batch as one SysML v2 commit. The API takes no precondition, so once a head is known — read by Graph, resumed or written — it is re-read first and a moved one refuses the write as a StaleBranchError; a branch read without a head has to be still without one.
func (*Repository) Graph ¶
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. A branch with no commit yet reads as an empty graph.
func (*Repository) GraphAt ¶
GraphAt reads the branch as one commit left it: its elements, paged through and read as the graph their JSON spells.
func (*Repository) Head ¶
func (r *Repository) Head(ctx context.Context) (string, error)
Head is the branch's current head commit; empty for a branch no commit has reached yet, as a freshly created project's is on some servers.
func (*Repository) Project ¶
func (r *Repository) Project() string
Project is the id of the project the repository is a branch of.
func (*Repository) Resume ¶
func (r *Repository) Resume(commit string)
Resume records the last-seen commit a saved sync state carries, so a head that has since moved is refused instead of written past.
func (*Repository) Seen ¶
func (r *Repository) Seen() string
Seen is the head commit the last Graph read stood at, or the last commit this repository wrote; empty before either.
type Representation ¶
type Representation struct{}
Representation is what the server 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 struct {
Project, Branch, Seen, Head string
}
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.
func (*StaleBranchError) Error ¶
func (e *StaleBranchError) Error() string
type StatusError ¶
StatusError is a response outside 2xx. It carries the body, because servers answer with their diagnostic there.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Message ¶
func (e *StatusError) Message() string
Message is the server's diagnostic: the body's message field when it is a JSON object stating one, else the body itself, trimmed to a line's worth.
type UnreachableError ¶
UnreachableError is a server that answered nothing: the connection failed before any status came back.
func (*UnreachableError) Error ¶
func (e *UnreachableError) Error() string
func (*UnreachableError) Unwrap ¶
func (e *UnreachableError) Unwrap() error
type UnrepresentableError ¶
UnrepresentableError is a value the server's JSON commit path has no spelling for; the diff refuses it rather than approximating.
func (*UnrepresentableError) Error ¶
func (e *UnrepresentableError) Error() string