repo

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MainBranchName = "main"
	RemoteName     = "origin"
)

Variables

View Source
var (
	ErrMissingCredentials = fmt.Errorf("missing credentials")
	ErrNotFound           = fmt.Errorf("not found")
)
View Source
var (
	ErrInvalidName = errors.New("invalid name")
)

Functions

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.

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 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
	Persist 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
}

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
	// Underlying filesystem interfaces
	fs.Provider
	fs.ConfigWriter
}

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 {
	CompileFeature(ctx context.Context, registry *protoregistry.Types, namespace, featureName string) (*feature.CompiledFeature, error)
	PersistFeature(ctx context.Context, registry *protoregistry.Types, namespace string, f *feature.Feature, force bool) error
	Compile(ctx context.Context, req *CompileRequest) ([]*FeatureCompilationResult, error)
	FindFeatureFiles(ctx context.Context, namespaceFilter, featureFilter string, verify bool) ([]*feature.FeatureFile, int, error)
	BuildDynamicTypeRegistry(ctx context.Context, protoDirPath string) (*protoregistry.Types, error)
	ReBuildDynamicTypeRegistry(ctx context.Context, protoDirPath string) (*protoregistry.Types, error)
	Format(ctx context.Context) error
	FormatFeature(ctx context.Context, ff feature.FeatureFile) error
	AddFeature(ctx context.Context, ns, featureName string, fType feature.FeatureType) (string, 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, iCtx map[string]interface{}) (*anypb.Any, feature.FeatureType, error)
	Parse(ctx context.Context, ns, featureName string) (*feature.Feature, 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)
	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
	CompiledFeature  *feature.CompiledFeature
	CompilationError error
}

func (*FeatureCompilationResult) Err

func (fcr *FeatureCompilationResult) Err() error

func (*FeatureCompilationResult) SummaryString

func (fcr *FeatureCompilationResult) SummaryString() string

type FeatureCompilationResults

type FeatureCompilationResults []*FeatureCompilationResult

func (FeatureCompilationResults) Err

func (fcrs FeatureCompilationResults) Err() error

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
	// 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) (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 main, 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 branch that HEAD is set up to track.
	Pull(ap AuthProvider) 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)
}

Provides functionality for interacting with git.

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 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) 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
}

Jump to

Keyboard shortcuts

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