box

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTransferNoAnswer = errors.New("box received the transfer request but did not answer in time")

ErrTransferNoAnswer reports that Box received the whole transfer request but no answer from Box arrived before the client stopped waiting: the wait timed out, or Box's gateway gave up with a 504. Box documents that a transfer keeps running after a gateway timeout; that it also keeps running when we stop waiting and close the connection is assumed, not documented. Either way the caller reports the transfer as still in progress.

Functions

func NewTransferHTTPClient added in v0.1.1

func NewTransferHTTPClient() *http.Client

NewTransferHTTPClient returns an HTTP client for the transfer request. The client from uhttp.NewClient stops waiting for response headers after 60 seconds, while Box holds the transfer request open until it finishes (up to 10 minutes). This client has no header timeout, so the caller's context alone bounds the wait. It keeps the proxy and HTTP/2 keepalive settings of the uhttp transport, and opens a new connection per request so a connection left idle across a Lambda freeze is never reused. It sends the same baton-sdk User-Agent as uhttp, but unlike the uhttp transport it does not retry a request that was never sent (a dial or proxy-connect failure) and does not log requests.

func RequestAccessToken

func RequestAccessToken(ctx context.Context, clientID string, clientSecret string, enterpriseId string, baseURL string) (string, error)

RequestAccessToken creates bearer token needed to use the Box API.

Types

type APIError added in v0.0.4

type APIError struct {
	Message string
	Code    string
	Status  int
}

APIError carries a structured Box API error so callers can check error codes with errors.As.

func (*APIError) Error added in v0.0.4

func (e *APIError) Error() string

Error returns only Box's error code: the status error it is joined with already carries the HTTP status and Box's message.

type BaseType

type BaseType struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, token string, baseURL string, opts ...ClientOption) (*Client, error)

func (*Client) ActivateUser added in v0.0.4

func (c *Client) ActivateUser(ctx context.Context, userID string) error

ActivateUser sets a Box user's status back to active.

func (*Client) CheckAdminAccess added in v0.0.5

func (c *Client) CheckAdminAccess(ctx context.Context) error

CheckAdminAccess verifies the token has manage-users admin scope by requesting a single user entry. Box CCG Service Accounts are not assigned a role designation, so validating via the role field is incorrect; a 403 here means insufficient scope.

func (*Client) CreateUser added in v0.0.4

func (c *Client) CreateUser(ctx context.Context, input CreateUserInput) (*User, error)

CreateUser creates a new managed Box user via POST /2.0/users.

func (*Client) DeactivateUser added in v0.0.4

func (c *Client) DeactivateUser(ctx context.Context, userID string) error

DeactivateUser sets a Box user's status to inactive (reversible).

func (*Client) DeleteUser added in v0.0.4

func (c *Client) DeleteUser(ctx context.Context, userID string, force bool) error

DeleteUser permanently deletes a Box user via DELETE /2.0/users/{id}. With force=true Box removes the user even when they still own content, and deletes that content; with force=false Box refuses to delete a user who still owns content. notify=false suppresses the email notification sent to the user.

func (*Client) GetCurrentUserWithEnterprise

func (c *Client) GetCurrentUserWithEnterprise(ctx context.Context) (User, error)

GetCurrentUserWithEnterprise returns current user with enterprise data.

func (*Client) GetGroup

func (c *Client) GetGroup(ctx context.Context, groupId string) (Group, error)

GetGroup returns Box group details.

func (*Client) GetGroupMemberships

func (c *Client) GetGroupMemberships(ctx context.Context, groupId string, marker string) ([]GroupMembership, string, annotations.Annotations, error)

GetGroupMemberships returns one page of memberships for the given group.

func (*Client) GetGroups

func (c *Client) GetGroups(ctx context.Context, marker string) ([]Group, string, annotations.Annotations, error)

GetGroups returns one page of groups from the Box enterprise.

func (*Client) GetUser added in v0.0.5

func (c *Client) GetUser(ctx context.Context, userID string) (*User, error)

GetUser fetches a single Box user by ID. It skips uhttp's GET cache: actions use it to check a user's current status, which an earlier action in the same process may have just changed.

func (*Client) GetUserByLogin added in v0.0.4

func (c *Client) GetUserByLogin(ctx context.Context, login string) (*User, error)

GetUserByLogin fetches a single user by exact login (email) match via GET /2.0/users?filter_term=. Returns nil, nil when no user with that login exists.

func (*Client) GetUsers

func (c *Client) GetUsers(ctx context.Context, marker string) ([]User, string, annotations.Annotations, error)

GetUsers returns one page of users from the Box enterprise.

func (*Client) TransferOwnedItems added in v0.1.1

func (c *Client) TransferOwnedItems(ctx context.Context, sourceUserID, destUserID string, notify bool) (*Folder, error)

TransferOwnedItems moves every item owned by sourceUserID into a new folder in destUserID's account via PUT /2.0/users/{id}/folders/0, and returns that folder. Box names it "{login} - {name}'s Files and Folders" after the source user, with a suffix such as " (1)" when that name is taken. Box holds the request open while it moves content; only a transfer that runs past 10 minutes keeps going after Box answers, and Box offers no endpoint to check completion.

When Box has received the whole request but the wait ends first (the context deadline, a response-header timeout, or a 504 from Box's gateway), the error wraps ErrTransferNoAnswer. A connection that closes or resets after the request was sent is deliberately a plain error: it may come from a proxy that never forwarded the request, and reporting a transfer that never started as in progress invites a deprovision that deletes the content.

func (*Client) UpdateUser added in v0.0.4

func (c *Client) UpdateUser(ctx context.Context, userID string, updates map[string]interface{}) (*User, error)

UpdateUser updates a Box user's properties via PUT /2.0/users/{user_id}.

type ClientOption added in v0.1.1

type ClientOption func(*Client)

ClientOption configures a Client.

func WithTransferHTTPClient added in v0.1.1

func WithTransferHTTPClient(httpClient *http.Client) ClientOption

WithTransferHTTPClient sets the HTTP client used for the transfer request. Without it, the transfer request uses the client passed to NewClient.

type CreateUserInput added in v0.0.4

type CreateUserInput struct {
	Login  string `json:"login"`
	Name   string `json:"name"`
	Role   string `json:"role,omitempty"`
	Status string `json:"status,omitempty"`
}

CreateUserInput holds the fields sent to POST /2.0/users.

type Enterprise

type Enterprise struct {
	BaseType
	Name string `json:"name"`
}

type Folder added in v0.1.1

type Folder struct {
	BaseType
	Name string `json:"name"`
}

Folder is the subset of a Box folder returned by the transfer owned folders endpoint.

type Group

type Group struct {
	BaseType
	InvitabilityLevel      string `json:"invitability_level"`
	MemberViewabilityLevel string `json:"member_viewability_level"`
	Name                   string `json:"name"`
}

type GroupMembership

type GroupMembership struct {
	BaseType
	Role  string `json:"role"`
	User  User   `json:"user"`
	Group Group  `json:"group"`
}

type User

type User struct {
	BaseType
	Enterprise Enterprise `json:"enterprise"`
	Login      string     `json:"login"`
	Name       string     `json:"name"`
	Phone      string     `json:"phone"`
	Role       string     `json:"role"`
	Status     string     `json:"status"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL