Skip to main content

Group

c.Group calls the API's Group group. The groups of the host.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[GroupAccount]]group:readList the groups of the host.
Create(ctx, hostname, input)*Response[Collection[GroupResult]]group:writeAdd a group.
Get(ctx, hostname, name)*Response[Collection[GroupAccount]]group:readGet one group.
Update(ctx, hostname, input)*Response[Collection[GroupResult]]group:writeSet the members of a group.
Delete(ctx, hostname, name)*Response[Collection[GroupResult]]group:writeRemove a group.

List​

func (s *GroupService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[GroupAccount]], error)

List the groups of the host.

Lists each group with its ID and its members, by name, from /etc/group through gohai, on every platform. The members are the users that /etc/group names; a user whose primary group it is is not listed again.

It sends GET /api/node/{hostname}/group, and needs the permission group:read.

The examples of the method's definition:

A host with a group, go run group.go list:

resp, err := c.Group.List(ctx, target)

Create​

func (s *GroupService) Create(
ctx context.Context,
hostname string,
input GroupCreateInput,
) (*Response[Collection[GroupResult]], error)

Add a group.

Adds the group with groupadd, with the ID when one is given. A group that the host has already does not change and reports changed: false, whatever its ID. It runs on the Debian family only, and elsewhere reports skipped.

It sends POST /api/node/{hostname}/group, and needs the permission group:write.

The examples of the method's definition:

Add a group, go run group.go create:

resp, err := c.Group.Create(ctx, target, client.GroupCreateInput{Name: "osapitest"})

Add a system group with its ID, go run group.go create-2:

resp, err := c.Group.Create(ctx, target, client.GroupCreateInput{
GID: 1999,
Name: "osapitest",
System: true,
})

Get​

func (s *GroupService) Get(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[GroupAccount]], error)

Get one group.

Reads one group from the same list. A group that the host does not have is not found.

It sends GET /api/node/{hostname}/group/{name}, and needs the permission group:read.

The examples of the method's definition:

A group, go run group.go get:

resp, err := c.Group.Get(ctx, target, "developers")

Update​

func (s *GroupService) Update(
ctx context.Context,
hostname string,
input GroupUpdateInput,
) (*Response[Collection[GroupResult]], error)

Set the members of a group.

Sets the members with gpasswd -M, in place of the members that the group has. The same members, in any order, do not change it and report changed: false. A group that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.

It sends PUT /api/node/{hostname}/group/{name}, and needs the permission group:write.

The examples of the method's definition:

Set the members, go run group.go update:

resp, err := c.Group.Update(ctx, target, client.GroupUpdateInput{
Members: []string{"root"},
Name: "osapitest",
})

Delete​

func (s *GroupService) Delete(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[GroupResult]], error)

Remove a group.

Removes the group with groupdel. A group that the host does not have does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends DELETE /api/node/{hostname}/group/{name}, and needs the permission group:write.

The examples of the method's definition:

Remove a group, go run group.go delete:

resp, err := c.Group.Delete(ctx, target, "osapitest")

Types​

The fields of each type are the properties of its schema in the API's spec.

GroupAccount​

FieldTypeDescription
ErrorstringError message if the agent failed.
GIDintIts numeric group ID.
HostnamestringHostname of the agent that produced this result.
Members[]stringThe users it has as members, besides those whose primary group it is.
NamestringThe group.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

GroupCreateInput​

FieldTypeDescription
GIDintIts numeric group ID; the system assigns one when it is 0.
NamestringThe group to add, such as developers.
SystemboolAdd it as a system group, with an ID from the system range.

GroupResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe group.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

GroupUpdateInput​

FieldTypeDescription
NamestringThe name of the path. The group to remove, such as developers.
Members[]stringIts members, which replace the members it has; none when empty.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Example​

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