Skip to main content

File

c.File calls the API's File group. Object Store file management operations.

Methods​

MethodReturnsPermissionDescription
List(ctx)*Response[FileListResponse]file:readList stored files.
Stale(ctx)*Response[StaleDeploymentsResponse]file:readList stale file deployments.
Get(ctx, name)*Response[FileInfoResponse]file:readGet file metadata.
Delete(ctx, name)errorfile:writeDelete a file.
Upload(ctx, name, contentType, file)*Response[FileUploadResponse]file:writeUpload a file.
Update(ctx, name, contentType, file)*Response[FileUploadResponse]file:writeReplace 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​

FieldTypeDescription
ContentTypeContentTypeContentType 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.
NamestringThe name of the file.
SHA256stringSHA-256 hash of the file content.
SizeintFile size in bytes.
SourcestringSource of the file: 'system' or 'user'.

FileInfoResponse​

FieldTypeDescription
ContentTypeContentTypeContentType 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.
NamestringThe name of the file.
SHA256stringSHA-256 hash of the file content.
SizeintFile size in bytes.

FileListResponse​

FieldTypeDescription
Items[]FileInfoList of stored files.
TotalItemsintTotal number of files.

FileUploadResponse​

FieldTypeDescription
ChangedboolWhether the file content changed. False when the Object Store already held an object with the same SHA-256 digest.
ContentTypeContentTypeContentType 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.
NamestringThe name of the uploaded file.
SHA256stringSHA-256 hash of the file content.
SizeintFile size in bytes.

StaleDeployment​

FieldTypeDescription
CurrentSHAstringSHA-256 hash of the current object store content.
DeployedAtstringWhen the file was last deployed.
DeployedSHAstringSHA-256 of the object when it was deployed.
HostnamestringHost where the file is deployed.
ObjectNamestringName of the object in the Object Store.
PathstringDeployment path on the target host.
ProviderstringProvider that manages this deployment.

StaleDeploymentsResponse​

FieldTypeDescription
Items[]StaleDeploymentThe stale deployments.
TotalItemsintTotal number of stale deployments.

Example​

examples/sdk/client/file.go runs each example of this page. With no argument, it lists them.