Documentation
¶
Index ¶
- Variables
- func Routes(s *server.Server) []server.Route
- type CreateRequest
- type DeleteRequest
- type GetRequest
- type ListRequest
- type UpdateRequest
- type UserAccount
- type UserCollectionResponse
- type UserCreateRequest
- type UserCreateResponse
- type UserDeleteResponse
- type UserGetResponse
- type UserResult
- type UserUpdateRequest
- type UserUpdateResponse
Constants ¶
This section is empty.
Variables ¶
var Group = endpoint.Define( "user", "The users of the host", endpoint.Area(area.Security), endpoint.Prefix("node/{hostname}"), endpoint.Uses[dispatch.Deps](), endpoint.Tag("user_operations", "User", "The users of the host"), endpoint.CommandNotes("The [user behavior](../../../../../reference/behaviors/security/user/user.md) page tells where the behavior runs, what it is built on and its settings."), endpoint.Doc[types.RowStatus](dispatch.RowStatusDoc), endpoint.Get[ListRequest, UserCollectionResponse]("list"). Handle(HandleList). ID("GetNodeUser"). Describe("List the users of the host"). Permission("user:read"). Returns("Each target host's result."). Explain("Lists each user with its IDs, home, shell, groups and whether it is locked, through gohai: from /etc/passwd, /etc/group and /etc/shadow on Linux, and from the directory service with dscl on macOS. The groups are those that list the user as a member, besides its primary group."). Example("--target web-01", "A host with users"). Result("A host with users, on one host:\n\n```ansi\n$ osapi client node user list --target web-01\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\x1b[38;2;10;143;176mUID \x1b[0m\x1b[38;2;10;143;176mGID \x1b[0m\x1b[38;2;10;143;176mHOME \x1b[0m\x1b[38;2;10;143;176mSHELL \x1b[0m\x1b[38;2;10;143;176mGROUPS \x1b[0m\x1b[38;2;10;143;176mLOCKED\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n \x1b[38;2;138;138;138mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mroot\x1b[0m 0 0 /root /bin/bash none yes\n\n 1 host: \x1b[38;2;103;234;147m1 ok\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 list --target _all\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\x1b[38;2;10;143;176mUID \x1b[0m\x1b[38;2;10;143;176mGID \x1b[0m\x1b[38;2;10;143;176mHOME \x1b[0m\x1b[38;2;10;143;176mSHELL \x1b[0m\x1b[38;2;10;143;176mGROUPS \x1b[0m\x1b[38;2;10;143;176mLOCKED\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n \x1b[38;2;138;138;138mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mroot\x1b[0m 0 0 /root /bin/bash none yes\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n \x1b[38;2;138;138;138mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mroot\x1b[0m 0 0 /root /bin/bash none yes\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\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 \"gid\": 1000,\n \"groups\": [\n \"developers\"\n ],\n \"home\": \"/home/alice\",\n \"hostname\": \"web-01\",\n \"locked\": false,\n \"name\": \"alice\",\n \"shell\": \"/bin/bash\",\n \"status\": \"ok\",\n \"uid\": 1000\n },\n {\n \"gid\": 0,\n \"home\": \"/root\",\n \"hostname\": \"web-01\",\n \"locked\": true,\n \"name\": \"root\",\n \"shell\": \"/bin/bash\",\n \"status\": \"ok\",\n \"uid\": 0\n }\n ]\n}\n```"). 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.")), endpoint.Get[GetRequest, UserGetResponse]("get"). Handle(HandleGet). ID("GetNodeUserByKey"). Describe("Get one user"). Permission("user:read"). Returns("Each target host's result."). Explain("Reads one user from the same list. A user that the host does not have is not found."). Example("--target web-01 --name alice", "A user"). Result("A user, on one host:\n\n```ansi\n$ osapi client node user get --target web-01 --name alice\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\x1b[38;2;10;143;176mUID \x1b[0m\x1b[38;2;10;143;176mGID \x1b[0m\x1b[38;2;10;143;176mHOME \x1b[0m\x1b[38;2;10;143;176mSHELL \x1b[0m\x1b[38;2;10;143;176mGROUPS \x1b[0m\x1b[38;2;10;143;176mLOCKED\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n\n 1 host: \x1b[38;2;103;234;147m1 ok\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 get --target _all --name alice\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\x1b[38;2;10;143;176mUID \x1b[0m\x1b[38;2;10;143;176mGID \x1b[0m\x1b[38;2;10;143;176mHOME \x1b[0m\x1b[38;2;10;143;176mSHELL \x1b[0m\x1b[38;2;10;143;176mGROUPS \x1b[0m\x1b[38;2;10;143;176mLOCKED\x1b[0m\n \x1b[1mweb-01\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1malice\x1b[0m 1000 1000 /home/alice /bin/bash developers no\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\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 \"gid\": 1000,\n \"groups\": [\n \"developers\"\n ],\n \"home\": \"/home/alice\",\n \"hostname\": \"web-01\",\n \"locked\": false,\n \"name\": \"alice\",\n \"shell\": \"/bin/bash\",\n \"status\": \"ok\",\n \"uid\": 1000\n }\n ]\n}\n```\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A user that the host does not have | `--name nobody` | not found |\n| A name that is an option | `--name -r` | account_name |\n| A name longer than 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host has no user with that name."), 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.")), endpoint.Post[CreateRequest, UserCreateResponse]("create"). Handle(HandleCreate). ID("PostNodeUser"). Describe("Add a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Adds the user with useradd, with its home directory, and sets its password with chpasswd when one is given. The controller hashes the password, so the job and NATS have only the hash. A user that the host has already does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped."). Example("--target web-01 --name osapitest", "Add a user"). Example("--target web-01 --name osapitest --shell /bin/sh --groups root --password -", "Add a user with a shell, groups and a password"). Example("--target web-01 --name osapitest --uid 1999 --gid 100 --home /home/osapitest --system", "Add a system user with its IDs and its home"). Example("--target web-01 --name osapitest", "A user that the host has"). Result("Add a user, on one host:\n\n```ansi\n$ osapi client node user create --target web-01 --name osapitest\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 create --target _all --name osapitest\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\nAdd a user with a shell, groups and a password, on one host:\n\n```ansi\n$ osapi client node user create --target web-01 --name osapitest --shell /bin/sh --groups root --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 create --target _all --name osapitest --shell /bin/sh --groups root --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\nAdd a system user with its IDs and its home, on one host:\n\n```ansi\n$ osapi client node user create --target web-01 --name osapitest --uid 1999 --gid 100 --home /home/osapitest --system\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 create --target _all --name osapitest --uid 1999 --gid 100 --home /home/osapitest --system\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\nA user that the host has, on one host:\n\n```ansi\n$ osapi client node user create --target web-01 --name osapitest\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 1 host: \x1b[38;2;103;234;147m1 ok\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 create --target _all --name osapitest\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\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\": false,\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| Add a user | runs `useradd --create-home -- osapitest` |\n| Add a user with a shell, groups and a password | runs `useradd --create-home -s /bin/sh -G root -- osapitest`; runs `chpasswd -e` |\n| Add a system user with its IDs and its home | runs `useradd --create-home -u 1999 -g 100 -d /home/osapitest -r -- osapitest` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A name that is an option | `--name -r` | account_name |\n| A name longer than 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |\n| A negative user ID | `--name osapitest --uid -1` | min |\n| A negative group ID | `--name osapitest --gid -1` | min |\n| A home that is not absolute | `--name osapitest --home home` | startswith |\n| A home with a line break | `--name osapitest --home \"/home/a\\nb\"` | no_linebreak |\n| A shell that is not absolute | `--name osapitest --shell bash` | startswith |\n| A shell with a line break | `--name osapitest --shell \"/bin/a\\nb\"` | no_linebreak |\n| A group that is an option | `--name osapitest --groups -r` | account_name |\n| A group longer than 32 characters | `--name osapitest --groups aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |\n| A password with a line break | `--name osapitest --password -` | no_linebreak |\n| A hash that is not a crypt hash | `--name osapitest` | crypt hash |"). 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.")), endpoint.Put[UpdateRequest, UserUpdateResponse]("update"). Handle(HandleUpdate). ID("PutNodeUser"). Describe("Change a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Changes what the input gives and the user does not have already, with usermod: its shell, its home, which usermod moves the files to, its groups, which replace the groups it has, and whether it is locked. The same values report changed: false. 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 --shell /bin/bash", "Set the shell"). Example("--target web-01 --name osapitest --shell /bin/bash", "The shell it has"). Example("--target web-01 --name osapitest --home /home/osapitest2 --groups root --lock locked", "Move the home, set the groups and lock it"). Example("--target web-01 --name osapitest --lock unlocked", "Unlock it"). Result("Set the shell, on one host:\n\n```ansi\n$ osapi client node user update --target web-01 --name osapitest --shell /bin/bash\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 update --target _all --name osapitest --shell /bin/bash\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\nThe shell it has, on one host:\n\n```ansi\n$ osapi client node user update --target web-01 --name osapitest --shell /bin/bash\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 1 host: \x1b[38;2;103;234;147m1 ok\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 update --target _all --name osapitest --shell /bin/bash\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\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\": false,\n \"hostname\": \"web-01\",\n \"name\": \"osapitest\",\n \"status\": \"ok\"\n }\n ]\n}\n```\n\nMove the home, set the groups and lock it, on one host:\n\n```ansi\n$ osapi client node user update --target web-01 --name osapitest --home /home/osapitest2 --groups root --lock locked\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 update --target _all --name osapitest --home /home/osapitest2 --groups root --lock locked\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\nUnlock it, on one host:\n\n```ansi\n$ osapi client node user update --target web-01 --name osapitest --lock unlocked\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 update --target _all --name osapitest --lock unlocked\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 the shell | runs `usermod -s /bin/bash -- osapitest` |\n| Move the home, set the groups and lock it | runs `usermod -d /home/osapitest2 -m -G root -L -- osapitest` |\n| Unlock it | runs `usermod -U -- osapitest` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A user that the host does not have | `--name nobody` | not found |\n| A name that is an option | `--name -r` | account_name |\n| A name longer than 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |\n| A shell that is not absolute | `--name alice --shell bash` | startswith |\n| A shell with a line break | `--name alice --shell \"/bin/a\\nb\"` | no_linebreak |\n| A home that is not absolute | `--name alice --home home` | startswith |\n| A home with a line break | `--name alice --home \"/home/a\\nb\"` | no_linebreak |\n| A group that is an option | `--name alice --groups -r` | account_name |\n| A group longer than 32 characters | `--name alice --groups aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |\n| A lock that is not locked or unlocked | `--name alice --lock maybe` | enum |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host has no user with that name."), 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.")), endpoint.Delete[DeleteRequest, UserDeleteResponse]("delete"). Handle(HandleDelete). ID("DeleteNodeUser"). Describe("Remove a user"). Permission("user:write"). Returns("Each target host's result, with whether it changed."). Explain("Removes the user and its home directory with userdel -r. A user that the host does not have does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped."). Example("--target web-01 --name osapitest", "Remove a user"). Example("--target web-01 --name osapitest", "A user that the host does not have"). Result("Remove a user, on one host:\n\n```ansi\n$ osapi client node user delete --target web-01 --name osapitest\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 delete --target _all --name osapitest\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\nA user that the host does not have, on one host:\n\n```ansi\n$ osapi client node user delete --target web-01 --name osapitest\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 1 host: \x1b[38;2;103;234;147m1 ok\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 delete --target _all --name osapitest\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;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n \x1b[1mweb-02\x1b[0m \x1b[38;2;103;234;147mok\x1b[0m \x1b[1mosapitest\x1b[0m\n\n 3 hosts: \x1b[38;2;103;234;147m2 ok\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\": false,\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| Remove a user | runs `userdel -r -- osapitest` |\n\nThe command fails in these cases:\n\n| Call | Flags | Fails with |\n| --- | --- | --- |\n| A name that is an option | `--name -r` | account_name |\n| A name longer than 32 characters | `--name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` | max |"). Errors(endpoint.NotFound(behavior.ErrNotFound, "The host has no user with that name."), 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 user as an endpoint group, which its spec comes from.
Functions ¶
Types ¶
type CreateRequest ¶
type CreateRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Body UserCreateRequest `in:"body" validate:"required"`
}
CreateRequest is the request of user create: its target and its input.
type DeleteRequest ¶
type DeleteRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `` /* 143-byte string literal not displayed */
}
DeleteRequest is the request of user delete: its target and its input.
type GetRequest ¶
type GetRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
Name string `doc:"The user, such as alice" in:"path" json:"name" param:"UserName" validate:"required,max=32,account_name"`
}
GetRequest is the request of user get: its target and its input.
type ListRequest ¶
type ListRequest struct {
Hostname string `` /* 182-byte string literal not displayed */
}
ListRequest is the request of user list: its target and its input.
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:"UserName" validate:"required,max=32,account_name"`
Body UserUpdateRequest `in:"body" validate:"required"`
}
UpdateRequest is the request of user update: its target and its input.
type UserAccount ¶
type UserAccount 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"`
UID *int `doc:"Its numeric user ID" json:"uid,omitempty"`
GID *int `doc:"Its primary group ID" json:"gid,omitempty"`
Home *string `doc:"Its home directory" json:"home,omitempty"`
Shell *string `doc:"Its login shell" json:"shell,omitempty"`
Groups *[]string `doc:"The groups it is a member of, besides its primary group" json:"groups,omitempty"`
Locked *bool `doc:"Whether a login with its password is refused" json:"locked,omitempty"`
Error *string `doc:"Error message if the agent failed." json:"error,omitempty"`
}
UserAccount is the result of user on one host.
type UserCollectionResponse ¶
type UserCollectionResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserAccount `json:"results"`
}
UserCollectionResponse is each target host's result.
func HandleList ¶
func HandleList( ctx context.Context, d dispatch.Deps, in ListRequest, ) (UserCollectionResponse, error)
HandleList runs user list on the target, for the endpoint server.
type UserCreateRequest ¶
type UserCreateRequest struct {
Name string `doc:"The user to add, such as alice" json:"name" validate:"required,max=32,account_name"`
UID int `doc:"Its numeric user ID; the system assigns one when it is 0" json:"uid,omitempty" validate:"omitempty,min=0"`
GID int `doc:"Its primary group ID; a group of its own when it is 0" json:"gid,omitempty" validate:"omitempty,min=0"`
Home string `doc:"Its home directory; /home/<name> when empty" json:"home,omitempty" validate:"omitempty,startswith=/,no_linebreak"`
Shell string `` /* 143-byte string literal not displayed */
Groups []string `` /* 131-byte string literal not displayed */
System bool `doc:"Add it as a system user, with an ID from the system range" json:"system,omitempty" validate:"omitempty"`
Password secret.Value `` /* 133-byte string literal not displayed */
}
UserCreateRequest is the body of user create.
type UserCreateResponse ¶
type UserCreateResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserResult `json:"results"`
}
UserCreateResponse is each target host's result.
func HandleCreate ¶
func HandleCreate( ctx context.Context, d dispatch.Deps, in CreateRequest, ) (UserCreateResponse, error)
HandleCreate runs user create on the target, for the endpoint server.
type UserDeleteResponse ¶
type UserDeleteResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserResult `json:"results"`
}
UserDeleteResponse is each target host's result.
func HandleDelete ¶
func HandleDelete( ctx context.Context, d dispatch.Deps, in DeleteRequest, ) (UserDeleteResponse, error)
HandleDelete runs user delete on the target, for the endpoint server.
type UserGetResponse ¶
type UserGetResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserAccount `json:"results"`
}
UserGetResponse is each target host's result.
func HandleGet ¶
func HandleGet( ctx context.Context, d dispatch.Deps, in GetRequest, ) (UserGetResponse, error)
HandleGet runs user get on the target, for the endpoint server.
type UserResult ¶
type UserResult 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"`
}
UserResult is the result of user on one host.
type UserUpdateRequest ¶
type UserUpdateRequest struct {
Shell string `doc:"Its login shell, such as /bin/bash" json:"shell,omitempty" validate:"omitempty,startswith=/,no_linebreak"`
Home string `` /* 127-byte string literal not displayed */
Groups []string `` /* 137-byte string literal not displayed */
Lock types.Lock `` /* 139-byte string literal not displayed */
}
UserUpdateRequest is the body of user update.
type UserUpdateResponse ¶
type UserUpdateResponse struct {
JobID string `` /* 133-byte string literal not displayed */
Results []UserResult `json:"results"`
}
UserUpdateResponse is each target host's result.
func HandleUpdate ¶
func HandleUpdate( ctx context.Context, d dispatch.Deps, in UpdateRequest, ) (UserUpdateResponse, error)
HandleUpdate runs user update on the target, for the endpoint server.