repo

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemoteName = "origin"

	// Username for LekkoApp bot.
	LekkoAppUser = "lekko-app[bot]"
)

Variables

View Source
var (
	ErrMissingCredentials = fmt.Errorf("missing credentials")
	ErrNotFound           = fmt.Errorf("not found")
)
View Source
var (
	ErrInvalidName = errors.New("invalid name")
)
View Source
var ErrRemoteHasChanges = errors.New("Remote repository has new changes, " +
	fmt.Sprintf("please run %s to merge them locally and try again.", logging.Bold("lekko pull")))

Functions

func DefaultRepoBasePath added in v0.3.18

func DefaultRepoBasePath() (string, error)

func GenBranchName added in v0.2.7

func GenBranchName(ghUsername string) (string, error)

Generates a branch name based on the given github username, or if not available, the github username stored in git config.

func GetCoauthorInformation added in v0.3.8

func GetCoauthorInformation(commitMessage string) (string, string)

Returns the coauthor name and email based on the long git commit message. e.g. `Co-authored-by: <coauthor_name> <coauthor_email>`. TODO: Consider if we want to properly handle multiple coauthors.

func GetCommitSignature added in v0.3.2

func GetCommitSignature(ctx context.Context, ap AuthProvider, lekkoUser string) (*object.Signature, error)

GetCommitSignature returns the commit signature for the provided credentials. It tries to use the name and email associated with the user's GitHub account. If the name or email is not available, it tries to fetch the email separately. It uses GitHub's noreply email as a fallback. If GitHub creds aren't available, use lekko username. This applies to users that don't have a GitHub account.

func GetGitRootPath added in v0.3.25

func GetGitRootPath() (string, error)

func GetRepoPath added in v0.3.26

func GetRepoPath(dot *dotlekko.DotLekko) (string, error)

func GitAuthForRemote added in v0.3.23

func GitAuthForRemote(r *git.Repository, remoteName string, ap AuthProvider) (transport.AuthMethod, error)

func GitAuthForURL added in v0.3.23

func GitAuthForURL(url string, ap AuthProvider) transport.AuthMethod

func GitPull added in v0.3.22

func GitPull(r *git.Repository, rs secrets.ReadSecrets) error

TODO: consolidate with pkg/repo/repo.go

func InitIfNotExists added in v0.3.15

func InitIfNotExists(repoPath string) (string, error)

func MirrorAtURL added in v0.2.28

func MirrorAtURL(ctx context.Context, ap AuthProvider, url string) error

Mirrors the template config repo at the provided url. Note: a repository must already exist at the given url.

func PrepareGithubRepo added in v0.3.25

func PrepareGithubRepo() (string, error)

func ResetAndClean added in v0.3.22

func ResetAndClean(gitRepo *git.Repository) error

Types

type AuthProvider

type AuthProvider interface {
	GetUsername() string
	GetToken() string
}

AuthProvider provides access to basic auth credentials. Depending on the context (local vs ephemeral), credentials may be provided in different ways, thus the interface.

type Author added in v0.3.8

type Author struct {
	Name  string
	Email string
}

type CompileRequest

type CompileRequest struct {
	// Registry of protobuf types. This field is optional, if it does not exist, it will be instantiated.
	Registry *protoregistry.Types
	// Optional fields to filter features by, so as to not compile the entire world.
	NamespaceFilter, FeatureFilter string
	// Whether or not to persist the successfully compiled features
	DryRun bool
	// If true, any generated compilation changes will overwrite previous features
	// even if there are type mismatches
	IgnoreBackwardsCompatibility bool
	// If true, we will verify the structure of all feature files, ensuring that each
	// .star file has the relevant generated json and proto files, and all relevant compliance
	// checks are run. This should be false if we've just added a new .star file and are
	// compiling it for the first time.
	Verify bool
	// If true, and if a version later than the existing namespace version exists,
	// we will compile the requested feature(s) to the latest version.
	// Note: if upgrading, no feature filter is allowed to be specified.
	// That is because you must upgrade an entire namespace at a time.
	Upgrade bool
	// Enable verbose logging output
	Verbose bool
}

func (CompileRequest) Validate added in v0.2.8

func (cr CompileRequest) Validate() error

type ConfigurationRepository added in v0.2.7

type ConfigurationRepository interface {
	// Provides CRUD functionality on Lekko configuration stored anywhere
	ConfigurationStore
	// Allows interacting with git
	GitRepository
	// Allows interacting with a git provider, e.g. GitHub
	GitProvider
	// Allows writing logs to configurable destinations
	Logger
	// Underlying filesystem interfaces
	fs.Provider
	fs.ConfigWriter

	// Returns the history of changes made on the repository. Items can also be filtered to config.
	// Offset (0-based) and maxLen are required to limit the number of history items returned.
	GetHistory(ctx context.Context, namespace, configName string, offset, maxLen int32) ([]*HistoryItem, error)
}

ConfigurationRepository provides read and write access to Lekko configuration stored in a git repository.

func NewEphemeral

func NewEphemeral(url string, auth AuthProvider, branchName *string) (ConfigurationRepository, error)

Creates a new instance of Repo designed to work with ephemeral repos.

func NewLocal

func NewLocal(path string, auth AuthProvider) (ConfigurationRepository, error)

Creates a new instance of Repo designed to work with filesystem-based repos.

func NewLocalClone

func NewLocalClone(path, url string, auth AuthProvider) (ConfigurationRepository, error)

Creates a local clone of a remote github config repository based on the given url at the provided path.

type ConfigurationStore added in v0.2.7

type ConfigurationStore interface {
	Compile(ctx context.Context, req *CompileRequest) ([]*FeatureCompilationResult, error)
	Verify(ctx context.Context, req *VerifyRequest) error
	BuildDynamicTypeRegistry(ctx context.Context, protoDirPath string) (*protoregistry.Types, error)
	ReBuildDynamicTypeRegistry(ctx context.Context, protoDirPath string, useExternalTypes bool) (*protoregistry.Types, error)
	GetFileDescriptorSet(ctx context.Context, protoDirPath string) (*descriptorpb.FileDescriptorSet, error)
	Format(ctx context.Context, verbose bool) error
	AddFeature(ctx context.Context, ns, featureName string, fType eval.ConfigType, protoMessageName string, defaultValue interface{}) (string, error)
	BuildProtoStarInputs(ctx context.Context, messageName string, nv feature.NamespaceVersion) (*star.ProtoStarInputs, error)
	BuildProtoStarInputsWithTypes(ctx context.Context, messageName string, nv feature.NamespaceVersion, types *protoregistry.Types) (*star.ProtoStarInputs, error)
	RemoveFeature(ctx context.Context, ns, featureName string) error
	AddNamespace(ctx context.Context, name string) error
	RemoveNamespace(ctx context.Context, ns string) error
	Eval(ctx context.Context, ns, featureName string, featureCtx map[string]interface{}) (*anypb.Any, eval.ConfigType, eval.ResultPath, error)
	Parse(ctx context.Context, ns, featureName string, registry *protoregistry.Types) (*featurev1beta1.StaticFeature, error)
	GetContents(ctx context.Context) (map[metadata.NamespaceConfigRepoMetadata][]feature.FeatureFile, error)
	ListNamespaces(ctx context.Context) ([]*metadata.NamespaceConfigRepoMetadata, error)
	GetFeatureFiles(ctx context.Context, namespace string) ([]feature.FeatureFile, error)
	GetFeatureFile(ctx context.Context, namespace, featureName string) (*feature.FeatureFile, error)
	GetFeatureContents(ctx context.Context, namespace, featureName string) (*feature.FeatureContents, error)
	GetFeatureHash(ctx context.Context, namespace, featureName string) (*plumbing.Hash, error)
	GetProtoMessages(ctx context.Context) ([]string, error)
	ParseMetadata(ctx context.Context) (*metadata.RootConfigRepoMetadata, map[string]*metadata.NamespaceConfigRepoMetadata, error)
	RestoreWorkingDirectory(hash string) error
}

Provides functionality needed for accessing and making changes to Lekko configuration. This interface should make no assumptions about where the configuration is stored.

type FeatureCompilationResult

type FeatureCompilationResult struct {
	NamespaceName         string
	FeatureName           string
	NamespaceVersion      feature.NamespaceVersion
	CompiledFeature       *feature.CompiledFeature
	CompilationError      error
	CompilationDiffExists bool
	FormattingDiffExists  bool
	PersistenceError      error
}

func (*FeatureCompilationResult) CompilationErrorString added in v0.2.21

func (fcr *FeatureCompilationResult) CompilationErrorString(r Logger)

func (*FeatureCompilationResult) Err

func (fcr *FeatureCompilationResult) Err() error

func (*FeatureCompilationResult) Summary added in v0.2.21

func (fcr *FeatureCompilationResult) Summary(r Logger) []string

type FeatureCompilationResults

type FeatureCompilationResults []*FeatureCompilationResult

func (FeatureCompilationResults) Err

func (fcrs FeatureCompilationResults) Err() error

func (FeatureCompilationResults) RenderSummary added in v0.2.21

func (fcrs FeatureCompilationResults) RenderSummary(r Logger)

type GitProvider added in v0.2.7

type GitProvider interface {
	Review(ctx context.Context, title string, ghCli *gh.GithubClient, ap AuthProvider) (string, error)
	Merge(ctx context.Context, prNum *int, ghCli *gh.GithubClient, ap AuthProvider) error
}

Allows interacting with an underlying git provider, like GitHub. This interface provides tools to create code reviews and merge them. TODO: generalize the arguments to this interface so that we're not just tied to github.

type GitRepository added in v0.2.7

type GitRepository interface {
	// Checks out the branch at origin/${branchName}. The remote branch must exist.
	CheckoutRemoteBranch(branchName string) error
	// Checks out the given sha. Sha must exist on the local
	// git repository (i.e. we shouldn't have to consult the remote
	// repo to check it out).
	CheckoutLocalHash(sha string) error
	// Returns the url of the remote that the local repository is set up to track.
	GetRemoteURL() (string, error)
	// Commit will take an optional commit message and push the changes in the
	// local working directory to the remote branch.
	Commit(ctx context.Context, ap AuthProvider, message string, signature *object.Signature, coauthors ...*object.Signature) (string, error)
	// Cleans up all resources and references associated with the given branch on
	// local and remote, if they exist. If branchName is nil, uses the current
	// (non-master) branch. Will switch the current branch back to the default, and
	// pull from remote to ensure we are on the latest commit.
	Cleanup(ctx context.Context, branchName *string, ap AuthProvider) error
	// Pull the latest changes from the given branch name.
	Pull(ctx context.Context, ap AuthProvider, branchName string) error
	// Returns the hash of the current commit that HEAD is pointing to.
	Hash() (string, error)
	BranchName() (string, error)
	IsClean() (bool, error)
	// Creates new remote branch config at the given sha, and checks out the
	// new branch locally. branchName must be sufficiently unique.
	NewRemoteBranch(branchName string) error
	Read(path string) ([]byte, error)
	Status() (git.Status, error)
	HeadCommit() (*object.Commit, error)
	DefaultBranchName() string
	// contains filtered or unexported methods
}

Provides functionality for interacting with git.

type HistoryItem added in v0.3.8

type HistoryItem struct {
	Description    string
	Author         Author
	CoAuthors      []Author
	ConfigContents map[string][]string // Map of namespaces to changed configs (added or updated)
	CommitSHA      string
	Timestamp      time.Time
}

type Logger added in v0.2.16

type Logger interface {
	Logf(format string, a ...any)
	// Allows configuring the logger by temporarily overriding the
	// current logging configuration. Prior configuration is restored
	// by calling clear().
	ConfigureLogger(c *LoggingConfiguration) (clear func())
	// If colors are supported (e.g. in Bash), the methods below will customize
	// variables to be printed with the specified formatting applied.
	Bold(v interface{}) string
	Red(v interface{}) string
	Green(v interface{}) string
	Yellow(v interface{}) string
	Writer() io.Writer
}

Allows customizing how the we log print statements and where we log them to.

type LoggingConfiguration added in v0.2.16

type LoggingConfiguration struct {
	Writer         io.Writer
	ColorsDisabled bool
}

type RepoCmd added in v0.2.1

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

Responsible for all repository management actions on the command line. e.g. create/delete/list repos.

func NewRepoCmd added in v0.2.1

func (*RepoCmd) Create added in v0.2.1

func (r *RepoCmd) Create(ctx context.Context, owner, repo, description string) (string, error)

func (*RepoCmd) Delete added in v0.2.1

func (r *RepoCmd) Delete(ctx context.Context, owner, repo string, deleteOnRemote bool) error

func (*RepoCmd) Import added in v0.3.10

func (r *RepoCmd) Import(ctx context.Context, repoPath, owner, repoName, description string) error

func (*RepoCmd) List added in v0.2.1

func (r *RepoCmd) List(ctx context.Context) ([]*Repository, error)

type Repository added in v0.2.1

type Repository struct {
	Owner       string
	RepoName    string
	Description string
	URL         string
}

type VerifyRequest added in v0.2.28

type VerifyRequest struct {
	// Registry of protobuf types. This field is optional, if it does not exist, it will be instantiated.
	Registry *protoregistry.Types
	// Optional fields to filter features by, so as to not verify the entire world.
	NamespaceFilter, FeatureFilter string
}

Jump to

Keyboard shortcuts

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