Documentation
¶
Overview ¶
Package grafana emulates the Amazon Managed Grafana control-plane API (aws-sdk-go-v2/service/grafana, protocol restjson1).
Index ¶
- Constants
- Variables
- type APIKey
- type AssertionAttributes
- type Handler
- func (h *Handler) ChaosOperations() []string
- func (h *Handler) ChaosRegions() []string
- func (h *Handler) ChaosServiceName() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Snapshot(ctx context.Context) []byte
- type InMemoryBackend
- func (b *InMemoryBackend) AccountID() string
- func (b *InMemoryBackend) AssociateLicense(id, licenseType, grafanaToken string) (*Workspace, error)
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CreateWorkspace(req *createWorkspaceRequest) (*Workspace, error)
- func (b *InMemoryBackend) CreateWorkspaceAPIKey(workspaceID, keyName, keyRole string, secondsToLive int32) (*APIKey, error)
- func (b *InMemoryBackend) CreateWorkspaceServiceAccount(workspaceID, name, grafanaRole string) (*ServiceAccount, error)
- func (b *InMemoryBackend) CreateWorkspaceServiceAccountToken(workspaceID, serviceAccountID, name string, secondsToLive int32) (*ServiceAccountToken, error)
- func (b *InMemoryBackend) DeleteWorkspace(id string) (*Workspace, error)
- func (b *InMemoryBackend) DeleteWorkspaceAPIKey(workspaceID, keyName string) error
- func (b *InMemoryBackend) DeleteWorkspaceServiceAccount(workspaceID, serviceAccountID string) error
- func (b *InMemoryBackend) DeleteWorkspaceServiceAccountToken(workspaceID, serviceAccountID, tokenID string) error
- func (b *InMemoryBackend) DescribeWorkspace(id string) (*Workspace, error)
- func (b *InMemoryBackend) DescribeWorkspaceAuthentication(id string) (*Workspace, error)
- func (b *InMemoryBackend) DescribeWorkspaceConfiguration(id string) (string, string, error)
- func (b *InMemoryBackend) DisassociateLicense(id, licenseType string) (*Workspace, error)
- func (b *InMemoryBackend) ListPermissions(workspaceID, groupID, userID, userType string) ([]*Permission, error)
- func (b *InMemoryBackend) ListTagsForResource(resourceArn string) (map[string]string, error)
- func (b *InMemoryBackend) ListVersions(workspaceID string) ([]string, error)
- func (b *InMemoryBackend) ListWorkspaceServiceAccountTokens(workspaceID, serviceAccountID string) ([]*ServiceAccountToken, error)
- func (b *InMemoryBackend) ListWorkspaceServiceAccounts(workspaceID string) ([]*ServiceAccount, error)
- func (b *InMemoryBackend) ListWorkspaces() []*Workspace
- func (b *InMemoryBackend) Region() string
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) TagResource(_ context.Context, resourceArn string, newTags map[string]string) error
- func (b *InMemoryBackend) TaggedResources() []TaggedEntry
- func (b *InMemoryBackend) UntagResource(_ context.Context, resourceArn string, tagKeys []string) error
- func (b *InMemoryBackend) UpdatePermissions(workspaceID string, instructions []updateInstructionWire) ([]updateErrorWire, error)
- func (b *InMemoryBackend) UpdateWorkspace(id string, req *updateWorkspaceRequest) (*Workspace, error)
- func (b *InMemoryBackend) UpdateWorkspaceAuthentication(id string, req *updateWorkspaceAuthenticationRequest) (*Workspace, error)
- func (b *InMemoryBackend) UpdateWorkspaceConfiguration(id string, req *updateWorkspaceConfigurationRequest) error
- func (b *InMemoryBackend) WorkspaceARN(id string) string
- type NetworkAccessConfiguration
- type Permission
- type Provider
- type RoleValues
- type SamlConfiguration
- type ServiceAccount
- type ServiceAccountToken
- type TaggedEntry
- type VpcConfiguration
- type Workspace
Constants ¶
const ( StatusActive = "ACTIVE" StatusCreating = "CREATING" StatusDeleting = "DELETING" StatusFailed = "FAILED" StatusUpdating = "UPDATING" StatusUpgrading = "UPGRADING" StatusDeletionFailed = "DELETION_FAILED" StatusCreationFailed = "CREATION_FAILED" StatusUpdateFailed = "UPDATE_FAILED" StatusUpgradeFailed = "UPGRADE_FAILED" StatusLicenseRemovalFailed = "LICENSE_REMOVAL_FAILED" StatusVersionUpdating = "VERSION_UPDATING" StatusVersionUpdateFailed = "VERSION_UPDATE_FAILED" StatusDegraded = "DEGRADED" )
Workspace lifecycle statuses, mirroring types.WorkspaceStatus in aws-sdk-go-v2/service/grafana/types/enums.go. Only the subset this emulator actually drives (Active/Creating/Updating/Deleting/Upgrading/ VersionUpdating) is exercised; the *_FAILED and Degraded values are wire- accurate constants but this in-memory backend has no fault-injection path that produces them today (see PARITY.md "deliberately simplified").
const ( AuthProviderAWSSSO = "AWS_SSO" AuthProviderSAML = "SAML" )
AuthenticationProviderTypes wire values (types.AuthenticationProviderTypes).
const ( SamlStatusConfigured = "CONFIGURED" SamlStatusNotConfigured = "NOT_CONFIGURED" )
SamlConfigurationStatus wire values (types.SamlConfigurationStatus).
const ( LicenseEnterprise = "ENTERPRISE" LicenseEnterpriseFreeTrial = "ENTERPRISE_FREE_TRIAL" )
LicenseType wire values (types.LicenseType).
const ( PermissionTypeCustomerManaged = "CUSTOMER_MANAGED" PermissionTypeServiceManaged = "SERVICE_MANAGED" AccountAccessTypeCurrentAccount = "CURRENT_ACCOUNT" AccountAccessTypeOrganization = "ORGANIZATION" )
PermissionType / AccountAccessType wire values.
const ( RoleAdmin = "ADMIN" RoleEditor = "EDITOR" RoleViewer = "VIEWER" )
Role wire values (types.Role), shared by permissions, API keys, and service accounts.
const ( UserTypeSSOUser = "SSO_USER" UserTypeSSOGroup = "SSO_GROUP" )
UserType wire values (types.UserType).
const ( UpdateActionAdd = "ADD" UpdateActionRevoke = "REVOKE" )
UpdateAction wire values (types.UpdateAction).
Variables ¶
var ErrNilAppContext = errors.New("AppContext is required")
ErrNilAppContext is returned by Provider.Init when appCtx is nil.
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct {
CreatedAt time.Time
ExpiresAt time.Time
WorkspaceID string
KeyName string
KeyRole string
Key string
}
APIKey mirrors the legacy CreateWorkspaceApiKey mechanism. Keyed by WorkspaceID + KeyName. The plaintext Key is generated once at creation and stored so it can be validated/echoed; the real API never lets a caller retrieve it again either (there is no GetWorkspaceApiKey operation).
type AssertionAttributes ¶
type AssertionAttributes struct {
Email string
Groups string
Login string
Name string
Org string
Role string
}
AssertionAttributes mirrors types.AssertionAttributes.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
AccountID string
Region string
}
Handler is the HTTP handler for the Amazon Managed Grafana API.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a new Grafana handler.
func (*Handler) ChaosOperations ¶
ChaosOperations returns all operations that can be fault-injected.
func (*Handler) ChaosRegions ¶
ChaosRegions returns all regions this handler handles.
func (*Handler) ChaosServiceName ¶
ChaosServiceName returns the lowercase AWS service name for fault rule matching.
func (*Handler) ExtractOperation ¶
ExtractOperation extracts the operation name from the request.
func (*Handler) ExtractResource ¶
ExtractResource extracts the primary resource identifier from the request.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations returns every operation this handler routes -- all 25 operations on the aws-sdk-go-v2/service/grafana client, per sdk_completeness_test.go's empty exception list.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler function for Grafana requests.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) RouteMatcher ¶
RouteMatcher returns a function that matches Grafana API requests.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is the in-memory store for Amazon Managed Grafana.
A single coarse lock guards every collection below: nearly every operation in this service reads or mutates workspace-scoped state (a workspace's own fields, or one of its child collections keyed by workspace ID), so the invariant boundary is the whole backend, not any one collection -- see .claude/memories/pkgs-catalog.md's locking rule.
func NewInMemoryBackend ¶
func NewInMemoryBackend(ctx context.Context, accountID, region string) *InMemoryBackend
NewInMemoryBackend creates a new in-memory Amazon Managed Grafana backend.
func (*InMemoryBackend) AccountID ¶
func (b *InMemoryBackend) AccountID() string
AccountID returns the account ID for this backend.
func (*InMemoryBackend) AssociateLicense ¶
func (b *InMemoryBackend) AssociateLicense(id, licenseType, grafanaToken string) (*Workspace, error)
AssociateLicense assigns a Grafana Enterprise license to a workspace. ENTERPRISE_FREE_TRIAL is rejected: "Amazon Managed Grafana workspaces no longer support Grafana Enterprise free trials" (CreateWorkspaceApiKeyInput's sibling AssociateLicenseInput.LicenseType doc comment) is a real-service behavior fact this emulator encodes rather than silently accepting.
The not-ACTIVE precondition below is reported as ValidationException, NOT ConflictException: unlike UpdateWorkspace/UpdateWorkspaceConfiguration, AssociateLicense's own deserializeOpErrorAssociateLicense in the real SDK's deserializers.go does not list ConflictException among the error shapes it recognizes for this operation -- returning one here would deserialize client-side as an untyped smithy.GenericAPIError instead of a matchable *types.ConflictException, breaking real caller error handling.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops all scheduled state-transition timers so none outlives the backend. Safe to call multiple times.
func (*InMemoryBackend) CreateWorkspace ¶
func (b *InMemoryBackend) CreateWorkspace(req *createWorkspaceRequest) (*Workspace, error)
CreateWorkspace creates a new workspace in the CREATING state, scheduling its async transition to ACTIVE (see scheduleWorkspaceTransition).
func (*InMemoryBackend) CreateWorkspaceAPIKey ¶
func (b *InMemoryBackend) CreateWorkspaceAPIKey( workspaceID, keyName, keyRole string, secondsToLive int32, ) (*APIKey, error)
CreateWorkspaceAPIKey creates a Grafana API key for a workspace (implements the CreateWorkspaceApiKey SDK operation).
func (*InMemoryBackend) CreateWorkspaceServiceAccount ¶
func (b *InMemoryBackend) CreateWorkspaceServiceAccount( workspaceID, name, grafanaRole string, ) (*ServiceAccount, error)
CreateWorkspaceServiceAccount creates a service account within a workspace.
func (*InMemoryBackend) CreateWorkspaceServiceAccountToken ¶
func (b *InMemoryBackend) CreateWorkspaceServiceAccountToken( workspaceID, serviceAccountID, name string, secondsToLive int32, ) (*ServiceAccountToken, error)
CreateWorkspaceServiceAccountToken creates a token for a workspace service account, returning the plaintext key exactly once (matching ServiceAccountTokenSummaryWithKey's doc comment: "it is not retrievable at a later time").
func (*InMemoryBackend) DeleteWorkspace ¶
func (b *InMemoryBackend) DeleteWorkspace(id string) (*Workspace, error)
DeleteWorkspace deletes a workspace, cascading to its API keys, service accounts, service account tokens, and permissions (real AWS would reject deletion of a workspace with certain dependent resources still attached; this emulator instead cascades synchronously, matching services/eks's DeleteCluster "for test convenience this fake cascades" precedent). The returned copy reflects the workspace's state immediately before removal, with Status forced to DELETING.
func (*InMemoryBackend) DeleteWorkspaceAPIKey ¶
func (b *InMemoryBackend) DeleteWorkspaceAPIKey(workspaceID, keyName string) error
DeleteWorkspaceAPIKey deletes a Grafana API key from a workspace (implements the DeleteWorkspaceApiKey SDK operation).
func (*InMemoryBackend) DeleteWorkspaceServiceAccount ¶
func (b *InMemoryBackend) DeleteWorkspaceServiceAccount(workspaceID, serviceAccountID string) error
DeleteWorkspaceServiceAccount deletes a service account, cascading to its tokens (real behavior: "This will delete any tokens created for the service account, as well").
func (*InMemoryBackend) DeleteWorkspaceServiceAccountToken ¶
func (b *InMemoryBackend) DeleteWorkspaceServiceAccountToken(workspaceID, serviceAccountID, tokenID string) error
DeleteWorkspaceServiceAccountToken deletes a token for a workspace service account.
func (*InMemoryBackend) DescribeWorkspace ¶
func (b *InMemoryBackend) DescribeWorkspace(id string) (*Workspace, error)
DescribeWorkspace returns a copy of the workspace with the given ID.
func (*InMemoryBackend) DescribeWorkspaceAuthentication ¶
func (b *InMemoryBackend) DescribeWorkspaceAuthentication(id string) (*Workspace, error)
DescribeWorkspaceAuthentication returns the authentication state for a workspace.
func (*InMemoryBackend) DescribeWorkspaceConfiguration ¶
func (b *InMemoryBackend) DescribeWorkspaceConfiguration(id string) (string, string, error)
DescribeWorkspaceConfiguration returns the opaque configuration JSON blob and current Grafana version for a workspace.
func (*InMemoryBackend) DisassociateLicense ¶
func (b *InMemoryBackend) DisassociateLicense(id, licenseType string) (*Workspace, error)
DisassociateLicense removes the Grafana Enterprise license from a workspace. Disassociating a license type the workspace does not currently have is treated as an idempotent no-op (the workspace is returned unchanged) rather than an error: deserializeOpErrorDisassociateLicense in the real SDK's deserializers.go does not list ConflictException among the error shapes this operation can return, so there is no wire-accurate way to signal "nothing to remove" as an error here (unlike, e.g., AssociateLicense's ValidationException path for an unsupported license type, this isn't a malformed-request condition either).
func (*InMemoryBackend) ListPermissions ¶
func (b *InMemoryBackend) ListPermissions(workspaceID, groupID, userID, userType string) ([]*Permission, error)
ListPermissions returns the permission grants for a workspace, optionally filtered by groupID, userID, and/or userType -- mirroring ListPermissionsInput's groupId/userId/userType query parameters.
func (*InMemoryBackend) ListTagsForResource ¶
func (b *InMemoryBackend) ListTagsForResource(resourceArn string) (map[string]string, error)
ListTagsForResource returns the tags for the workspace identified by resourceArn.
func (*InMemoryBackend) ListVersions ¶
func (b *InMemoryBackend) ListVersions(workspaceID string) ([]string, error)
ListVersions returns the Grafana versions creatable (workspaceID == "") or, when workspaceID is non-empty, the versions that specific workspace may upgrade to.
func (*InMemoryBackend) ListWorkspaceServiceAccountTokens ¶
func (b *InMemoryBackend) ListWorkspaceServiceAccountTokens( workspaceID, serviceAccountID string, ) ([]*ServiceAccountToken, error)
ListWorkspaceServiceAccountTokens returns every token for a workspace service account (never including the plaintext key -- see types.ServiceAccountTokenSummary's doc comment on this file's models.go).
func (*InMemoryBackend) ListWorkspaceServiceAccounts ¶
func (b *InMemoryBackend) ListWorkspaceServiceAccounts(workspaceID string) ([]*ServiceAccount, error)
ListWorkspaceServiceAccounts returns every service account for a workspace.
func (*InMemoryBackend) ListWorkspaces ¶
func (b *InMemoryBackend) ListWorkspaces() []*Workspace
ListWorkspaces returns every workspace, ordered by ID (matching store.Table.Snapshot's deterministic ordering).
func (*InMemoryBackend) Region ¶
func (b *InMemoryBackend) Region() string
Region returns the AWS region this backend is configured for.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state from a JSON snapshot.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the backend state to JSON.
func (*InMemoryBackend) TagResource ¶
func (b *InMemoryBackend) TagResource(_ context.Context, resourceArn string, newTags map[string]string) error
TagResource adds or updates tags on the workspace identified by resourceArn. Only workspaces are taggable ("Currently, the only resource that can be tagged is workspaces" -- TagResourceInput's doc comment).
func (*InMemoryBackend) TaggedResources ¶
func (b *InMemoryBackend) TaggedResources() []TaggedEntry
TaggedResources returns every tagged workspace, for the resourcegroupstaggingapi integration.
func (*InMemoryBackend) UntagResource ¶
func (b *InMemoryBackend) UntagResource(_ context.Context, resourceArn string, tagKeys []string) error
UntagResource removes tags from the workspace identified by resourceArn.
func (*InMemoryBackend) UpdatePermissions ¶
func (b *InMemoryBackend) UpdatePermissions( workspaceID string, instructions []updateInstructionWire, ) ([]updateErrorWire, error)
UpdatePermissions applies a batch of ADD/REVOKE instructions to a workspace's permission grants. This is explicitly a partial-failure batch op (matching UpdatePermissionsOutput.Errors's doc comment): a malformed instruction is recorded in the returned error slice rather than aborting the whole batch.
func (*InMemoryBackend) UpdateWorkspace ¶
func (b *InMemoryBackend) UpdateWorkspace(id string, req *updateWorkspaceRequest) (*Workspace, error)
UpdateWorkspace merges req onto the named workspace. The workspace must be ACTIVE or DEGRADED (not mid-transition) or this returns a ConflictException- shaped error.
func (*InMemoryBackend) UpdateWorkspaceAuthentication ¶
func (b *InMemoryBackend) UpdateWorkspaceAuthentication( id string, req *updateWorkspaceAuthenticationRequest, ) (*Workspace, error)
UpdateWorkspaceAuthentication updates a workspace's authentication providers and, when SAML is enabled, its SAML configuration.
func (*InMemoryBackend) UpdateWorkspaceConfiguration ¶
func (b *InMemoryBackend) UpdateWorkspaceConfiguration(id string, req *updateWorkspaceConfigurationRequest) error
UpdateWorkspaceConfiguration replaces a workspace's configuration blob and, when GrafanaVersion is supplied, upgrades it (upgrade-only -- see isUpgradeVersion). The workspace must be ACTIVE or DEGRADED.
func (*InMemoryBackend) WorkspaceARN ¶
func (b *InMemoryBackend) WorkspaceARN(id string) string
WorkspaceARN builds the ARN for a workspace ID. Confirmed via terraform-provider-aws's internal/service/grafana/workspace.go (workspaceARN: c.RegionalARN(ctx, "grafana", "/workspaces/"+id)) -- see PARITY.md for the full verification trail. Note the leading "/" baked into the resource segment itself, not a separate "/" join.
type NetworkAccessConfiguration ¶
NetworkAccessConfiguration mirrors types.NetworkAccessConfiguration. Both fields are real (possibly empty, never nil once set) lists: an empty slice on both means the workspace is fully locked (see doc comment on the real type), not "no configuration".
type Permission ¶
Permission is one (workspace, user) -> role grant, mirroring types.PermissionEntry (Role + User{Id,Type}) plus the WorkspaceID needed to key/index it.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Amazon Managed Grafana.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init initializes the Grafana service backend and handler.
type RoleValues ¶
RoleValues mirrors types.RoleValues.
type SamlConfiguration ¶
type SamlConfiguration struct {
AssertionAttributes *AssertionAttributes
RoleValues *RoleValues
IdpMetadataURL string
IdpMetadataXML string
AllowedOrganizations []string
LoginValidityDuration int32
}
SamlConfiguration mirrors types.SamlConfiguration. IdpMetadataURL and IdpMetadataXML represent the two members of the types.IdpMetadata union; exactly one may be set at a time (validated by UpdateWorkspaceAuthentication -- see authentication.go), mirroring "Specifying both will cause an error" on the real union's doc comment.
type ServiceAccount ¶
type ServiceAccount struct {
WorkspaceID string
ID string
Name string
GrafanaRole string
IsDisabled bool
}
ServiceAccount mirrors types.ServiceAccountSummary plus the WorkspaceID needed to key/index it.
type ServiceAccountToken ¶
type ServiceAccountToken struct {
CreatedAt time.Time
ExpiresAt time.Time
LastUsedAt time.Time
WorkspaceID string
ServiceAccountID string
ID string
Name string
Key string
}
ServiceAccountToken mirrors types.ServiceAccountTokenSummary plus the plaintext Key (only ever surfaced once, by CreateWorkspaceServiceAccountToken's ServiceAccountTokenSummaryWithKey response shape -- see service_account_tokens.go).
type TaggedEntry ¶
TaggedEntry is one tagged resource, used by TaggedResources for the resourcegroupstaggingapi integration (cli.go's wireTaggingGrafana).
type VpcConfiguration ¶
VpcConfiguration mirrors types.VpcConfiguration.
type Workspace ¶
type Workspace struct {
Created time.Time
Modified time.Time
LicenseExpiration time.Time
FreeTrialExpiration time.Time
NetworkAccessControl *NetworkAccessConfiguration
VpcConfiguration *VpcConfiguration
SamlConfig *SamlConfiguration
Tags *tags.Tags
ID string
ARN string
Name string
Description string
AccountAccessType string
PermissionType string
Status string
DegradedWorkspaceReason string
Endpoint string
GrafanaVersion string
Configuration string
OrganizationRoleName string
StackSetName string
KmsKeyID string
IPAddressType string
WorkspaceRoleARN string
LicenseType string
GrafanaToken string
SsoClientID string
SamlConfigurationStatus string
AuthenticationProviders []string
DataSources []string
NotificationDestinations []string
OrganizationalUnits []string
FreeTrialConsumed bool
}
Workspace is the internal state of one Amazon Managed Grafana workspace, a superset of types.WorkspaceDescription plus bookkeeping fields not on the wire (ARN, and the SAML/AWS-SSO sub-state that DescribeWorkspace does not itself expose but DescribeWorkspaceAuthentication does).
Source Files
¶
- api_keys.go
- authentication.go
- configuration.go
- consts.go
- errors.go
- handler.go
- handler_api_keys.go
- handler_authentication.go
- handler_configuration.go
- handler_license.go
- handler_permissions.go
- handler_service_account_tokens.go
- handler_service_accounts.go
- handler_tags.go
- handler_versions.go
- handler_workspaces.go
- license.go
- models.go
- permissions.go
- persistence.go
- provider.go
- service_account_tokens.go
- service_accounts.go
- store.go
- store_setup.go
- tags.go
- versions.go
- wire.go
- wire_convert.go
- workspace_update.go
- workspaces.go