Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Group = endpoint.Define( "password", "The password of a user", endpoint.Area(area.Security), endpoint.Prefix("node/{hostname}/user/{name}"), endpoint.Uses[dispatch.Deps](), endpoint.Tag("password_operations", "User password", "The password of a user"), endpoint.CommandNotes("The [password behavior](../../../../../../reference/behaviors/security/user/password/password.md) page tells where the behavior runs, what it is built on and its settings."), endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc), endpoint.Put[UpdateRequest, UserPasswordUpdateResponse]("update"). Handle(HandleUpdate). ID("PutNodeUserPassword"). Describe("Set the password of a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Sets the password with chpasswd -e, from its hash on standard input. The controller hashes the password, so the job and NATS have only the hash. Each call makes a new hash, so it always reports changed: true. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped."). Example("--target web-01 --name osapitest --password -", "Set a password"). Result("Set a password, on one host:\n\n```ansi\n$ osapi client node user password update --target web-01 --name osapitest --password -\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 1 host: \x1b[38;2;103;234;147m1 changed\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n```\n\nOn each host, where one cannot run it:\n\n```ansi\n$ osapi client node user password update --target _all --name osapitest --password -\n\x1b[1;38;2;0;213;255mResults:\x1b[0m\n \x1b[38;2;10;143;176mHOSTNAME \x1b[0m\x1b[38;2;10;143;176mSTATUS \x1b[0m\x1b[38;2;10;143;176mNAME\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m \x1b[1mosapitest\x1b[0m\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mchanged\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 3 hosts: \x1b[38;2;103;234;147m2 changed\x1b[0m, \x1b[38;5;222m1 skipped\x1b[0m \x1b[38;2;138;138;138mjob 550e8400-e29b-41d4-a716-446655440000\x1b[0m \x1b[38;2;138;138;138mtrace 26e448c9dbe1c4a8d216a98c675079c9\x1b[0m\n\n\x1b[1;38;2;255;0;255mDetails:\x1b[0m\n \x1b[1mmac-01\x1b[0m \x1b[38;5;222mskipped\x1b[0m operation not supported on this OS family\n```\n\nWith `--json`, the API's response:\n\n```json\n{\n \"job_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n \"results\": [\n {\n \"changed\": true,\n \"hostname\": \"web-01\",\n \"name\": \"osapitest\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nWith the default settings, each example does this on the host:\n\n| Example | On the host |\n| --- | --- |\n| Set a password | runs `chpasswd -e` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| No password | `--name alice` | give the password |\n| A user that the host does not have | `--name nobody` | not found |\n| A hash that is not a crypt hash | `--name alice` | crypt hash |\n| A name that is an option | `--name -r` | account_name |\n| A name longer than 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |\n| A password with a line break | `--name alice --password -` | no_linebreak |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host does not have what the request names, such as the object of a deploy."), endpoint.Conflict(behavior.ErrNotManaged, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotManaged), endpoint.Conflict(behavior.ErrNotInstalled, "osapi did not deploy the item, so it does not change it, or the host does not have a program that the method needs.").Because(types.ReasonNotInstalled), endpoint.Invalid(dispatch.ErrInvalid, "The request is not valid, or the host refuses the input, such as a path that is a directory.")), )
Group is password as an endpoint group, which its spec comes from.
Functions ¶
Types ¶
type UpdateRequest ¶
type UpdateRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `doc:"The user, such as alice" in:"path" json:"name" param:"UserPasswordName" validate:"required,max=32,account_name"`
Body UserPasswordUpdateRequest `in:"body" validate:"required"`
}
UpdateRequest is the request of password update: its target and its input.
type UserPasswordResult ¶
type UserPasswordResult struct {
Hostname string `doc:"Hostname of the agent that produced this result." json:"hostname"`
Status types.RowStatus `doc:"The status of the operation for this host." json:"status"`
Name *string `doc:"The user" json:"name,omitempty"`
Changed *bool `doc:"Whether the host changed" json:"changed,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
UserPasswordResult is the result of password on one host.
type UserPasswordUpdateRequest ¶
type UserPasswordUpdateRequest struct {
Password secret.Value `doc:"The new password, which osapi hashes on the controller" json:"password,omitempty" validate:"omitempty,no_linebreak"`
}
UserPasswordUpdateRequest is the body of password update.
type UserPasswordUpdateResponse ¶
type UserPasswordUpdateResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserPasswordResult `json:"results"`
}
UserPasswordUpdateResponse is each target host's result.
func HandleUpdate ¶
func HandleUpdate( ctx context.Context, d dispatch.Deps, in UpdateRequest, ) (UserPasswordUpdateResponse, error)
HandleUpdate runs password update on the target, for the endpoint server.