organization

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package organization is responsible for OTF organizations

templ: version: v0.3.865

Index

Constants

View Source
const (
	DefaultSessionTimeout    = 20160
	DefaultSessionExpiration = 20160
)

Variables

View Source
var DefaultOrganizationPermissions = TFEOrganizationPermissions{
	CanCreateWorkspace: true,
	CanUpdate:          true,
	CanDestroy:         true,
}

Functions

func NewCommand added in v0.1.9

func NewCommand(client *otfapi.Client) *cobra.Command

Types

type CLI added in v0.1.9

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

type Client

type Client struct {
	*otfapi.Client

	Service
}

func (*Client) CreateOrganization added in v0.1.0

func (c *Client) CreateOrganization(ctx context.Context, options CreateOptions) (*Organization, error)

CreateOrganization creates a new organization with the given options.

func (*Client) DeleteOrganization

func (c *Client) DeleteOrganization(ctx context.Context, organization Name) error

DeleteOrganization deletes an organization via http.

type CreateOptions added in v0.1.8

type CreateOptions struct {
	Name *string

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	Email                      *string
	CollaboratorAuthPolicy     *string
	CostEstimationEnabled      *bool
	SessionRemember            *int
	SessionTimeout             *int
	AllowForceDeleteWorkspaces *bool
}

CreateOptions represents the options for creating an organization. See types.CreateOptions for more details.

type CreateOrganizationTokenOptions added in v0.2.0

type CreateOrganizationTokenOptions struct {
	Organization Name `schema:"organization_name,required"`
	Expiry       *time.Time
}

CreateOrganizationTokenOptions are options for creating an organization token via the service endpoint

type Entitlements

type Entitlements struct {
	ID                    resource.TfeID
	Agents                bool
	AuditLogging          bool
	CostEstimation        bool
	Operations            bool
	PrivateModuleRegistry bool
	SSO                   bool
	Sentinel              bool
	StateStorage          bool
	Teams                 bool
	VCSIntegrations       bool
}

OTF is free and therefore the user is entitled to all currently supported services.

type ListOptions added in v0.0.51

type ListOptions struct {
	resource.PageOptions
}

ListOptions represents the options for listing organizations.

type Name added in v0.3.17

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

func NewName added in v0.3.17

func NewName(name string) (Name, error)

func NewTestName added in v0.3.17

func NewTestName(t *testing.T) Name

func (Name) Kind added in v0.3.17

func (Name) Kind() resource.Kind

func (Name) MarshalText added in v0.3.17

func (name Name) MarshalText() ([]byte, error)

func (*Name) Scan added in v0.3.17

func (name *Name) Scan(text any) error

func (*Name) Set added in v0.3.17

func (name *Name) Set(v string) error

Set satisfies the pflag.Value interface

func (Name) String added in v0.3.17

func (name Name) String() string

func (*Name) Type added in v0.3.17

func (name *Name) Type() string

Type satisfies the pflag.Value interface

func (*Name) UnmarshalText added in v0.3.17

func (name *Name) UnmarshalText(text []byte) error

func (*Name) Value added in v0.3.17

func (name *Name) Value() (driver.Value, error)

Value satisfies the pflag.Value interface

type Options

type Options struct {
	RestrictOrganizationCreation bool
	TokensService                *tokens.Service
	Authorizer                   *authz.Authorizer

	*sql.DB
	*tfeapi.Responder
	*sql.Listener
	logr.Logger
}

type Organization

type Organization struct {
	ID        resource.TfeID `jsonapi:"primary,organizations" db:"organization_id"`
	CreatedAt time.Time      `jsonapi:"attribute" json:"created-at" db:"created_at"`
	UpdatedAt time.Time      `jsonapi:"attribute" json:"updated-at" db:"updated_at"`
	Name      Name           `jsonapi:"attribute" json:"name" db:"name"`

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	Email                      *string `db:"email"`
	CollaboratorAuthPolicy     *string `db:"collaborator_auth_policy"`
	SessionRemember            *int    `db:"session_remember"`
	SessionTimeout             *int    `db:"session_timeout"`
	AllowForceDeleteWorkspaces bool    `db:"allow_force_delete_workspaces"`
	CostEstimationEnabled      bool    `db:"cost_estimation_enabled"`
}

Organization is an OTF organization, comprising workspaces, users, etc.

func NewOrganization added in v0.1.0

func NewOrganization(opts CreateOptions) (*Organization, error)

func (*Organization) Update

func (org *Organization) Update(opts UpdateOptions) error

type OrganizationToken added in v0.2.0

type OrganizationToken struct {
	ID        resource.TfeID `db:"organization_token_id"`
	CreatedAt time.Time      `db:"created_at"`
	// Token belongs to an organization
	Organization Name `db:"organization_name"`
	// Optional expiry.
	Expiry *time.Time
}

OrganizationToken provides information about an API token for an organization

func (*OrganizationToken) CanAccess added in v0.3.6

func (u *OrganizationToken) CanAccess(action authz.Action, req authz.Request) bool

func (*OrganizationToken) String added in v0.2.0

func (u *OrganizationToken) String() string

type Service

type Service struct {
	RestrictOrganizationCreation bool

	*authz.Authorizer
	logr.Logger
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) *Service

func (*Service) AddHandlers added in v0.2.2

func (s *Service) AddHandlers(r *mux.Router)

func (*Service) AfterCreateOrganization added in v0.1.8

func (s *Service) AfterCreateOrganization(hook func(context.Context, *Organization) error)

func (*Service) BeforeDeleteOrganization added in v0.1.8

func (s *Service) BeforeDeleteOrganization(hook func(context.Context, *Organization) error)

func (*Service) Create added in v0.2.2

func (s *Service) Create(ctx context.Context, opts CreateOptions) (*Organization, error)

Create creates an organization. Only users can create organizations, or, if RestrictOrganizationCreation is true, then only the site admin can create organizations. Creating an organization automatically creates an owners team and adds creator as an owner.

func (*Service) CreateToken added in v0.2.2

CreateToken creates an organization token. If an organization token already exists it is replaced.

func (*Service) Delete added in v0.2.2

func (s *Service) Delete(ctx context.Context, name Name) error

func (*Service) DeleteToken added in v0.2.2

func (s *Service) DeleteToken(ctx context.Context, organization Name) error

func (*Service) Get added in v0.2.2

func (s *Service) Get(ctx context.Context, name Name) (*Organization, error)

func (*Service) GetEntitlements

func (s *Service) GetEntitlements(ctx context.Context, organization Name) (Entitlements, error)

func (*Service) GetOrganizationToken added in v0.2.0

func (s *Service) GetOrganizationToken(ctx context.Context, organization Name) (*OrganizationToken, error)

func (*Service) List added in v0.2.2

func (s *Service) List(ctx context.Context, opts ListOptions) (*resource.Page[*Organization], error)

List organizations. If the subject lacks the ListOrganizationsAction permission then its organization memberships are listed instead.

func (*Service) ListTokens added in v0.2.2

func (s *Service) ListTokens(ctx context.Context, organization Name) ([]*OrganizationToken, error)

func (*Service) Update added in v0.2.2

func (s *Service) Update(ctx context.Context, name Name, opts UpdateOptions) (*Organization, error)

func (*Service) WatchOrganizations added in v0.2.0

func (s *Service) WatchOrganizations(ctx context.Context) (<-chan pubsub.Event[*Organization], func())

type TFEAuthPolicyType added in v0.3.17

type TFEAuthPolicyType string

TFEAuthPolicyType represents an authentication policy type.

const (
	AuthPolicyPassword  TFEAuthPolicyType = "password"
	AuthPolicyTwoFactor TFEAuthPolicyType = "two_factor_mandatory"
)

List of available authentication policies.

type TFEEntitlements added in v0.3.17

type TFEEntitlements struct {
	ID                    resource.TfeID `jsonapi:"primary,entitlement-sets"`
	Agents                bool           `jsonapi:"attribute" json:"agents"`
	AuditLogging          bool           `jsonapi:"attribute" json:"audit-logging"`
	CostEstimation        bool           `jsonapi:"attribute" json:"cost-estimation"`
	Operations            bool           `jsonapi:"attribute" json:"operations"`
	PrivateModuleRegistry bool           `jsonapi:"attribute" json:"private-module-registry"`
	SSO                   bool           `jsonapi:"attribute" json:"sso"`
	Sentinel              bool           `jsonapi:"attribute" json:"sentinel"`
	StateStorage          bool           `jsonapi:"attribute" json:"state-storage"`
	Teams                 bool           `jsonapi:"attribute" json:"teams"`
	VCSIntegrations       bool           `jsonapi:"attribute" json:"vcs-integrations"`
}

Entitlements represents the entitlements of an organization. Unlike TFE/TFC, OTF is free and therefore the user is entitled to all currently supported services. Entitlements represents the entitlements of an organization.

type TFEOrganization added in v0.3.17

type TFEOrganization struct {
	Name                                              Name                        `jsonapi:"primary,organizations"`
	AssessmentsEnforced                               bool                        `jsonapi:"attribute" json:"assessments-enforced"`
	CollaboratorAuthPolicy                            TFEAuthPolicyType           `jsonapi:"attribute" json:"collaborator-auth-policy"`
	CostEstimationEnabled                             bool                        `jsonapi:"attribute" json:"cost-estimation-enabled"`
	CreatedAt                                         time.Time                   `jsonapi:"attribute" json:"created-at"`
	Email                                             string                      `jsonapi:"attribute" json:"email"`
	ExternalID                                        resource.TfeID              `jsonapi:"attribute" json:"external-id"`
	OwnersTeamSAMLRoleID                              resource.TfeID              `jsonapi:"attribute" json:"owners-team-saml-role-id"`
	Permissions                                       *TFEOrganizationPermissions `jsonapi:"attribute" json:"permissions"`
	SAMLEnabled                                       bool                        `jsonapi:"attribute" json:"saml-enabled"`
	SessionRemember                                   *int                        `jsonapi:"attribute" json:"session-remember"`
	SessionTimeout                                    *int                        `jsonapi:"attribute" json:"session-timeout"`
	TrialExpiresAt                                    time.Time                   `jsonapi:"attribute" json:"trial-expires-at"`
	TwoFactorConformant                               bool                        `jsonapi:"attribute" json:"two-factor-conformant"`
	SendPassingStatusesForUntriggeredSpeculativePlans bool                        `jsonapi:"attribute" json:"send-passing-statuses-for-untriggered-speculative-plans"`
	RemainingTestableCount                            int                         `jsonapi:"attribute" json:"remaining-testable-count"`

	// Note: This will be false for TFE versions older than v202211, where the setting was introduced.
	// On those TFE versions, safe delete does not exist, so ALL deletes will be force deletes.
	AllowForceDeleteWorkspaces bool `jsonapi:"attribute" json:"allow-force-delete-workspaces"`
}

TFEOrganization represents a Terraform Enterprise organization.

type TFEOrganizationCreateOptions added in v0.3.17

type TFEOrganizationCreateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,organizations"`

	// Required: Name of the organization.
	Name *string `jsonapi:"attribute" json:"name"`

	// Optional: AssessmentsEnforced toggles whether health assessment enablement is enforced across all assessable workspaces (those with a minimum terraform versio of 0.15.4 and not running in local execution mode) or if the decision to enabled health assessments is delegated to the workspace setting AssessmentsEnabled.
	AssessmentsEnforced *bool `jsonapi:"attribute" json:"assessments-enforced,omitempty"`

	// Required: Admin email address.
	Email *string `jsonapi:"attribute" json:"email"`

	// Optional: Session expiration (minutes).
	SessionRemember *int `jsonapi:"attribute" json:"session-remember,omitempty"`

	// Optional: Session timeout after inactivity (minutes).
	SessionTimeout *int `jsonapi:"attribute" json:"session-timeout,omitempty"`

	// Optional: Authentication policy.
	CollaboratorAuthPolicy *TFEAuthPolicyType `jsonapi:"attribute" json:"collaborator-auth-policy,omitempty"`

	// Optional: Enable Cost Estimation
	CostEstimationEnabled *bool `jsonapi:"attribute" json:"cost-estimation-enabled,omitempty"`

	// Optional: The name of the "owners" team
	OwnersTeamSAMLRoleID *string `jsonapi:"attribute" json:"owners-team-saml-role-id,omitempty"`

	// Optional: SendPassingStatusesForUntriggeredSpeculativePlans toggles behavior of untriggered speculative plans to send status updates to version control systems like GitHub.
	SendPassingStatusesForUntriggeredSpeculativePlans *bool `jsonapi:"attribute" json:"send-passing-statuses-for-untriggered-speculative-plans,omitempty"`

	// Optional: AllowForceDeleteWorkspaces toggles behavior of allowing workspace admins to delete workspaces with resources under management.
	AllowForceDeleteWorkspaces *bool `jsonapi:"attribute" json:"allow-force-delete-workspaces,omitempty"`
}

TFEOrganizationCreateOptions represents the options for creating an organization.

type TFEOrganizationPermissions added in v0.3.17

type TFEOrganizationPermissions struct {
	CanCreateTeam               bool `json:"can-create-team"`
	CanCreateWorkspace          bool `json:"can-create-workspace"`
	CanCreateWorkspaceMigration bool `json:"can-create-workspace-migration"`
	CanDestroy                  bool `json:"can-destroy"`
	CanTraverse                 bool `json:"can-traverse"`
	CanUpdate                   bool `json:"can-update"`
	CanUpdateAPIToken           bool `json:"can-update-api-token"`
	CanUpdateOAuth              bool `json:"can-update-oauth"`
	CanUpdateSentinel           bool `json:"can-update-sentinel"`
}

TFEOrganizationPermissions represents the organization permissions.

type TFEOrganizationToken added in v0.3.17

type TFEOrganizationToken struct {
	ID        resource.TfeID `jsonapi:"primary,authentication-tokens"`
	CreatedAt time.Time      `jsonapi:"attribute" json:"created-at"`
	Token     string         `jsonapi:"attribute" json:"token"`
	ExpiredAt *time.Time     `jsonapi:"attribute" json:"expired-at"`
}

TFEOrganizationToken represents a Terraform Enterprise organization token.

type TFEOrganizationTokenCreateOptions added in v0.3.17

type TFEOrganizationTokenCreateOptions struct {
	// Optional: The token's expiration date.
	// This feature is available in TFE release v202305-1 and later
	ExpiredAt *time.Time `jsonapi:"attribute" json:"expired-at,omitempty"`
}

TFEOrganizationTokenCreateOptions contains the options for creating an organization token.

type TFEOrganizationUpdateOptions added in v0.3.17

type TFEOrganizationUpdateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,organizations"`

	// New name for the organization.
	Name *string `jsonapi:"attribute" json:"name,omitempty"`

	// Optional: AssessmentsEnforced toggles whether health assessment enablement is enforced across all assessable workspaces (those with a minimum terraform versio of 0.15.4 and not running in local execution mode) or if the decision to enabled health assessments is delegated to the workspace setting AssessmentsEnabled.
	AssessmentsEnforced *bool `jsonapi:"attribute" json:"assessments-enforced,omitempty"`

	// New admin email address.
	Email *string `jsonapi:"attribute" json:"email,omitempty"`

	// Session expiration (minutes).
	SessionRemember *int `jsonapi:"attribute" json:"session-remember,omitempty"`

	// Session timeout after inactivity (minutes).
	SessionTimeout *int `jsonapi:"attribute" json:"session-timeout,omitempty"`

	// Authentication policy.
	CollaboratorAuthPolicy *TFEAuthPolicyType `jsonapi:"attribute" json:"collaborator-auth-policy,omitempty"`

	// Enable Cost Estimation
	CostEstimationEnabled *bool `jsonapi:"attribute" json:"cost-estimation-enabled,omitempty"`

	// The name of the "owners" team
	OwnersTeamSAMLRoleID *string `jsonapi:"attribute" json:"owners-team-saml-role-id,omitempty"`

	// SendPassingStatusesForUntriggeredSpeculativePlans toggles behavior of untriggered speculative plans to send status updates to version control systems like GitHub.
	SendPassingStatusesForUntriggeredSpeculativePlans *bool `jsonapi:"attribute" json:"send-passing-statuses-for-untriggered-speculative-plans,omitempty"`

	// Optional: AllowForceDeleteWorkspaces toggles behavior of allowing workspace admins to delete workspaces with resources under management.
	AllowForceDeleteWorkspaces *bool `jsonapi:"attribute" json:"allow-force-delete-workspaces,omitempty"`
}

TFEOrganizationUpdateOptions represents the options for updating an organization.

type UpdateOptions added in v0.1.8

type UpdateOptions struct {
	Name            *string
	SessionRemember *int
	SessionTimeout  *int

	// TFE fields that OTF does not support but persists merely to pass the
	// go-tfe integration tests
	Email                      *string
	CollaboratorAuthPolicy     *string
	CostEstimationEnabled      *bool
	AllowForceDeleteWorkspaces *bool
}

UpdateOptions represents the options for updating an organization.

Jump to

Keyboard shortcuts

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