# Shares ## ShareResourceWithPrincipal `client.Groups.Shares.New(ctx, body) (*GroupShareNewResponse, error)` **post** `/gitpod.v1.GroupService/ShareResourceWithPrincipal` Shares a resource directly with a principal (user or service account). Use this method to: - Grant a user or service account direct access to a runner, project, or other resource - Share resources without creating and managing groups manually ### Examples - Share a runner with a user: Grants admin access to a runner for a specific user. ```yaml resourceType: RESOURCE_TYPE_RUNNER resourceId: "d2c94c27-3b76-4a42-b88c-95a85e392c68" principal: PRINCIPAL_USER principalId: "f53d2330-3795-4c5d-a1f3-453121af9c60" role: RESOURCE_ROLE_RUNNER_ADMIN ``` - Share a runner with a service account: Grants user access to a runner for a service account. ```yaml resourceType: RESOURCE_TYPE_RUNNER resourceId: "d2c94c27-3b76-4a42-b88c-95a85e392c68" principal: PRINCIPAL_SERVICE_ACCOUNT principalId: "a1b2c3d4-5678-90ab-cdef-1234567890ab" role: RESOURCE_ROLE_RUNNER_USER ``` ### Authorization Requires admin role on the specific resource. ### Parameters - `body GroupShareNewParams` - `Principal param.Field[Principal]` Type of principal to share with (user or service account) - `PrincipalID param.Field[string]` ID of the principal (user or service account) to share with - `ResourceID param.Field[string]` ID of the resource to share - `ResourceType param.Field[ResourceType]` Type of resource to share (runner, project, etc.) - `Role param.Field[ResourceRole]` Role to grant the principal on the resource ### Returns - `type GroupShareNewResponse interface{…}` Empty response on success ### Example ```go package main import ( "context" "fmt" "github.com/gitpod-io/gitpod-sdk-go" "github.com/gitpod-io/gitpod-sdk-go/option" "github.com/gitpod-io/gitpod-sdk-go/shared" ) func main() { client := gitpod.NewClient( option.WithBearerToken("My Bearer Token"), ) share, err := client.Groups.Shares.New(context.TODO(), gitpod.GroupShareNewParams{ Principal: gitpod.F(shared.PrincipalServiceAccount), PrincipalID: gitpod.F("a1b2c3d4-5678-90ab-cdef-1234567890ab"), ResourceID: gitpod.F("d2c94c27-3b76-4a42-b88c-95a85e392c68"), ResourceType: gitpod.F(shared.ResourceTypeRunner), Role: gitpod.F(shared.ResourceRoleRunnerUser), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", share) } ``` #### Response ```json {} ``` ## UnshareResourceWithPrincipal `client.Groups.Shares.Delete(ctx, body) (*GroupShareDeleteResponse, error)` **post** `/gitpod.v1.GroupService/UnshareResourceWithPrincipal` Removes direct access for a principal (user or service account) from a resource. Use this method to: - Revoke a principal's direct access to a resource - Remove sharing without affecting group-based access ### Examples - Remove user access from a runner: Revokes a user's direct access to a runner. ```yaml resourceType: RESOURCE_TYPE_RUNNER resourceId: "d2c94c27-3b76-4a42-b88c-95a85e392c68" principal: PRINCIPAL_USER principalId: "f53d2330-3795-4c5d-a1f3-453121af9c60" ``` ### Authorization Requires admin role on the specific resource. ### Parameters - `body GroupShareDeleteParams` - `Principal param.Field[Principal]` Type of principal to remove access from (user or service account) - `PrincipalID param.Field[string]` ID of the principal (user or service account) to remove access from - `ResourceID param.Field[string]` ID of the resource to unshare - `ResourceType param.Field[ResourceType]` Type of resource to unshare ### Returns - `type GroupShareDeleteResponse interface{…}` Empty response on success ### Example ```go package main import ( "context" "fmt" "github.com/gitpod-io/gitpod-sdk-go" "github.com/gitpod-io/gitpod-sdk-go/option" "github.com/gitpod-io/gitpod-sdk-go/shared" ) func main() { client := gitpod.NewClient( option.WithBearerToken("My Bearer Token"), ) share, err := client.Groups.Shares.Delete(context.TODO(), gitpod.GroupShareDeleteParams{ Principal: gitpod.F(shared.PrincipalUser), PrincipalID: gitpod.F("f53d2330-3795-4c5d-a1f3-453121af9c60"), ResourceID: gitpod.F("d2c94c27-3b76-4a42-b88c-95a85e392c68"), ResourceType: gitpod.F(shared.ResourceTypeRunner), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", share) } ``` #### Response ```json {} ```