projects

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 7 Imported by: 17

Documentation

Overview

Package projects manages and retrieves Projects in the OpenStack Identity Service.

Example to List Projects

listOpts := projects.ListOpts{
	Enabled: gophercloud.Enabled,
}

allPages, err := projects.List(identityClient, listOpts).AllPages(context.TODO())
if err != nil {
	panic(err)
}

allProjects, err := projects.ExtractProjects(allPages)
if err != nil {
	panic(err)
}

for _, project := range allProjects {
	fmt.Printf("%+v\n", project)
}

Example to Create a Project

createOpts := projects.CreateOpts{
	Name:        "project_name",
	Description: "Project Description",
	Tags:        []string{"FirstTag", "SecondTag"},
}

project, err := projects.Create(context.TODO(), identityClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update a Project

projectID := "966b3c7d36a24facaf20b7e458bf2192"

updateOpts := projects.UpdateOpts{
	Enabled: gophercloud.Disabled,
}

project, err := projects.Update(context.TODO(), identityClient, projectID, updateOpts).Extract()
if err != nil {
	panic(err)
}

updateOpts = projects.UpdateOpts{
	Tags: &[]string{"FirstTag"},
}

project, err = projects.Update(context.TODO(), identityClient, projectID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Project

projectID := "966b3c7d36a24facaf20b7e458bf2192"
err := projects.Delete(context.TODO(), identityClient, projectID).ExtractErr()
if err != nil {
	panic(err)
}

Example to List all tags of a Project

projectID := "966b3c7d36a24facaf20b7e458bf2192"
err := projects.ListTags(context.TODO(), identityClient, projectID).Extract()
if err != nil {
	panic(err)
}

Example to modify all tags of a Project

projectID := "966b3c7d36a24facaf20b7e458bf2192"
tags := ["foo", "bar"]
projects, err := projects.ModifyTags(context.TODO(), identityClient, projectID, tags).Extract()
if err != nil {
	panic(err)
}

Example to Delete all tags of a Project

projectID := "966b3c7d36a24facaf20b7e458bf2192"
err := projects.DeleteTags(context.TODO(), identityClient, projectID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

List enumerates the Projects to which the current token has access.

func ListAvailable

func ListAvailable(client *gophercloud.ServiceClient) pagination.Pager

ListAvailable enumerates the Projects which are available to a specific user.

Types

type CreateOpts

type CreateOpts struct {
	// DomainID is the ID this project will belong under.
	DomainID string `json:"domain_id,omitempty"`

	// Enabled sets the project status to enabled or disabled.
	Enabled *bool `json:"enabled,omitempty"`

	// IsDomain indicates if this project is a domain.
	IsDomain *bool `json:"is_domain,omitempty"`

	// Name is the name of the project.
	Name string `json:"name" required:"true"`

	// ParentID specifies the parent project of this new project.
	ParentID string `json:"parent_id,omitempty"`

	// Description is the description of the project.
	Description string `json:"description,omitempty"`

	// Tags is a list of tags to associate with the project.
	Tags []string `json:"tags,omitempty"`

	// Extra is free-form extra key/value pairs to describe the project.
	Extra map[string]any `json:"-"`

	// Options are defined options in the API to enable certain features.
	Options map[Option]any `json:"options,omitempty"`
}

CreateOpts represents parameters used to create a project.

func (CreateOpts) ToProjectCreateMap

func (opts CreateOpts) ToProjectCreateMap() (map[string]any, error)

ToProjectCreateMap formats a CreateOpts into a create request.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToProjectCreateMap() (map[string]any, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

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

CreateResult is the result of a Create request. Call its Extract method to interpret it as a Project.

func Create

func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create creates a new Project.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Project, error)

Extract interprets any projectResults as a Project.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the result of a Delete request. Call its ExtractErr method to determine if the request succeeded or failed.

func Delete

func Delete(ctx context.Context, client *gophercloud.ServiceClient, projectID string) (r DeleteResult)

Delete deletes a project.

type DeleteTagsResult

type DeleteTagsResult struct {
	gophercloud.ErrResult
}

DeleteTagsResult is the result of a Delete Tags request. Call its ExtractErr method to determine if the request succeeded or failed.

func DeleteTags

func DeleteTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string) (r DeleteTagsResult)

DeleteTag deletes a tag from a project.

type GetResult

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

GetResult is the result of a Get request. Call its Extract method to interpret it as a Project.

func Get

func Get(ctx context.Context, client *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves details on a single project, by ID.

func (GetResult) Extract

func (r GetResult) Extract() (*Project, error)

Extract interprets any projectResults as a Project.

type InvalidListFilter

type InvalidListFilter struct {
	FilterName string
}

InvalidListFilter is returned by the ToUserListQuery method when validation of a filter does not pass

func (InvalidListFilter) Error

func (e InvalidListFilter) Error() string

type ListOpts

type ListOpts struct {
	// DomainID filters the response by a domain ID.
	DomainID string `q:"domain_id"`

	// Enabled filters the response by enabled projects.
	Enabled *bool `q:"enabled"`

	// IsDomain filters the response by projects that are domains.
	// Setting this to true is effectively listing domains.
	IsDomain *bool `q:"is_domain"`

	// Name filters the response by project name.
	Name string `q:"name"`

	// ParentID filters the response by projects of a given parent project.
	ParentID string `q:"parent_id"`

	// Tags filters on specific project tags. All tags must be present for the project.
	Tags string `q:"tags"`

	// TagsAny filters on specific project tags. At least one of the tags must be present for the project.
	TagsAny string `q:"tags-any"`

	// NotTags filters on specific project tags. All tags must be absent for the project.
	NotTags string `q:"not-tags"`

	// NotTagsAny filters on specific project tags. At least one of the tags must be absent for the project.
	NotTagsAny string `q:"not-tags-any"`

	// Filters filters the response by custom filters such as
	// 'name__contains=foo'
	Filters map[string]string `q:"-"`
}

ListOpts enables filtering of a list request.

func (ListOpts) ToProjectListQuery

func (opts ListOpts) ToProjectListQuery() (string, error)

ToProjectListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToProjectListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request

type ListTagsResult

type ListTagsResult struct {
	gophercloud.Result
}

ListTagsResult is the result of a List Tags request. Call its Extract method to interpret it as a list of tags.

func ListTags

func ListTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string) (r ListTagsResult)

CheckTags lists tags for a project.

func (ListTagsResult) Extract

func (r ListTagsResult) Extract() (*Tags, error)

Extract interprets any ListTagsResult as a Tags Object.

type ModifyTagsOpts

type ModifyTagsOpts struct {
	// Tags is the list of tags associated with the project.
	Tags []string `json:"tags,omitempty"`
}

Tags represents a list of Tags object.

func (ModifyTagsOpts) ToModifyTagsCreateMap

func (opts ModifyTagsOpts) ToModifyTagsCreateMap() (map[string]any, error)

ToModifyTagsCreateMap formats a ModifyTagsOpts into a Modify tags request.

type ModifyTagsOptsBuilder

type ModifyTagsOptsBuilder interface {
	ToModifyTagsCreateMap() (map[string]any, error)
}

ModifyTagsOptsBuilder allows extensions to add additional parameters to the Modify request.

type ModifyTagsResult

type ModifyTagsResult struct {
	gophercloud.Result
}

ModifyTagsResLinksult is the result of a Tags request. Call its Extract method to interpret it as a project of tags.

func ModifyTags

func ModifyTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string, opts ModifyTagsOptsBuilder) (r ModifyTagsResult)

ModifyTags deletes all tags of a project and adds new ones.

func (ModifyTagsResult) Extract

func (r ModifyTagsResult) Extract() (*ProjectTags, error)

Extract interprets any ModifyTags as a Tags Object.

type Option

type Option string

Option is a specific option defined at the API to enable features on a project.

const (
	Immutable Option = "immutable"
)

type Project

type Project struct {
	// IsDomain indicates whether the project is a domain.
	IsDomain bool `json:"is_domain"`

	// Description is the description of the project.
	Description string `json:"description"`

	// DomainID is the domain ID the project belongs to.
	DomainID string `json:"domain_id"`

	// Enabled is whether or not the project is enabled.
	Enabled bool `json:"enabled"`

	// ID is the unique ID of the project.
	ID string `json:"id"`

	// Name is the name of the project.
	Name string `json:"name"`

	// ParentID is the parent_id of the project.
	ParentID string `json:"parent_id"`

	// Tags is the list of tags associated with the project.
	Tags []string `json:"tags,omitempty"`

	// Extra is free-form extra key/value pairs to describe the project.
	Extra map[string]any `json:"-"`

	// Options are defined options in the API to enable certain features.
	Options map[Option]any `json:"options,omitempty"`
}

Project represents an OpenStack Identity Project.

func ExtractProjects

func ExtractProjects(r pagination.Page) ([]Project, error)

ExtractProjects returns a slice of Projects contained in a single page of results.

func (*Project) UnmarshalJSON

func (r *Project) UnmarshalJSON(b []byte) error

type ProjectPage

type ProjectPage struct {
	pagination.LinkedPageBase
}

ProjectPage is a single page of Project results.

func (ProjectPage) IsEmpty

func (r ProjectPage) IsEmpty() (bool, error)

IsEmpty determines whether or not a page of Projects contains any results.

func (ProjectPage) NextPageURL

func (r ProjectPage) NextPageURL() (string, error)

NextPageURL extracts the "next" link from the links section of the result.

type ProjectTags

type ProjectTags struct {
	// Tags is the list of tags associated with the project.
	Projects []Project `json:"projects,omitempty"`
	// Links contains referencing links to the implied_role.
	Links map[string]any `json:"links"`
}

ProjectTags represents a list of Tags object.

type Tags

type Tags struct {
	// Tags is the list of tags associated with the project.
	Tags []string `json:"tags,omitempty"`
}

Tags represents a list of Tags object.

type UpdateOpts

type UpdateOpts struct {
	// DomainID is the ID this project will belong under.
	DomainID string `json:"domain_id,omitempty"`

	// Enabled sets the project status to enabled or disabled.
	Enabled *bool `json:"enabled,omitempty"`

	// IsDomain indicates if this project is a domain.
	IsDomain *bool `json:"is_domain,omitempty"`

	// Name is the name of the project.
	Name string `json:"name,omitempty"`

	// ParentID specifies the parent project of this new project.
	ParentID string `json:"parent_id,omitempty"`

	// Description is the description of the project.
	Description *string `json:"description,omitempty"`

	// Tags is a list of tags to associate with the project.
	Tags *[]string `json:"tags,omitempty"`

	// Extra is free-form extra key/value pairs to describe the project.
	Extra map[string]any `json:"-"`

	// Options are defined options in the API to enable certain features.
	Options map[Option]any `json:"options,omitempty"`
}

UpdateOpts represents parameters to update a project.

func (UpdateOpts) ToProjectUpdateMap

func (opts UpdateOpts) ToProjectUpdateMap() (map[string]any, error)

ToUpdateCreateMap formats a UpdateOpts into an update request.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToProjectUpdateMap() (map[string]any, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult

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

UpdateResult is the result of an Update request. Call its Extract method to interpret it as a Project.

func Update

func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)

Update modifies the attributes of a project.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*Project, error)

Extract interprets any projectResults as a Project.

Jump to

Keyboard shortcuts

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