gcpresourcemanager

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 50 Imported by: ? modules, 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.

README

Google Cloud Resource Manager and Service Usage

Parity grade: B · SDK cloud.google.com/go/resourcemanager@v1.18.1 · last audited 2026-10-31 (4d0fa2d3a)

Coverage

Metric Value
PARITY entries audited 39 (12 ok, 25 partial, 2 gap)
Feature families 7 (4 ok, 3 partial)
Known gaps 3
Deferred items 0
Resource leaks clean
Known gaps
  • Enforcement (--gcp-enforce-projects, --gcp-enforce-service-enablement, default off) is wired through pkgs/gcpenforce but not everywhere: unenforced are Cloud Storage calls that name no project (object and bucket-scoped paths; only ?project= calls such as bucket create and list are checked), the Artifact Registry Docker /v2 registry, the Resource Manager v1 and Cloud Billing REST handlers, Cloud Functions and Cloud Run workload ingress, the Cloud DNS wire server, Identity Toolkit calls keyed by API key (accounts:signUp), operations endpoints (deliberately skipped), and requests that name no project (projects/- wildcards, folder or organization parents). A service missing from the 51-entry catalog is treated as enabled. The error shapes (403 PERMISSION_DENIED with ErrorInfo reason SERVICE_DISABLED / CONSUMER_INVALID, domain googleapis.com, metadata service and consumer, plus a Help link) and the message texts are recalled, not from a primary source; a DELETE_REQUESTED project answers CONSUMER_INVALID like an unknown one (the real 'Project #N has been deleted' form is unverified).
  • Project creation is instantaneous (operations are done when returned); real creation takes seconds and the operation can fail asynchronously. No quota (projects.create) or billing-account behaviour.
  • Not emulated: organizations other than the one configured, organization policies, ListEffectiveTags, folders and projects as tag-binding targets are accepted but tags are not inherited, v1beta1 Service Usage, Service Usage consumer quota and admin overrides, usage checks for check_if_service_has_usage, GetIamPolicy audit configs.

More

Documentation

Index

Constants

View Source
const (
	// DefaultPort is the dedicated gRPC and REST listener's default TCP port.
	DefaultPort = 8148
	// DefaultOrganizationID is the id of the single emulated organization.
	DefaultOrganizationID = "123456789012"
	// DefaultDomain is the display name (the domain) of the emulated organization.
	DefaultDomain = "gopherstack.local"
	// DefaultSeedProjects are the project ids created at startup.
	DefaultSeedProjects = "gopherstack-test"
	// DefaultDeleteRetention is how long a DELETE_REQUESTED project or folder stays restorable.
	DefaultDeleteRetention = 30 * 24 * time.Hour
)

Variables

View Source
var ErrNilAppContext = errors.New("gcpresourcemanager: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

Functions

func CatalogServices

func CatalogServices() []string

CatalogServices returns the googleapis.com names of every service the emulator can enable, sorted.

Types

type ConfigProvider

type ConfigProvider interface {
	GetGCPResourceManagerSettings() Settings
}

ConfigProvider extracts Resource Manager configuration from the AppContext Config.

type EnforceConfigProvider

type EnforceConfigProvider interface {
	GetGCPEnforceSettings() gcpenforce.Settings
}

EnforceConfigProvider extracts the opt-in GCP enforcement switches from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves Resource Manager (v3 gRPC and REST, v1 REST) and Service Usage on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) Enforcement

func (h *Handler) Enforcement() gcpenforce.Settings

Enforcement returns the active enforcement switches.

func (*Handler) EnforcementGate

func (h *Handler) EnforcementGate() *gcpenforce.Gate

EnforcementGate returns the Gate the other GCP services consult, or nil when enforcement is off.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) ProjectsAPI

func (h *Handler) ProjectsAPI() resourcemanagerpb.ProjectsServer

ProjectsAPI returns the Projects server for in-process callers.

func (*Handler) Reset

func (h *Handler) Reset()

Reset restores the seeded state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: the service runs on its own listener.

func (*Handler) ServiceUsageAPI

func (h *Handler) ServiceUsageAPI() serviceusagepb.ServiceUsageServer

ServiceUsageAPI returns the Service Usage server for in-process callers.

func (*Handler) SetEnforcement

func (h *Handler) SetEnforcement(s gcpenforce.Settings)

SetEnforcement turns the opt-in project and API-enablement checks of the other GCP services on or off.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the listener, forcing a close after a short grace period.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

type InMemoryBackend struct {
	Audit gcpaudit.Emitter
	// contains filtered or unexported fields
}

InMemoryBackend holds Resource Manager and Service Usage state under one lock.

func NewBackend

func NewBackend(s Settings) *InMemoryBackend

NewBackend creates a backend with the organization and seed projects of s.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates a backend for the default organization, with no projects.

func (*InMemoryBackend) BatchEnableServices

BatchEnableServices enables up to 20 services atomically: one unknown service fails the whole batch.

func (*InMemoryBackend) BatchGetServices

BatchGetServices returns the state of up to 30 services of one project.

func (*InMemoryBackend) BillingInfo

func (b *InMemoryBackend) BillingInfo(ref string) (billingInfo, error)

BillingInfo returns the Cloud Billing association of a project (billingAccountName is empty when none).

func (*InMemoryBackend) CheckProject

func (b *InMemoryBackend) CheckProject(project, service string) error

CheckProject returns CONSUMER_INVALID for service unless project (id or number) exists and is ACTIVE.

func (*InMemoryBackend) CheckServiceEnabled

func (b *InMemoryBackend) CheckServiceEnabled(project, service string) error

CheckServiceEnabled returns the SERVICE_DISABLED error Google APIs answer with when project has not enabled service, and nil when it has (or the service is not in the catalog). An unknown project is CONSUMER_INVALID.

func (*InMemoryBackend) CreateFolder

CreateFolder creates a folder under the organization or another folder.

func (*InMemoryBackend) CreateLien

func (b *InMemoryBackend) CreateLien(in V1Lien) (V1Lien, error)

CreateLien attaches a lien to an active project.

func (*InMemoryBackend) CreateProject

CreateProject creates a project; the returned operation is already done.

func (*InMemoryBackend) CreateTagBinding

CreateTagBinding binds a tag value to a resource; a resource holds one value per tag key.

func (*InMemoryBackend) CreateTagHold

CreateTagHold records a use of a tag value that no tag binding captures.

func (*InMemoryBackend) CreateTagKey

CreateTagKey creates a tag key under the organization or a project.

func (*InMemoryBackend) CreateTagValue

CreateTagValue creates a tag value under a tag key.

func (*InMemoryBackend) DeleteFolder

DeleteFolder marks an empty folder DELETE_REQUESTED; deleting a requested folder is a no-op.

func (*InMemoryBackend) DeleteLien

func (b *InMemoryBackend) DeleteLien(name string) error

DeleteLien removes a lien.

func (*InMemoryBackend) DeleteProject

DeleteProject marks an ACTIVE project DELETE_REQUESTED; deleting a requested project is a no-op.

func (*InMemoryBackend) DeleteTagBinding

DeleteTagBinding removes a tag binding.

func (*InMemoryBackend) DeleteTagHold

DeleteTagHold removes a tag hold.

func (*InMemoryBackend) DeleteTagKey

DeleteTagKey deletes a tag key that has no tag values.

func (*InMemoryBackend) DeleteTagValue

DeleteTagValue deletes a tag value that is not bound to any resource.

func (*InMemoryBackend) DisableService

DisableService disables an enabled service, and its enabled dependents when asked to.

func (*InMemoryBackend) EnableService

EnableService enables a service and its dependencies; enabling an enabled service succeeds.

func (*InMemoryBackend) GetFolder

func (b *InMemoryBackend) GetFolder(name string) (*resourcemanagerpb.Folder, error)

GetFolder returns a folder, including one that is DELETE_REQUESTED.

func (*InMemoryBackend) GetIamPolicy

func (b *InMemoryBackend) GetIamPolicy(in *iampb.GetIamPolicyRequest) (*iampb.Policy, error)

GetIamPolicy returns the policy of a resource at the requested version.

func (*InMemoryBackend) GetLien

func (b *InMemoryBackend) GetLien(name string) (V1Lien, error)

GetLien returns a lien by name.

func (*InMemoryBackend) GetNamespacedTagKey

func (b *InMemoryBackend) GetNamespacedTagKey(ns string) (*resourcemanagerpb.TagKey, error)

GetNamespacedTagKey finds a tag key by "{org id or project id}/{short name}".

func (*InMemoryBackend) GetNamespacedTagValue

func (b *InMemoryBackend) GetNamespacedTagValue(ns string) (*resourcemanagerpb.TagValue, error)

GetNamespacedTagValue finds a tag value by "{org or project id}/{key}/{value}".

func (*InMemoryBackend) GetOrganization

func (b *InMemoryBackend) GetOrganization(name string) (*resourcemanagerpb.Organization, error)

GetOrganization returns the emulated organization.

func (*InMemoryBackend) GetProject

func (b *InMemoryBackend) GetProject(name string) (*resourcemanagerpb.Project, error)

GetProject returns a project by number or id, including one that is DELETE_REQUESTED.

func (*InMemoryBackend) GetService

func (b *InMemoryBackend) GetService(name string) (*serviceusagepb.Service, error)

GetService returns a service's state for a project.

func (*InMemoryBackend) GetTagKey

func (b *InMemoryBackend) GetTagKey(name string) (*resourcemanagerpb.TagKey, error)

GetTagKey returns a tag key.

func (*InMemoryBackend) GetTagValue

func (b *InMemoryBackend) GetTagValue(name string) (*resourcemanagerpb.TagValue, error)

GetTagValue returns a tag value.

func (*InMemoryBackend) ListFolders

ListFolders lists the direct child folders of an organization or folder, ordered by display name.

func (*InMemoryBackend) ListLiens

func (b *InMemoryBackend) ListLiens(parent, token string, size int) (page.Page[V1Lien], error)

ListLiens lists the liens of one project.

func (*InMemoryBackend) ListProjects

ListProjects lists the direct children of a folder or organization, ordered by display name.

func (*InMemoryBackend) ListServices

ListServices lists the catalog's services with their state for a project, ordered by name.

func (*InMemoryBackend) ListTagBindings

ListTagBindings lists the tag bindings of a resource.

func (*InMemoryBackend) ListTagHolds

ListTagHolds lists the holds of a tag value; the filter takes holder and origin terms joined by AND.

func (*InMemoryBackend) ListTagKeys

ListTagKeys lists the tag keys of an organization or project.

func (*InMemoryBackend) ListTagValues

ListTagValues lists the values of a tag key.

func (*InMemoryBackend) MoveFolder

MoveFolder re-parents an ACTIVE folder under the organization or another active folder.

func (*InMemoryBackend) MoveProject

MoveProject re-parents an ACTIVE project under the organization or an active folder.

func (*InMemoryBackend) OrganizationName

func (b *InMemoryBackend) OrganizationName() string

OrganizationName is the resource name of the emulated organization.

func (*InMemoryBackend) ProjectIDs

func (b *InMemoryBackend) ProjectIDs() []string

ProjectIDs lists the ids of the projects that are not DELETE_REQUESTED, sorted.

func (*InMemoryBackend) ProjectInOrganization

func (b *InMemoryBackend) ProjectInOrganization(ref string) (bool, bool)

ProjectInOrganization reports (inOrganization, known): whether the project sits under the emulated organization through its folder ancestry, and false for known when the project is not registered.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset restores the seeded state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot, replacing all state; the organization stays as configured.

func (*InMemoryBackend) SearchFolders

SearchFolders returns the folders matching the query; ACTIVE ones unless the query names a state.

func (*InMemoryBackend) SearchOrganizations

SearchOrganizations returns the organization when it matches the query (domain or directoryCustomerId).

func (*InMemoryBackend) SearchProjects

SearchProjects returns the projects matching any term of the query; ACTIVE ones unless the query names a state.

func (*InMemoryBackend) SetBillingAccount

func (b *InMemoryBackend) SetBillingAccount(ref, account string) (billingInfo, error)

SetBillingAccount links a project to a billing account, or unlinks it when account is empty. Billing accounts are not modelled, so any well-formed name is accepted.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the clock timestamps and the deletion retention derive from.

func (*InMemoryBackend) SetIamPolicy

func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)

SetIamPolicy replaces a policy; a stale etag aborts the call.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises projects, folders, tags, enabled services, IAM policies and operations.

func (*InMemoryBackend) TestIamPermissions

TestIamPermissions reports every requested permission as granted: the emulator authorises all callers.

func (*InMemoryBackend) UndeleteFolder

UndeleteFolder restores a DELETE_REQUESTED folder; an ACTIVE folder is a no-op success.

func (*InMemoryBackend) UndeleteProject

UndeleteProject restores a DELETE_REQUESTED project.

func (*InMemoryBackend) UpdateFolder

UpdateFolder renames an ACTIVE folder.

func (*InMemoryBackend) UpdateProject

UpdateProject changes the display name and labels of an ACTIVE project.

func (*InMemoryBackend) UpdateTagKey

UpdateTagKey changes a tag key's description.

func (*InMemoryBackend) UpdateTagValue

UpdateTagValue changes a tag value's description.

type Provider

type Provider struct{}

Provider implements service.Provider for Resource Manager and Service Usage. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	OrganizationID string `` //nolint:lll // config struct tags are intentionally verbose
	/* 188-byte string literal not displayed */
	Domain string `` //nolint:lll // config struct tags are intentionally verbose
	/* 176-byte string literal not displayed */
	SeedProjects string `` //nolint:lll // config struct tags are intentionally verbose
	/* 244-byte string literal not displayed */
	DeleteRetention time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 264-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 252-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPResourceManager.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type V1Lien

type V1Lien struct {
	Name         string   `json:"name,omitempty"`
	Parent       string   `json:"parent,omitempty"`
	Origin       string   `json:"origin,omitempty"`
	Reason       string   `json:"reason,omitempty"`
	CreateTime   string   `json:"createTime,omitempty"`
	Restrictions []string `json:"restrictions,omitempty"`
}

V1Lien is the cloudresourcemanager v1 Lien resource.

Jump to

Keyboard shortcuts

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