NodeFile
c.NodeFile calls the API's NodeFile group. Files of the object store, deployed
to the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Get(ctx, hostname, path) | *Response[Collection[FileStatus]] | file:read | Show whether a deployed file holds what osapi wrote. |
Update(ctx, hostname, input) | *Response[Collection[FileUpdateResult]] | file:write | Deploy an object of the object store to a path. |
Delete(ctx, hostname, input) | *Response[Collection[FileDeleteResult]] | file:write | Remove a file that osapi deployed. |
Get
func (s *NodeFileService) Get(
ctx context.Context,
hostname string,
path string,
) (*Response[Collection[FileStatus]], error)
Show whether a deployed file holds what osapi wrote.
Compares the file on the host with the record that osapi keeps of what it deployed: in-sync when they agree, drifted when something changed the file, missing when osapi deployed the file and it is gone, and unmanaged when osapi did not deploy the path or undeployed it. A path that is a directory is refused.
It sends GET /api/node/{hostname}/file, and needs the permission file:read.
The examples of the method's definition:
A deployed file, go run node_file.go get:
resp, err := c.NodeFile.Get(ctx, target, "/etc/osapi/file-example.conf")
Update
func (s *NodeFileService) Update(
ctx context.Context,
hostname string,
input NodeFileUpdateInput,
) (*Response[Collection[FileUpdateResult]], error)
Deploy an object of the object store to a path.
Writes the object at the path with its mode and ownership, and keeps a record of it. A template object, or content_type template, is rendered first with .Facts, .Vars and .Hostname. The record keeps the SHA-256 of the object as it was read. A file that holds the content, mode and owner already, from the same object, does not change and reports changed: false. osapi client file stale list compares the object now with that SHA-256, so it shows the deployments whose object changed since.
It sends PUT /api/node/{hostname}/file, and needs the permission file:write.
The examples of the method's definition:
Deploy a file, go run node_file.go update:
resp, err := c.NodeFile.Update(ctx, target, client.NodeFileUpdateInput{
ObjectName: "example.conf",
Path: "/etc/osapi/file-example.conf",
})
Render a template, go run node_file.go update-2:
resp, err := c.NodeFile.Update(ctx, target, client.NodeFileUpdateInput{
ObjectName: "example.conf.tmpl",
Path: "/etc/osapi/file-example.conf",
Vars: map[string]string{"port": "8080"},
})
Delete
func (s *NodeFileService) Delete(
ctx context.Context,
hostname string,
input NodeFileDeleteInput,
) (*Response[Collection[FileDeleteResult]], error)
Remove a file that osapi deployed.
Removes the file and keeps its record, marked undeployed, so status reports unmanaged. A path that osapi did not deploy, or deleted already, does not change and reports changed: false. The object stays in the object store.
It sends DELETE /api/node/{hostname}/file, and needs the permission
file:write.
The examples of the method's definition:
Remove a deployed file, go run node_file.go delete:
resp, err := c.NodeFile.Delete(ctx, target, client.NodeFileDeleteInput{Path: "/etc/osapi/file-example.conf"})
Types
The fields of each type are the properties of its schema in the API's spec.
ContentType
ContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.
A string, one of raw, template.
FileDeleteResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the host changed. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Path | string | Absolute path of the file. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
FileStatus
| Field | Type | Description |
|---|---|---|
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Path | string | Absolute path of the file. |
SHA256 | string | SHA-256 of the file on the host, when it is there. |
State | string | in-sync, drifted, missing or unmanaged. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
FileUpdateResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the host changed. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Path | string | Absolute path of the file. |
SHA256 | string | SHA-256 of the content that the file holds. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
NodeFileDeleteInput
| Field | Type | Description |
|---|---|---|
Path | string | Absolute path of the file on the host. |
NodeFileUpdateInput
| Field | Type | Description |
|---|---|---|
ContentType | ContentType | ContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts. |
Group | string | Group that owns the file; left as written when empty. |
Mode | string | Permissions in octal, such as 0644; when empty, a file keeps its mode and a new file gets 0644. |
ObjectName | string | The object of the object store, from osapi client file list. |
Owner | string | User that owns the file; left as written when empty. |
Path | string | Absolute path of the file on the host. |
Vars | map[string]string | Variables of a template, as .Vars, each as key=value. |
RowStatus
What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
A string, one of ok, failed, skipped, timeout.
Example
examples/sdk/client/node_file.go
runs each example of this page. With no argument, it lists them.