Documentation
¶
Index ¶
- Constants
- Variables
- func FetchAllPages[T any](req *CloudFoundryClient, method string, path any, modifiers ...RequestModifier) ([]T, error)
- func GetPaginated[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) ([]T, error)
- func GetResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
- func PatchResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
- func PostResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
- func SendRequestAndParseResult[T any](req *CloudFoundryClient, method string, path any, modifiers ...RequestModifier) (*T, error)
- type AbsolutePath
- type AuthTokenInfo
- type CloudFoundryClient
- func (req *CloudFoundryClient) CreateRole(role Role, spaceOrOrganizationGUID string, options CreateRoleOptions) (*models.Role, error)
- func (req *CloudFoundryClient) CreateSpace(name, orgGUID string, options CreateSpaceOptions) (*models.Space, error)
- func (req *CloudFoundryClient) CreateUser(guid string, options CreateUserOptions) (*models.User, error)
- func (req *CloudFoundryClient) DeleteAndExpectStatus(path string, expectedStatus int, modifiers ...RequestModifier) error
- func (req *CloudFoundryClient) DeleteRole(roleGUID string) error
- func (req *CloudFoundryClient) DeleteUser(userGUID string) error
- func (req *CloudFoundryClient) Get(path string, modifiers ...RequestModifier) (*resty.Response, error)
- func (req *CloudFoundryClient) GetRole(roleGUID string) (*models.Role, error)
- func (req *CloudFoundryClient) GetSpace(guid string) (*models.Space, error)
- func (req *CloudFoundryClient) GetTokenInfo() AuthTokenInfo
- func (req *CloudFoundryClient) GetUser(userGUID string) (*models.User, error)
- func (req *CloudFoundryClient) ListOrganizations(options ListOrganizationsOptions) ([]models.Organization, error)
- func (req *CloudFoundryClient) ListRole(options ListRoleOptions) ([]models.Role, error)
- func (req *CloudFoundryClient) ListSpaces(options ListSpacesOptions) ([]models.Space, error)
- func (req *CloudFoundryClient) ListUsers(options ListUsersOptions) ([]models.User, error)
- func (req *CloudFoundryClient) ListUsersForSpace(spaceGUID string, options ListUsersForSpaceOptions) ([]models.User, error)
- func (req *CloudFoundryClient) Post(path string, modifiers ...RequestModifier) (*resty.Response, error)
- func (req *CloudFoundryClient) RefreshToken() error
- func (req *CloudFoundryClient) SendRequest(method string, path any, modifiers ...RequestModifier) (*resty.Response, error)
- func (req *CloudFoundryClient) TokenIsExpired() bool
- func (req *CloudFoundryClient) UpdateSpace(guid string, options UpdateSpaceOptions) (*models.Space, error)
- func (req *CloudFoundryClient) UpdateUser(guid string, metadata util.KV) (*models.User, error)
- type CloudFoundryConfig
- type CloudFoundryError
- type CloudFoundryPaginatedResult
- type CreateRoleOptions
- type CreateSpaceOptions
- type CreateUserOptions
- type ListOrganizationsOptions
- type ListRoleOptions
- type ListSpacesOptions
- type ListUsersForSpaceOptions
- type ListUsersOptions
- type OrderBy
- type PaginationOptions
- type RelativePath
- type RequestModifier
- type Role
- type UpdateSpaceOptions
Constants ¶
const ( // TokenExpirySafetyMargin is the lastAuthTime to subtract from the authToken expiration lastAuthTime to ensure // that the authToken is refreshed before it expires TokenExpirySafetyMargin = 5 * time.Second // MaxPaginationPages is the maximum number of pages to fetch in a paginated request MaxPaginationPages = 100 // MaxItemsPerPage is the maximum number of items to return per page // according to https://v3-apidocs.cloudfoundry.org/version/3.158.0/index.html#list-organizations // the maximum per_page is 5000 MaxItemsPerPage = 5000 )
const ( OrganizationUserRole Role = "organization_user" OrganizationAuditorRole = "organization_auditor" OrganizationManagerRole = "organization_manager" OrganizationBillingManagerRole = "organization_billing_manager" OrganizationSpaceAuditorRole = "space_auditor" SpaceDeveloperRole = "space_developer" SpaceManagerRole = "space_manager" SpaceSupporterRole = "space_supporter" )
const ( OrderByCreatedAtAsc = "created_at" OrderByCreatedAtDesc = "-created_at" OrderByUpdatedAtAsc = "updated_at" OrderByUpdatedAtDesc = "-updated_at" )
Variables ¶
var ( CreateRoleTargetMissingErr = fmt.Errorf("either UserGUID or Username must be provided") InvalidRoleErr = fmt.Errorf("invalid role") )
Functions ¶
func FetchAllPages ¶
func FetchAllPages[T any]( req *CloudFoundryClient, method string, path any, modifiers ...RequestModifier, ) ([]T, error)
FetchAllPages is a wrapper around SendRequest which automatically fetches all pages of a paginated response :param req: The requester to use :param method: The HTTP method to use :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifier: One or more optional modifiers that will be called with the request object before it is executed :return: The resources from all pages
func GetPaginated ¶
func GetPaginated[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) ([]T, error)
GetPaginated is a wrapper around FetchAllPages which automatically sets the method to GET :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The resources from all pages
func GetResult ¶
func GetResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
GetResult is a wrapper around SendRequestAndParseResult which automatically sets the method to GET :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server, parsed as the given type
func PatchResult ¶
func PatchResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
PatchResult is a wrapper around SendRequestAndParseResult which automatically sets the method to Patch :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server, parsed as the given type
func PostResult ¶
func PostResult[T any](req *CloudFoundryClient, path string, modifiers ...RequestModifier) (*T, error)
PostResult is a wrapper around SendRequestAndParseResult which automatically sets the method to Post :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server, parsed as the given type
func SendRequestAndParseResult ¶
func SendRequestAndParseResult[T any]( req *CloudFoundryClient, method string, path any, modifiers ...RequestModifier, ) (*T, error)
SendRequestAndParseResult is a wrapper around SendRequest which automatically sets the result type :param req: The requester to use :param method: The HTTP method to use :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifier: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server, parsed as the given type
Types ¶
type AbsolutePath ¶
type AbsolutePath string
AbsolutePath is a type that represents an absolute path
type AuthTokenInfo ¶
type AuthTokenInfo struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` RefreshToken string `json:"refresh_token"` ExpiresIn int `json:"expires_in"` Scope string `json:"scope"` JTI string `json:"jti"` }
AuthTokenInfo is the response from the authToken endpoint and will be returned after a successful authentication
type CloudFoundryClient ¶
type CloudFoundryClient struct {
// contains filtered or unexported fields
}
CloudFoundryClient is a struct that manages the authToken and refreshes it if necessary
func (*CloudFoundryClient) CreateRole ¶
func (req *CloudFoundryClient) CreateRole( role Role, spaceOrOrganizationGUID string, options CreateRoleOptions, ) (*models.Role, error)
CreateRole creates a role for a user in an organization or space The role must be one of the following: - organization_user - organization_auditor - organization_manager - organization_billing_manager - space_auditor - space_developer - space_manager - space_supporter The targetRelationGUID must be the GUID of the organization or space The options must include either UserGUID or Username
func (*CloudFoundryClient) CreateSpace ¶
func (req *CloudFoundryClient) CreateSpace(name, orgGUID string, options CreateSpaceOptions) (*models.Space, error)
CreateSpace creates a space with the specified name and organization GUID You can also specify labels and annotations
func (*CloudFoundryClient) CreateUser ¶
func (req *CloudFoundryClient) CreateUser(guid string, options CreateUserOptions) (*models.User, error)
CreateUser creates a new user with the specified GUID and options including labels and annotations. It returns the created user or an error if the creation fails.
func (*CloudFoundryClient) DeleteAndExpectStatus ¶
func (req *CloudFoundryClient) DeleteAndExpectStatus(path string, expectedStatus int, modifiers ...RequestModifier) error
DeleteAndExpectStatus is a wrapper around SendRequestAndParseResult which automatically sets the method to Delete :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server, parsed as the given type
func (*CloudFoundryClient) DeleteRole ¶
func (req *CloudFoundryClient) DeleteRole(roleGUID string) error
DeleteRole deletes a role by GUID
func (*CloudFoundryClient) DeleteUser ¶
func (req *CloudFoundryClient) DeleteUser(userGUID string) error
DeleteUser deletes a user by their GUID, along with all roles associated with them. It returns an error if the deletion fails.
func (*CloudFoundryClient) Get ¶
func (req *CloudFoundryClient) Get(path string, modifiers ...RequestModifier) (*resty.Response, error)
Get is a wrapper around SendRequest which automatically sets the method to GET :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server
func (*CloudFoundryClient) GetRole ¶
func (req *CloudFoundryClient) GetRole(roleGUID string) (*models.Role, error)
GetRole fetches a role by GUID
func (*CloudFoundryClient) GetSpace ¶
func (req *CloudFoundryClient) GetSpace(guid string) (*models.Space, error)
GetSpace returns a space by GUID
func (*CloudFoundryClient) GetTokenInfo ¶
func (req *CloudFoundryClient) GetTokenInfo() AuthTokenInfo
GetTokenInfo returns a copy of the authToken info
func (*CloudFoundryClient) GetUser ¶
func (req *CloudFoundryClient) GetUser(userGUID string) (*models.User, error)
GetUser fetches a user by their GUID. It returns the user if found or an error otherwise.
func (*CloudFoundryClient) ListOrganizations ¶
func (req *CloudFoundryClient) ListOrganizations(options ListOrganizationsOptions) ([]models.Organization, error)
ListOrganizations fetches a list of organizations based on the provided fetch options, which include pagination and filters by names and GUIDFilters.
func (*CloudFoundryClient) ListRole ¶
func (req *CloudFoundryClient) ListRole(options ListRoleOptions) ([]models.Role, error)
ListRole fetches a list of roles based on the provided fetch options
func (*CloudFoundryClient) ListSpaces ¶
func (req *CloudFoundryClient) ListSpaces(options ListSpacesOptions) ([]models.Space, error)
ListSpaces returns a list of spaces the user has access to
func (*CloudFoundryClient) ListUsers ¶
func (req *CloudFoundryClient) ListUsers(options ListUsersOptions) ([]models.User, error)
ListUsers lists all users that the current user can see, optionally filtered by the provided ListUsersOptions. It supports filtering by multiple criteria such as GUIDFilters, usernames, partial usernames, origins, and labels, and allows sorting of the results.
func (*CloudFoundryClient) ListUsersForSpace ¶
func (req *CloudFoundryClient) ListUsersForSpace(spaceGUID string, options ListUsersForSpaceOptions) ([]models.User, error)
ListUsersForSpace lists all users with a role in the specified space. This method supports filtering by user GUIDFilters, usernames (or partial usernames), origins, as well as pagination and sorting options.
func (*CloudFoundryClient) Post ¶
func (req *CloudFoundryClient) Post(path string, modifiers ...RequestModifier) (*resty.Response, error)
Post is a wrapper around SendRequest which automatically sets the method to POST :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifiers: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server
func (*CloudFoundryClient) RefreshToken ¶
func (req *CloudFoundryClient) RefreshToken() error
RefreshToken tries to refresh the authToken
func (*CloudFoundryClient) SendRequest ¶
func (req *CloudFoundryClient) SendRequest( method string, path any, modifiers ...RequestModifier, ) (*resty.Response, error)
SendRequest is a wrapper around newAuthenticatedRequest which automatically sets the endpoint :param method: The HTTP method to use :param path: The path to the endpoint. This can be a string, AbsolutePath or RelativePath :param modifier: One or more optional modifiers that will be called with the request object before it is executed :return: The response from the server
func (*CloudFoundryClient) TokenIsExpired ¶
func (req *CloudFoundryClient) TokenIsExpired() bool
TokenIsExpired returns true if the authToken is expired
func (*CloudFoundryClient) UpdateSpace ¶
func (req *CloudFoundryClient) UpdateSpace(guid string, options UpdateSpaceOptions) (*models.Space, error)
UpdateSpace updates a space by GUID You can update the name, labels, and annotations
func (*CloudFoundryClient) UpdateUser ¶
UpdateUser updates a user's metadata including labels and annotations based on the provided GUID. It returns the updated user or an error if the update fails.
type CloudFoundryConfig ¶
type CloudFoundryConfig struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Organization string `json:"organization,omitempty"` APIEndpoint string `json:"api_endpoint,omitempty"` // Authorization and Authentication AuthEndpoint string `json:"auth_endpoint,omitempty"` OAuthClientID string `json:"oauth_client_id,omitempty"` OAuthClientSecret string `json:"oauth_client_secret,omitempty"` UAAEndpoint string `json:"uaa_endpoint,omitempty"` }
CloudFoundryConfig is the configuration for the Cloud Foundry httpClient
func LoadCloudFoundryConfig ¶
func LoadCloudFoundryConfig(fileName string) (res *CloudFoundryConfig, err error)
LoadCloudFoundryConfig loads the config from the `config.json` file
func (*CloudFoundryConfig) NewClient ¶
func (cfg *CloudFoundryConfig) NewClient() (*CloudFoundryClient, error)
NewClient returns a new request httpClient which manages the authToken and refreshes it if necessary
type CloudFoundryError ¶
type CloudFoundryError struct { Detail string `json:"detail"` Title string `json:"title"` Code int `json:"code"` }
CloudFoundryError is a struct that represents an error response from the server
func (CloudFoundryError) Error ¶
func (c CloudFoundryError) Error() string
Error returns a string representation of the error
type CloudFoundryPaginatedResult ¶
type CloudFoundryPaginatedResult[T any] struct { Pagination struct { TotalResults int `json:"total_results"` TotalPages int `json:"total_pages"` First *href `json:"first"` Last *href `json:"last"` Next *href `json:"next"` Previous *href `json:"previous"` } Resources []T }
CloudFoundryPaginatedResult is a struct that represents a paginated response from the server
type CreateRoleOptions ¶
type CreateSpaceOptions ¶
type CreateSpaceOptions struct { // Labels is a map of labels to assign to the space Labels map[string]string // Annotations is a map of annotations to assign to the space Annotations map[string]string }
CreateSpaceOptions are the options for creating a space
type CreateUserOptions ¶
type CreateUserOptions struct { // Labels is an optional map of labels to apply to the user. Labels are key-value pairs // that can be used to organize and categorize users. Labels map[string]string // Annotations is an optional map of annotations to apply to the user. Annotations are // key-value pairs that can store additional metadata that can be used by tools and libraries. Annotations map[string]string }
CreateUserOptions specifies options for creating a user, including labels and annotations that can be applied to the user. These are optional maps that store metadata.
type ListOrganizationsOptions ¶
type ListOrganizationsOptions struct { PaginationOptions // NameFilters is an optional list of organization names to filter by NameFilters []string // GUIDFilters is an optional list of organization GUIDFilters to filter by GUIDFilters []string }
ListOrganizationsOptions specifies criteria for fetching organizations, including pagination and optional filtering by names or GUIDFilters.
type ListRoleOptions ¶
type ListRoleOptions struct { PaginationOptions // RoleGUIDFilters is an optional list of role GUIDFilters to filter by RoleGUIDFilters []string // RoleTypeFilters is an optional list of role types to filter by RoleTypeFilters []string // SpaceGUIDFilters is an optional list of space GUIDFilters to filter by SpaceGUIDFilters []string // OrganizationGUIDFilters is an optional list of organization GUIDFilters to filter by OrganizationGUIDFilters []string // UserGUIDFilters is an optional list of user GUIDFilters to filter by UserGUIDFilters []string // OrderBy is an optional value to sort by OrderBy OrderBy }
ListRoleOptions specifies criteria for fetching roles, including pagination and optional filtering by type, user GUID, organization GUID, and space GUID
type ListSpacesOptions ¶
type ListSpacesOptions struct { PaginationOptions // Names is a list of space names to filter by Names []string // GUIDs is a list of space GUIDs to filter by GUIDs []string // OrganizationGUIDs is a list of organization GUIDs to filter by OrganizationGUIDs []string // Labels is a list of space labels to filter by LabelSelector string }
ListSpacesOptions are the options for listing spaces
type ListUsersForSpaceOptions ¶
type ListUsersForSpaceOptions struct { PaginationOptions // GUIDFilters is a comma-delimited list of user GUIDFilters to filter by. GUIDFilters []string // UsernameFilters is a comma-delimited list of usernames to filter by. Mutually exclusive with PartialUsernameFilters. UsernameFilters []string // PartialUsernameFilters is a comma-delimited list of strings to search by. Mutually exclusive with UsernameFilters. PartialUsernameFilters []string // OriginFilters is a comma-delimited list of user origins to filter by. OriginFilters []string // OrderBy specifies the value to sort by. Defaults to ascending; prepend with - to sort descending. OrderBy string // LabelSelector contains a list of label selector requirements. LabelSelector string }
ListUsersForSpaceOptions specifies the options for listing users for a space.
type ListUsersOptions ¶
type ListUsersOptions struct { // GUIDFilters is a list of user GUIDFilters to filter by. Providing multiple GUIDFilters // will return users that match any of the specified GUIDFilters. GUIDFilters []string // UsernameFilters is a list of exact usernames to filter by. Providing multiple // usernames will return users that match any of the specified usernames. // This filter is mutually exclusive with PartialUsernameFilters. UsernameFilters []string // PartialUsernameFilters is a list of partial username strings to search by. // Users that contain any of the provided strings in their username will be returned. // This filter is mutually exclusive with UsernameFilters. PartialUsernameFilters []string // OriginFilters is a list of user origin sources to filter by. OriginFilters could // be sources like 'uaa', 'ldap', etc., indicating where the user was authenticated from. // Users authenticated from any of the specified origins will be returned. OriginFilters []string // OrderBy determines the attribute by which the results are sorted. Valid // values might include attributes like 'created_at' or 'updated_at', with // the possibility to prepend with '-' for descending order. For example, // '-created_at' would sort the users by the creation date in descending order. OrderBy OrderBy // LabelSelector is a query string containing a list of label selector // requirements. The syntax of the selector is similar to Kubernetes label // selectors. This allows for filtering users based on a set of labels. LabelSelector string }
ListUsersOptions specifies options for listing users with various filters.
type PaginationOptions ¶
type PaginationOptions struct { // PerPage is the number of organizations to return per page PerPage int }
PaginationOptions is a struct that represents the options for the number of items to return per page
type RequestModifier ¶
type RequestModifier func(r *resty.Request)
RequestModifier is a type that represents a request modifier You can use this type to modify the request before it is executed
func WithBody ¶
func WithBody(body any) RequestModifier
WithBody is a request modifier that sets the body for a request
func WithQueryParams ¶
func WithQueryParams(params map[string]string) RequestModifier
WithQueryParams is a request modifier that sets the query parameters for a request
func WithRequestModifiers ¶
func WithRequestModifiers(modifiers ...RequestModifier) RequestModifier
WithRequestModifiers is a request modifier that applies all given modifiers to the request
func WithResult ¶
func WithResult[T any]() RequestModifier
WithResult is a request modifier that sets the result type for a request
type Role ¶
type Role string
Role is a Cloud Foundry role (e.g. organization_user, space_manager, ...)
type UpdateSpaceOptions ¶
type UpdateSpaceOptions struct { // Name is the new name of the space Name string // Labels is a map of labels to assign to the space Labels map[string]string // Annotations is a map of annotations to assign to the space Annotations map[string]string }
UpdateSpaceOptions are the options for updating a space