Skip to main content

Managedfile

Files osapi writes on a host and keeps a record of. osapi behavior get --name managedfile and osapi 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
Sudochown
Runsstat
Writes*
Keeps stateyes
Usesnone
Used bynetplan, 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 }
updateUpdateInput { path*, content*, mode, owner, group, secret, metadata }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 (4)​

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

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, whatever its record says, so a file edited by hand is put back.
Routeother behaviors only; it is not served
Input typeUpdateInput
Output typeResult

Input (7)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
pathstringyespattern ^/Absolute path of the file
contentstringyesThe file's whole content
modestringnopattern ^[0-7]{3,4}$Permissions in octal, such as 0600; 0644 when empty
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

Output (2)​

FIELDTYPEDESCRIPTION
pathstringAbsolute path of the file
changedbooleanWhether the host changed

Examples (4)​

EXAMPLEINPUTOUTPUT
A new filepath=/etc/osapi/example.conf, content=on , mode=, owner=, group=, secret=false, metadata=<nil>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>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>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>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