Skip to main content

Managed file

Files osapi writes on a host and keeps a record of. osapi dsl behavior get --name managedfile and osapi dsl behavior method get show the same.

Behavior​

Namemanagedfile
DescriptionFiles osapi writes on a host and keeps a record of
Placementnode
Internalyes
APIno
CLIno
Nextno
Platformsdebian, linux, darwin
Sudochown
Runsstat
Writes*
Keeps stateyes
Usesnone
Used bycertificate, file, netplan, ntp, schedule, service, sysctl

Methods (3)​

NAMEVERBROUTEPERMISSIONDESCRIPTION
getread--Read the record of a file osapi wrote
updatewrite--Write a file and keep a record of it
deletewrite--Remove a file osapi wrote and stop managing it

Types (3)​

NAMEINPUTOUTPUT
getGetInput { path* }Record { path, sha256, metadata, undeployed, object_sha256 }
updateUpdateInput { path*, content*, mode, owner, group, secret, metadata, object, content_type, object_sha256 }Result { path, changed }
deleteDeleteInput { path* }Result { path, changed }

Settings (0)​

None. Declare them with behavior.Config.

Telemetry​

Spanbehavior.managedfile.<method>
Child spansexec chown, exec stat, file.write, file.remove, file.chmod, kv.get, kv.put
Metricsosapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total
Attributesosapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed
Recorded inputspath (get, update, delete)

Method get​

Nameget
Verbread
DescriptionRead the record of a file osapi wrote
Routeother behaviors only; it is not served
Input typeGetInput
Output typeRecord

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
pathstringyespattern ^/Absolute path of the file

Output (5)​

FIELDTYPEDESCRIPTION
pathstringAbsolute path of the file
sha256stringChecksum of the content osapi wrote
metadataobjectWhat the caller keeps in the record
undeployedbooleanWhether osapi has stopped managing the file
object_sha256stringSHA-256 of the object that the content came from, in hex; empty for a secret or a file from no object

Examples (2)​

EXAMPLEINPUTOUTPUT
A file osapi wrotepath=/etc/osapi/example.confpath=/etc/osapi/example.conf, sha256=b6ac5bc39377e44ee783dff946f6703a994f5eb31a438e69dc0735b40060d2e8, metadata=map[setting:on], undeployed=false
A file osapi stopped managingpath=/etc/osapi/example.confpath=/etc/osapi/example.conf, sha256=b6ac5bc39377e44ee783dff946f6703a994f5eb31a438e69dc0735b40060d2e8, metadata=map[setting:on], undeployed=true

Method update​

Nameupdate
Verbwrite
DescriptionWrite a file and keep a record of it
DetailLeaves a file already holding the content alone and reports changed: false when its record has the same metadata and object. A file edited by hand is put back. New metadata, or a new object or object checksum, changes only the record.
Routeother behaviors only; it is not served
Input typeUpdateInput
Output typeResult

Input (10)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
pathstringyespattern ^/Absolute path of the file
contentstringyesThe file's whole content
modestringnopattern ^[0-7]{3,4}$Permissions in octal, such as 0600; when empty, a file keeps its mode and a new file gets 0644
ownerstringnopattern ^[a-z_][a-z0-9_-]*$?$User that owns the file; left as written when empty
groupstringnopattern ^[a-z_][a-z0-9_-]*$?$Group that owns the file; left as written when empty
secretbooleannoThe content is a secret: its record keeps no checksum of it
metadataobjectnoWhat the caller keeps in the file's record, such as the setting it holds
objectstringnoThe object of the object store that the content came from; empty when it came from no object
content_typestringnoone of raw templateHow the content was made from its object: raw or template
object_sha256stringnoSHA-256 of the object that the content came from, in hex

Output (2)​

FIELDTYPEDESCRIPTION
pathstringAbsolute path of the file
changedbooleanWhether the host changed

Examples (5)​

EXAMPLEINPUTOUTPUT
A new filepath=/etc/osapi/example.conf, content=on , mode=, owner=, group=, secret=false, metadata=<nil>, object=, content_type=, object_sha256=path=/etc/osapi/example.conf, changed=true
A secret only root readspath=/etc/myapp/token, content=s3cret , mode=0600, owner=root, group=root, secret=true, metadata=<nil>, object=, content_type=, object_sha256=path=/etc/myapp/token, changed=true
A secret only root reads, on a Macpath=/etc/myapp/token, content=s3cret , mode=0600, owner=root, group=wheel, secret=true, metadata=<nil>, object=, content_type=, object_sha256=path=/etc/myapp/token, changed=true
A file whose mode was changed by handpath=/etc/osapi/example.conf, content=on , mode=0600, owner=, group=, secret=false, metadata=<nil>, object=, content_type=, object_sha256=path=/etc/osapi/example.conf, changed=true
A file edited by handpath=/etc/osapi/example.conf, content=on , mode=, owner=, group=, secret=false, metadata=<nil>, object=, content_type=, object_sha256=path=/etc/osapi/example.conf, changed=true

Method delete​

Namedelete
Verbwrite
DescriptionRemove a file osapi wrote and stop managing it
DetailLeaves a file osapi has no record of alone, so it never removes what it did not write.
Routeother behaviors only; it is not served
Input typeDeleteInput
Output typeResult

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
pathstringyespattern ^/Absolute path of the file

Output (2)​

FIELDTYPEDESCRIPTION
pathstringAbsolute path of the file
changedbooleanWhether the host changed

Examples (2)​

EXAMPLEINPUTOUTPUT
A file osapi wrotepath=/etc/osapi/example.confpath=/etc/osapi/example.conf, changed=true
A file osapi never wrotepath=/etc/osapi/example.confpath=/etc/osapi/example.conf, changed=false