repository

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const HostIPAcornName = "hostip"
View Source
const IdentityProviderAcornName = "idp"
View Source
const KafkaAcornName = "kafka"
View Source
const MetadataAcornName = "metadata"
View Source
const VaultAcornName = "vault"

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitInfo

type CommitInfo struct {
	CommitHash   string
	TimeStamp    time.Time
	Message      string
	FilesChanged []string
}

CommitInfo holds information about a commit.

type CustomConfiguration

type CustomConfiguration interface {
	BbUser() string

	GitCommitterName() string
	GitCommitterEmail() string

	KafkaUser() string
	KafkaTopic() string
	KafkaSeedBrokers() string
	KafkaGroupIdOverride() string

	KeySetUrl() string

	MetadataRepoUrl() string

	OwnerRegex() string

	UpdateJobIntervalCronPart() string
	UpdateJobTimeoutSeconds() uint16

	VaultSecretsBasePath() string
	VaultKafkaSecretPath() string

	AlertTargetPrefix() string
	AlertTargetSuffix() string
}

func Custom

func Custom(configuration librepo.Configuration) CustomConfiguration

Custom is a type casting helper that gets you from the configuration acorn to your CustomConfiguration

type EventAffects

type EventAffects struct {
	OwnerAliases   []string `json:"ownerAliases"`
	ServiceNames   []string `json:"serviceNames"`
	RepositoryKeys []string `json:"repositoryKeys"`
}

type HostIP

type HostIP interface {
	IsHostIP() bool

	// ObtainLocalIp gets the first non-localhost ipv4 address from your interfaces.
	//
	// In a k8s deployment, that'll be the pod ip.
	ObtainLocalIp() (net.IP, error)
}

HostIP interacts with the local network interfaces.

type IdentityProvider

type IdentityProvider interface {
	IsIdentityProvider() bool

	// Setup uses the configuration to set up
	Setup(ctx context.Context) error

	// ObtainKeySet calls the key set endpoint and converts the keys to PEM for use with the jwt package
	ObtainKeySet(ctx context.Context) error

	// GetKeySet returns the previously obtained KeySet
	GetKeySet(ctx context.Context) []string

	// VerifyToken ensures synchronously that a token has not been revoked and the account is current.
	//
	// You should do this for critical operations that cannot live with the usual token
	// expiry cycle.
	VerifyToken(ctx context.Context, token string) error
}

IdentityProvider is the central singleton representing an Open ID Connect Identity Provider.

We use this to obtain a JWT keyset and to check its id endpoint to synchronously validate JWT tokens.

type Kafka

type Kafka interface {
	IsKafka() bool

	// SubscribeIncoming allows you to register a callback that is called whenever a message is received from the Kafka bus.
	//
	// Note, we currently only allow a single callback, so calling this multiple times will overwrite the callback.
	// Use this during application setup.
	SubscribeIncoming(ctx context.Context, callback ReceiverCallback) error

	// Send sends an UpdateEvent that originates in this application to the Kafka bus.
	Send(ctx context.Context, event UpdateEvent) error

	// StartReceiveLoop starts a background goroutine that calls the subscribed callback when messages come in
	StartReceiveLoop(ctx context.Context) error
}

Kafka is the central singleton representing the kafka messaging bus.

type Metadata

type Metadata interface {
	IsMetadata() bool

	// Clone performs an initial in-memory clone of the metadata repository on the mainline
	Clone(ctx context.Context) error

	// Pull updates the in-memory clone of the metadata repository on the mainline
	//
	// Any new commits that were not previously seen can now be obtained by NewPulledCommits.
	Pull(ctx context.Context) error

	// Commit performs a local add all and commit and returns the commit hash and the timestamp
	//
	// note: if this fails, the repository may be in an inconsistent state, so you should
	// Discard and Clone it again.
	Commit(ctx context.Context, message string) (CommitInfo, error)

	// Push sends commits from the in-memory clone to the upstream
	Push(ctx context.Context) error

	// Discard the in-memory clone (cannot fail, but will leave memory allocated until garbage collection)
	//
	// note: doing a new Clone implicitly discards
	Discard(ctx context.Context)

	// LastUpdated gives the time the git repo was last pulled (or pushed, which also ensures it is up-to-date).
	LastUpdated() time.Time

	// NewPulledCommits gives the business logic access to information about the newly pulled commits.
	//
	// The list is available until the next call to Pull, which clears it and adds any new commits.
	NewPulledCommits() []CommitInfo

	// IsCommitKnown is true if the given commit has been cloned, pulled or locally committed, meaning,
	// a Pull would not generate new information if this commit hash is in the pull.
	IsCommitKnown(hash string) bool

	Stat(filename string) (os.FileInfo, error)
	ReadDir(path string) ([]os.FileInfo, error)

	// ReadFile returns the contents of a file, the commit hash, timestamp and message for the last change to the file
	ReadFile(filename string) ([]byte, CommitInfo, error)

	// WriteFile creates or overwrites a file in the local copy
	WriteFile(filename string, contents []byte) error

	// DeleteFile deletes a file in the local copy
	DeleteFile(filename string) error

	// Mkdir creates a new directory (and potentially all directories leading up to it). Does nothing if already exists.
	MkdirAll(path string) error
}

Metadata is the central singleton representing the service-metadata git repository.

All operations are protected by a mutex, but of course this does not prevent multiple goroutines from making changes between operations, so you will probably need a higher level mutex to avoid inadvertently committing changes made by another goroutine.

type ReceiverCallback

type ReceiverCallback func(event UpdateEvent)

type UpdateEvent

type UpdateEvent struct {
	Affected EventAffects `json:"affected"`

	// ISO-8601 UTC date time at which this information was committed.
	TimeStamp string `json:"timeStamp"`
	// The git commit hash this information was committed under.
	CommitHash string `json:"commitHash"`
}

type Vault

type Vault interface {
	IsVault() bool

	// Setup uses the configuration
	Setup(ctx context.Context) error

	// Authenticate authenticates against vault
	Authenticate(ctx context.Context) error

	// ObtainSecrets fetches the regular secrets from vault
	ObtainSecrets(ctx context.Context) error

	// ObtainKafkaSecrets fetches the kafka secrets from vault (skipped if kafka username / topic not configured)
	ObtainKafkaSecrets(ctx context.Context) error

	BbPassword() string

	KafkaPassword() string

	BasicAuthUsername() string
	BasicAuthPassword() string
}

Vault is the central singleton representing Hashicorp Vault.

We use Vault to obtain sensitive configuration values, called "secrets".

Jump to

Keyboard shortcuts

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