File
c.File calls the API's File group. Object Store file management operations.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx) | *Response[FileListResponse] | file:read | List stored files. |
Stale(ctx) | *Response[StaleDeploymentsResponse] | file:read | List stale file deployments. |
Get(ctx, name) | *Response[FileInfoResponse] | file:read | Get file metadata. |
Delete(ctx, name) | error | file:write | Delete a file. |
Upload(ctx, name, contentType, file) | *Response[FileUploadResponse] | file:write | Upload a file. |
Update(ctx, name, contentType, file) | *Response[FileUploadResponse] | file:write | Replace a file. |
GetChanged(ctx, name, file) | *Response[FileChanged] | GetChanged computes the SHA-256 of the content and compares it with the SHA-256 of the stored file. |
List
func (s *FileService) List(
ctx context.Context,
) (*Response[FileListResponse], error)
List stored files.
List all files stored in the Object Store.
It sends GET /api/file, and needs the permission file:read.
The examples of the method's definition:
List stored files, go run file.go list:
resp, err := c.File.List(ctx)
Stale
func (s *FileService) Stale(
ctx context.Context,
) (*Response[StaleDeploymentsResponse], error)
List stale file deployments.
Returns deployments where the source object in the Object Store has been updated since the file was last deployed. Controller-only check that compares state KV SHA-256 hashes against current object content.
It sends GET /api/file/stale, and needs the permission file:read.
The examples of the method's definition:
List stale file deployments, go run file.go stale:
resp, err := c.File.Stale(ctx)
Get
func (s *FileService) Get(
ctx context.Context,
name string,
) (*Response[FileInfoResponse], error)
Get file metadata.
Get metadata for a specific file in the Object Store.
It sends GET /api/file/{name}, and needs the permission file:read.
The examples of the method's definition:
Get file metadata, go run file.go get:
resp, err := c.File.Get(ctx, "app.conf")
Delete
func (s *FileService) Delete(
ctx context.Context,
name string,
) error
Delete a file.
Delete a file from the Object Store.
It sends DELETE /api/file/{name}, and needs the permission file:write.
The examples of the method's definition:
Delete a file, go run file.go delete:
err := c.File.Delete(ctx, "app.conf")
Upload
func (s *FileService) Upload(
ctx context.Context,
name string,
contentType types.ContentType,
file io.Reader,
) (*Response[FileUploadResponse], error)
Upload creates a file in the Object Store. It computes the SHA-256 of the content first, and skips the upload when the stored file has the same content. A file with other content is a ConflictError: Update replaces it.
The examples of the method's definition:
Upload a file, go run file.go upload:
content, err := os.ReadFile("/tmp/app.conf")
if err != nil {
return err
}
resp, err := c.File.Upload(ctx, "app.conf", types.ContentType(""), bytes.NewReader(content))
Upload a file, with --name app.conf.tmpl --file /tmp/app.conf.tmpl
--content-type template, go run file.go upload-2:
content, err := os.ReadFile("/tmp/app.conf.tmpl")
if err != nil {
return err
}
resp, err := c.File.Upload(ctx, "app.conf.tmpl", types.ContentType("template"), bytes.NewReader(content))
Update
func (s *FileService) Update(
ctx context.Context,
name string,
contentType types.ContentType,
file io.Reader,
) (*Response[FileUploadResponse], error)
Update replaces a file in the Object Store, or creates it when the name is new.
The examples of the method's definition:
Replace a file, go run file.go update:
content, err := os.ReadFile("/tmp/app.conf")
if err != nil {
return err
}
resp, err := c.File.Update(ctx, "app.conf", types.ContentType(""), bytes.NewReader(content))
GetChanged
func (s *FileService) GetChanged(
ctx context.Context,
name string,
file io.Reader,
) (*Response[FileChanged], error)
GetChanged computes the SHA-256 of the content and compares it with the SHA-256 of the stored file. Changed is true when the content differs, or the file does not exist yet.
It is not an operation of the API: it runs in the client.
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.
FileInfo
| 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. |
Name | string | The name of the file. |
SHA256 | string | SHA-256 hash of the file content. |
Size | int | File size in bytes. |
Source | string | Source of the file: 'system' or 'user'. |
FileInfoResponse
| 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. |
Name | string | The name of the file. |
SHA256 | string | SHA-256 hash of the file content. |
Size | int | File size in bytes. |
FileListResponse
| Field | Type | Description |
|---|---|---|
Items | []FileInfo | List of stored files. |
TotalItems | int | Total number of files. |
FileUploadResponse
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the file content changed. False when the Object Store already held an object with the same SHA-256 digest. |
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. |
Name | string | The name of the uploaded file. |
SHA256 | string | SHA-256 hash of the file content. |
Size | int | File size in bytes. |
StaleDeployment
| Field | Type | Description |
|---|---|---|
CurrentSHA | string | SHA-256 hash of the current object store content. |
DeployedAt | string | When the file was last deployed. |
DeployedSHA | string | SHA-256 of the object when it was deployed. |
Hostname | string | Host where the file is deployed. |
ObjectName | string | Name of the object in the Object Store. |
Path | string | Deployment path on the target host. |
Provider | string | Provider that manages this deployment. |
StaleDeploymentsResponse
| Field | Type | Description |
|---|---|---|
Items | []StaleDeployment | The stale deployments. |
TotalItems | int | Total number of stale deployments. |
Example
examples/sdk/client/file.go
runs each example of this page. With no argument, it lists them.