Documentation
¶
Overview ¶
Package connhub is a read model over the existing connection stores (git, registry, notify, secrets, DNS, cloud, webhooks). It never calls a provider and never carries a secret.
Index ¶
- Constants
- Variables
- func Covers(c Connection, t Target) bool
- func KnownRole(role string) bool
- func RoleSupported(c Connection, role string) bool
- func Roles() []string
- func ValidateRules(role string, raw []byte, lim RuleLimits) (string, error)
- type Binding
- type CatalogEntry
- type CloudReader
- type Connection
- type DNSReader
- type Filter
- type GitReader
- type MetaReader
- type NotifyChannel
- type NotifyReader
- type RegistryReader
- type ResolvedBinding
- type RuleLimits
- type SecretReader
- type Service
- type Sources
- type Target
- type WebhookReader
Constants ¶
const ( ConnectOneClick = "one_click" ConnectGuidedOAuth = "guided_oauth" ConnectToken = "token" ConnectSettingsPage = "settings_page" )
Connect methods a catalogue entry can offer.
const ( KindGit = "git" KindRegistry = "registry" KindNotify = "notify" KindSecret = "secret" KindDNS = "dns" KindCloud = "cloud" KindWebhook = "webhook" )
Kinds of connection. The ref prefix is the kind.
const ( HealthOK = "ok" HealthDegraded = "degraded" HealthNeedsReconnect = "needs_reconnect" HealthExpired = "expired" HealthUnknown = "unknown" )
Health values. They come from what each store already records.
const ( AuthAppInstall = "app_install" AuthOAuth = "oauth" AuthToken = "token" AuthWorkloadIdentity = "workload_identity" AuthURLSecret = "url_secret" )
Auth methods an adapter can report.
const ( CapSource = "source" CapWebhook = "webhook" CapStatus = "status" CapDeployments = "deployments" CapPreviews = "previews" CapRegistryPull = "registry_pull" CapNotify = "notify" CapSecrets = "secrets" CapDNS = "dns" CapProvisionHost = "provision" )
Capabilities a connection offers.
const DefaultRuleValueMaxLen = 512
DefaultRuleValueMaxLen bounds one rule string when no limit is configured.
Variables ¶
var ( ErrNotFound = errors.New("connhub: connection not found") ErrInvalid = errors.New("connhub: invalid request") )
Errors returned by the service.
Functions ¶
func Covers ¶
func Covers(c Connection, t Target) bool
Covers reports whether a connection's scope reaches target. A binding is refused when it does not, so binding never widens a connection's reach.
func RoleSupported ¶
func RoleSupported(c Connection, role string) bool
RoleSupported reports whether c has a capability that can fill role.
func ValidateRules ¶
func ValidateRules(role string, raw []byte, lim RuleLimits) (string, error)
ValidateRules checks raw against the role's schema and the size caps, and returns the canonical JSON to store. Empty input means no rules.
Types ¶
type Binding ¶
type Binding struct {
ID string `json:"id,omitempty"`
Ref string `json:"ref"`
TargetType string `json:"target_type"`
TargetID string `json:"target_id"`
Role string `json:"role"`
Rules string `json:"rules,omitempty"`
Origin string `json:"origin"`
}
Binding is one link between a connection and a target. Origin is "legacy" for links derived from the old columns and "binding" for rows in connection_bindings.
func CoveredBindings ¶
func CoveredBindings(rows []Binding, conns map[string]Connection, target Target) []Binding
CoveredBindings keeps the rows Resolve would keep from an app's own list: derived rows, and stored rows whose connection still covers the target.
type CatalogEntry ¶
type CatalogEntry struct {
ID string `json:"id"`
Category string `json:"category"`
Name string `json:"name"`
ConnectMethods []string `json:"connect_methods"`
CreateEndpoint string `json:"create_endpoint,omitempty"`
}
CatalogEntry names a provider the user can connect and the existing endpoint that creates it. The hub never creates connections itself, so CreateEndpoint is empty when no plain create route exists.
func Catalog ¶
func Catalog() []CatalogEntry
Catalog returns the static provider catalogue. Providers of a category share one create endpoint.
type CloudReader ¶
type CloudReader interface {
ListCloudConnections(ctx context.Context) ([]store.CloudConnection, error)
}
CloudReader reads cloud account connections.
type Connection ¶
type Connection struct {
Ref string `json:"ref"`
Kind string `json:"kind"`
Provider string `json:"provider"`
Label string `json:"label"`
Account string `json:"account,omitempty"`
Host string `json:"host,omitempty"`
ScopeType string `json:"scope_type"`
ScopeID string `json:"scope_id,omitempty"`
AuthMethod string `json:"auth_method"`
Health string `json:"health"`
HealthDetail string `json:"health_detail,omitempty"`
CheckedAt *time.Time `json:"checked_at,omitempty"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
ExpiringSoon bool `json:"expiring_soon"`
RotateAfter *time.Time `json:"rotate_after,omitempty"`
Capabilities []string `json:"capabilities"`
BoundCount int `json:"bound_count"`
CreatedAt *time.Time `json:"created_at,omitempty"`
IsDefault bool `json:"is_default,omitempty"`
}
Connection is one projected connection. No field holds a credential value.
type DNSReader ¶
type DNSReader interface {
GetCloudflareDNSSettings(ctx context.Context) (store.CloudflareDNSSettings, error)
GetRoute53DNSSettings(ctx context.Context) (store.Route53DNSSettings, error)
GetGoogleCloudDNSSettings(ctx context.Context) (store.GoogleCloudDNSSettings, error)
}
DNSReader reads the per provider DNS settings rows.
type GitReader ¶
type GitReader interface {
ListGitConnections(ctx context.Context, provider string) ([]store.GitConnection, error)
GetGitConnectionStatus(ctx context.Context, provider string) (store.GitConnectionStatus, bool, error)
GetGitHubAppConnection(ctx context.Context) (store.GitHubAppConnection, error)
ListGitHubAppInstallations(ctx context.Context) ([]store.GitHubAppInstallation, error)
ListGitSourcesByConnection(ctx context.Context, connectionID string) ([]string, error)
GetGitSource(ctx context.Context, serviceName string) (*store.GitSource, error)
}
GitReader reads forge connections and their recorded health.
type MetaReader ¶
type MetaReader interface {
ListConnectionMeta(ctx context.Context) (map[string]store.ConnectionMeta, error)
CountConnectionBindingsByRef(ctx context.Context) (map[string]int, error)
ListConnectionBindingsByTarget(ctx context.Context, targetType, targetID string) ([]store.ConnectionBinding, error)
}
MetaReader reads the hub sidecar and bindings tables.
type NotifyChannel ¶
NotifyChannel is the slice of a notification channel the hub shows, kept here so this package does not import the alerting package and its large dependency tree.
type NotifyReader ¶
type NotifyReader interface {
ListNotificationChannels(ctx context.Context) ([]NotifyChannel, error)
}
NotifyReader reads notification channels.
type RegistryReader ¶
type RegistryReader interface {
ListRegistryCredentials(ctx context.Context) ([]store.RegistryCredential, error)
}
RegistryReader reads registry credentials.
type ResolvedBinding ¶
type ResolvedBinding struct {
Binding
InheritedFrom string `json:"inherited_from,omitempty"`
Overridden bool `json:"overridden,omitempty"`
}
ResolvedBinding is one effective binding for an app. InheritedFrom names the org when the row comes from org defaults; Overridden marks an org row an app binding replaces for the same role.
func Resolve ¶
func Resolve(app, org []Binding, conns map[string]Connection, target Target) []ResolvedBinding
Resolve merges an app's own bindings with its org's: per role the app wins, the org fills gaps. Stored rows whose connection is gone or whose scope no longer covers the app are dropped, so a later scope change cannot leak.
type RuleLimits ¶
RuleLimits caps the whole rules document and each string inside it.
type SecretReader ¶
type SecretReader interface {
ListSecretConnections(ctx context.Context) ([]store.SecretConnection, error)
}
SecretReader reads named secret provider connections.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service projects connections from the configured sources.
func New ¶
New builds a service. expiryWarn supplies the warning window, read live from runtime settings.
func (*Service) AppBindings ¶
AppBindings returns the stored bindings of an app plus the links its legacy columns imply.
type Sources ¶
type Sources struct {
Git GitReader
Registry RegistryReader
Notify NotifyReader
Secrets SecretReader
DNS DNSReader
Cloud CloudReader
Webhooks WebhookReader
Meta MetaReader
}
Sources bundles the readers the service projects from.
type Target ¶
Target is what a binding points at. TeamID is the org that owns an app target, or the org itself for an org target.
type WebhookReader ¶
type WebhookReader interface {
ListEventWebhooks(ctx context.Context) ([]store.EventWebhook, error)
ListStatusWebhooks(ctx context.Context) ([]store.StatusWebhook, error)
}
WebhookReader reads outbound event and status page webhooks.