configurations

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ApplicationConfigurationName = "application.codefly.yaml"
	ApplicationKind              = "application"
)
View Source
const (
	PluginService = "service"
	PluginLibrary = "library"
)
View Source
const (
	PluginRuntimeService = "runtime::service"
	PluginFactoryService = "factory::service"
)
View Source
const (
	Unknown = "unknown"
	Grpc    = "grpc"
	Rest    = "rest"
	Tcp     = "tcp"
)
View Source
const EndpointPrefix = "CODEFLY_ENDPOINT__"
View Source
const GlobalConfigurationName = "codefly.yaml"
View Source
const PluginConfigurationName = "plugin.codefly.yaml"
View Source
const PluginProvider = "provider"
View Source
const ProjectConfigurationName = "project.codefly.yaml"
View Source
const ProviderConfigurationName = "provider.codefly.yaml"
View Source
const RestRoutePrefix = "CODEFLY-RESTROUTE_"
View Source
const ServiceConfigurationName = "service.codefly.yaml"

Variables

This section is empty.

Functions

func AsEndpointEnvironmentVariable added in v0.0.13

func AsEndpointEnvironmentVariable(app string, service string, endpoint *Endpoint, addresses []string) string

func AsEndpointEnvironmentVariableKey added in v0.0.13

func AsEndpointEnvironmentVariableKey(app string, service string, endpoint *Endpoint) string

func ExistsAtDir

func ExistsAtDir[C Configuration](dir string) bool

func ExtendDomain

func ExtendDomain(domain string, extension string) string

func FindUp

func FindUp[C Configuration](cur string) (*C, error)

FindUp looks for a service configuration in the current directory and up

func GlobalConfigurationDir

func GlobalConfigurationDir() string

func GlobalProjectRoot

func GlobalProjectRoot() string

func HomeDir

func HomeDir() string

func InitGlobal

func InitGlobal(getter GlobalConfigurationInputer, override Override)

InitGlobal initializes the global configuration of codefly GlobalConfigurationInputer: setup the configuration and defaults Override: policy to replace existing configuration

func KnownPluginImplementationKinds

func KnownPluginImplementationKinds() []string

func KnownProjects

func KnownProjects() []string

func LoadFromBytes added in v0.0.13

func LoadFromBytes[C Configuration](content []byte) (*C, error)

func LoadFromDir

func LoadFromDir[C Configuration](dir string) (*C, error)

func LoadFromPath

func LoadFromPath[C Configuration](p string) (*C, error)

func LoadGlobalConfiguration

func LoadGlobalConfiguration()

func LoadSpec

func LoadSpec(content []byte, obj any, override shared.BaseLogger) error

func OverrideWorkspaceConfigDir

func OverrideWorkspaceConfigDir(dir string)

func OverrideWorkspaceProjectRoot

func OverrideWorkspaceProjectRoot(dir string)

func ParseEndpointEnvironmentVariableKey added in v0.0.13

func ParseEndpointEnvironmentVariableKey(key string) (string, error)

func ParseRestRouteEnvironmentVariable added in v0.0.13

func ParseRestRouteEnvironmentVariable(env string) (string, []string)

func Path

func Path[C Configuration](dir string) string

func ProjectPath

func ProjectPath(relativePath string) string

func RelativeProjectPath

func RelativeProjectPath(p string) string

func Reset

func Reset()

func RestRouteAsEnvironmentVariable added in v0.0.13

func RestRouteAsEnvironmentVariable(reference string, addresses []string) string

func SaveCurrent

func SaveCurrent()

func SaveToDir

func SaveToDir[C Configuration](c *C, dir string) error

func SerializeAddresses

func SerializeAddresses(addresses []string) string

func SerializeSpec

func SerializeSpec(spec any) ([]byte, error)

func SetCurrentApplication

func SetCurrentApplication(app *Application)

func SetCurrentProject

func SetCurrentProject(p *Project)

func SolveDir

func SolveDir(dir string) string

func SolveDirOrCreate

func SolveDirOrCreate(dir string) string

func SupportedApi

func SupportedApi(kind string) error

func TypeName

func TypeName[C Configuration]() string

func ValidateDomain

func ValidateDomain()

func ValidateOrganization

func ValidateOrganization(org string) error

func ValidateProjectName

func ValidateProjectName(name string) error

func ValidateServiceName

func ValidateServiceName(name string) error

Types

type Application

type Application struct {
	Kind         string `yaml:"kind"`
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path"`
	Project      string `yaml:"project"`
	Domain       string `yaml:"domain"`

	Services []*ServiceReference `yaml:"services"`
}

func ApplicationConfiguration added in v0.0.13

func ApplicationConfiguration(current bool) (*Application, error)

func CurrentApplication

func CurrentApplication(opts ...Option) (*Application, error)

func FindApplicationUp

func FindApplicationUp(p string) (*Application, error)

func ListApplications

func ListApplications(opts ...Option) ([]*Application, error)

func LoadApplicationFromDir

func LoadApplicationFromDir(dir string) (*Application, error)

func LoadApplicationFromName

func LoadApplicationFromName(name string, opts ...Option) (*Application, error)

func MustCurrentApplication

func MustCurrentApplication() *Application

func NewApplication

func NewApplication(name string) (*Application, error)

func (*Application) AddService

func (app *Application) AddService(service *Service) error

func (*Application) Dir

func (app *Application) Dir(opts ...Option) string

func (*Application) GetServiceReferences

func (app *Application) GetServiceReferences(name string) (*ServiceReference, error)

func (*Application) LoadServiceFromName added in v0.0.13

func (app *Application) LoadServiceFromName(name string) (*Service, error)

func (*Application) Relative

func (app *Application) Relative(absolute string, opts ...Option) string

func (*Application) Save

func (app *Application) Save() error

func (*Application) ServiceDomain

func (app *Application) ServiceDomain(name string) string

type ApplicationReference added in v0.0.9

type ApplicationReference struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path,omitempty"`
}

An ApplicationReference

type ApplicationRestRoute added in v0.0.13

type ApplicationRestRoute struct {
	ServiceRestRoutes []*ServiceRestRoute
	Name              string
}

func (*ApplicationRestRoute) Save added in v0.0.13

func (r *ApplicationRestRoute) Save(ctx context.Context, dir string) error

Save as folder structure

type ClientEntry

type ClientEntry struct {
	Name string   `yaml:"name"`
	Apis []string `yaml:"apis"`
}

func (*ClientEntry) Validate

func (c *ClientEntry) Validate() error

type Configuration

type Configuration interface{}

type Endpoint

type Endpoint struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description,omitempty"`
	Public      bool   `yaml:"public,omitempty"`
	Api         string `yaml:"api,omitempty"`
	// FailOver indicates that this endpoint should fail over to another endpoint
	FailOver *Endpoint `yaml:"fail-over,omitempty"`
}

func (*Endpoint) Unique added in v0.0.13

func (e *Endpoint) Unique(app string, service string) string

type EndpointInstance added in v0.0.13

type EndpointInstance struct {
	Unique    string
	Addresses []string
}

func ParseEndpointEnvironmentVariable added in v0.0.13

func ParseEndpointEnvironmentVariable(env string) (*EndpointInstance, error)

type EndpointReference added in v0.0.9

type EndpointReference struct {
	Name string `yaml:"name"`
}

A EndpointReference

type ExtendedRestRoute added in v0.0.13

type ExtendedRestRoute[T any] struct {
	RestRoute `yaml:",inline"`

	Extension T `yaml:"extension"`
}

func LoadApplicationExtendedRoutes added in v0.0.13

func LoadApplicationExtendedRoutes[T any](dir string, logger shared.BaseLogger) ([]*ExtendedRestRoute[T], error)

func LoadExtendedRestRoute added in v0.0.13

func LoadExtendedRestRoute[T any](p string, app string, service string) (*ExtendedRestRoute[T], error)

func LoadExtendedRoutes added in v0.0.13

func LoadExtendedRoutes[T any](dir string, app string, service string) ([]*ExtendedRestRoute[T], error)

func LoadServiceExtendedRoutes added in v0.0.13

func LoadServiceExtendedRoutes[T any](dir string, app string) ([]*ExtendedRestRoute[T], error)

func NewExtendedRestRoute added in v0.0.13

func NewExtendedRestRoute[T any](rest RestRoute, value T) *ExtendedRestRoute[T]

type GlobalConfigurationInputer

type GlobalConfigurationInputer interface {
	// Fetch instantiates the input
	Fetch() error
	// Organization is now global
	Organization() string
	// Domain associated with the organization
	Domain() string
	// CreateDefaultProject returns true if a default project should be created
	CreateDefaultProject() bool
	// ProjectBuilder abstracts away the configuration of Project creation
	ProjectBuilder() ProjectBuilder
}

A GlobalConfigurationInputer abstracts away global configuration and default of project creation

type HttpMethod added in v0.0.13

type HttpMethod string
const (
	HttpMethodGet     HttpMethod = "GET"
	HttpMethodPut     HttpMethod = "PUT"
	HttpMethodPost    HttpMethod = "POST"
	HttpMethodDelete  HttpMethod = "DELETE"
	HttpMethodPatch   HttpMethod = "PATCH"
	HttpMethodOptions HttpMethod = "OPTIONS"
	HttpMethodHead    HttpMethod = "HEAD"
)

type NoApplicationError

type NoApplicationError struct {
	Project string
}

func (NoApplicationError) Error

func (e NoApplicationError) Error() string

type Option

type Option func(scope *Scope)

func WithApplication

func WithApplication(app *Application) Option

func WithProject

func WithProject(project *Project) Option

type Override

type Override interface {
	Override(p string) bool
}

type Partial added in v0.0.13

type Partial struct {
	Name string `yaml:"name"`

	// Applications in the partial of the project
	Applications []string `yaml:"applications"`
}

type Plugin

type Plugin struct {
	Kind       string `yaml:"kind"`
	Identifier string `yaml:"name"`
	Version    string `yaml:"version"`
	Publisher  string `yaml:"publisher"`
}

func LoadPluginConfiguration added in v0.0.13

func LoadPluginConfiguration(fs shared.FileSystem) Plugin

func LoadPluginConfigurationFromReader added in v0.0.13

func LoadPluginConfigurationFromReader(fs shared.FSReader) Plugin

func NewPlugin

func NewPlugin(kind string, publisher string, identifier string, version string) *Plugin

func ParsePlugin

func ParsePlugin(kind string, s string) (*Plugin, error)

func (*Plugin) ImplementationKind

func (p *Plugin) ImplementationKind() string

func (*Plugin) Key

func (p *Plugin) Key(f string, unique string) string

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Of

func (p *Plugin) Of(kind string) *Plugin

func (*Plugin) Patch added in v0.0.13

func (p *Plugin) Patch() (*Plugin, error)

func (*Plugin) Path

func (p *Plugin) Path() (string, error)

func (*Plugin) Unique

func (p *Plugin) Unique() string

func (*Plugin) Validate

func (p *Plugin) Validate()

type Project

type Project struct {
	Name         string       `yaml:"name"`
	Style        ProjectStyle `yaml:"style"`
	Domain       string       `yaml:"domain"`
	Organization string       `yaml:"organization"`
	RelativePath string       `yaml:"relative-path,omitempty"`

	// Applications in the project
	Applications       []*ApplicationReference `yaml:"applications"`
	CurrentApplication string                  `yaml:"current-application,omitempty"`

	// Partials are convenient way to run several applications
	Partials []Partial `yaml:"partials"`

	// Providers in the project
	Providers []ProviderReference `yaml:"providers"`
}

func CurrentProject

func CurrentProject() (*Project, error)

func ListProjects

func ListProjects() ([]*Project, error)

func LoadCurrentProject

func LoadCurrentProject() (*Project, error)

func LoadProjectFromDir

func LoadProjectFromDir(dir string) (*Project, error)

func LoadProjectFromName

func LoadProjectFromName(name string) (*Project, error)

func MustCurrentProject

func MustCurrentProject() *Project

func NewProject

func NewProject(name string) (*Project, error)

func ProjectConfiguration added in v0.0.13

func ProjectConfiguration(current bool) (*Project, error)

func (*Project) AddApplication added in v0.0.9

func (project *Project) AddApplication(app *ApplicationReference) error

func (*Project) AddPartial added in v0.0.13

func (project *Project) AddPartial(partial Partial) error

func (*Project) AddProvider added in v0.0.9

func (project *Project) AddProvider(provider *Provider) error

func (*Project) ApplicationByName added in v0.0.13

func (project *Project) ApplicationByName(override string) (*Application, error)

func (*Project) Dir

func (project *Project) Dir() string

func (*Project) GetPartial added in v0.0.13

func (project *Project) GetPartial(name string) (*Partial, error)

func (*Project) GetService

func (project *Project) GetService(name string) (*Service, error)

func (*Project) ListApplications added in v0.0.13

func (project *Project) ListApplications() ([]*Application, error)

func (*Project) ListServices

func (project *Project) ListServices() ([]*ServiceReference, error)

func (*Project) LoadApplicationFromReference added in v0.0.13

func (project *Project) LoadApplicationFromReference(ref *ApplicationReference) (*Application, error)

func (*Project) OtherApplications added in v0.0.9

func (project *Project) OtherApplications(app *Application) ([]*Application, error)

func (*Project) Relative

func (project *Project) Relative(absolute string) string

func (*Project) Save

func (project *Project) Save() error

func (*Project) SaveToDir

func (project *Project) SaveToDir(dir string) error

func (*Project) Unique

func (project *Project) Unique() string

type ProjectBuilder

type ProjectBuilder interface {
	ProjectName() string
	RelativePath() string
	Fetch() error
	Style() ProjectStyle
}

type ProjectInput

type ProjectInput struct {
	Name string
}

func (*ProjectInput) Fetch

func (p *ProjectInput) Fetch() error

func (*ProjectInput) ProjectDir

func (p *ProjectInput) ProjectDir() string

func (*ProjectInput) ProjectName

func (p *ProjectInput) ProjectName() string

func (*ProjectInput) RelativePath

func (p *ProjectInput) RelativePath() string

func (*ProjectInput) Style

func (p *ProjectInput) Style() ProjectStyle

type ProjectReference

type ProjectReference struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path,omitempty"`
}

ProjectReference is a reference to a project used by Workspace configuration

func FindProjectReference

func FindProjectReference(name string) (*ProjectReference, error)

type ProjectStyle

type ProjectStyle string
const (
	ProjectStyleUnknown   ProjectStyle = "unknown"
	ProjectStyleMonorepo  ProjectStyle = "monorepo"
	ProjectStyleMultirepo ProjectStyle = "multirepo"
)

func NewStyle

func NewStyle(style string) ProjectStyle

type Provider added in v0.0.9

type Provider struct {
	Kind   string  `yaml:"kind"`
	Name   string  `yaml:"name"`
	Plugin *Plugin `yaml:"plugin"`
}

func NewProvider added in v0.0.9

func NewProvider(name string, plugin *Plugin) (*Provider, error)

func (*Provider) Reference added in v0.0.9

func (p *Provider) Reference() (*ProviderReference, error)

type ProviderReference added in v0.0.9

type ProviderReference struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path,omitempty"`
}

A ProviderReference

type RestRoute added in v0.0.13

type RestRoute struct {
	Path        string
	Methods     []HttpMethod
	Application string `yaml:"-"`
	Service     string `yaml:"-"`
}

func LoadApplicationRoutes added in v0.0.13

func LoadApplicationRoutes(dir string) ([]*RestRoute, error)

func LoadRoute added in v0.0.13

func LoadRoute(p string, app string, service string) (*RestRoute, error)

func LoadRoutes added in v0.0.13

func LoadRoutes(dir string, app string, service string) ([]*RestRoute, error)

func LoadServiceRoutes added in v0.0.13

func LoadServiceRoutes(dir string, app string) ([]*RestRoute, error)

func UnwrapRoutes added in v0.0.13

func UnwrapRoutes[T any](routes []*ExtendedRestRoute[T]) []*RestRoute

func (*RestRoute) Save added in v0.0.13

func (r *RestRoute) Save(ctx context.Context, dir string) error

Save a route: The path is inferred from the configuration application

 service
	path.codefly.route.yaml

func (*RestRoute) String added in v0.0.13

func (r *RestRoute) String() string

type RunningOptions

type RunningOptions struct {
	Replicas    int  `yaml:"replicas,omitempty"`
	Quiet       bool `yaml:"quiet,omitempty"`
	Persistence bool `yaml:"persistence,omitempty"`
}

RunningOptions of the ServiceReference can tweak running behavior of service Note: this is not a part of the Service configuration but part of the Application running

type Scope

type Scope struct {
	Project     *Project
	Application *Application
}

func WithScope

func WithScope(opts ...Option) *Scope

func WithScopeProjectOnly added in v0.0.9

func WithScopeProjectOnly(opts ...Option) *Scope

func (*Scope) WithApplication

func (s *Scope) WithApplication(app *Application) *Scope

func (*Scope) WithProject added in v0.0.9

func (s *Scope) WithProject(project *Project) *Scope

type Service

type Service struct {
	Kind         string               `yaml:"kind"`
	Name         string               `yaml:"name"`
	Version      string               `yaml:"version"`
	Application  string               `yaml:"application"`
	RelativePath string               `yaml:"relative-path,omitempty"`
	Namespace    string               `yaml:"namespace"`
	Domain       string               `yaml:"domain"`
	Plugin       *Plugin              `yaml:"plugin"`
	Dependencies []*ServiceDependency `yaml:"dependencies"`
	Endpoints    []*Endpoint          `yaml:"endpoints"`
	Spec         map[string]any       `yaml:"spec"`
}

A Service

Convention: RelativePath from Application

func FindServiceFromReference added in v0.0.13

func FindServiceFromReference(ref *ServiceReference) (*Service, error)

func LoadService

func LoadService(input string) (*Service, error)

func LoadServiceFromDir

func LoadServiceFromDir(dir string, opts ...Option) (*Service, error)

func LoadServiceFromReference

func LoadServiceFromReference(ref *ServiceReference, opts ...Option) (*Service, error)

func LoadServicesFromInput

func LoadServicesFromInput(inputs ...string) ([]*Service, error)

LoadServicesFromInput from string inputs

func NewService

func NewService(name string, namespace string, plugin *Plugin, ops ...Option) (*Service, error)

func (*Service) AddDependencyReference

func (s *Service) AddDependencyReference(requirement *Service) error

AddDependencyReference adds a dependency to the service

func (*Service) AddSpec

func (s *Service) AddSpec(spec any) error

func (*Service) Dir

func (s *Service) Dir(opts ...Option) string

func (*Service) Duplicate

func (s *Service) Duplicate(name string) *Service

func (*Service) Endpoint

func (s *Service) Endpoint() string

func (*Service) Reference

func (s *Service) Reference() (*ServiceReference, error)

func (*Service) Save

func (s *Service) Save() error

func (*Service) SaveAtDir

func (s *Service) SaveAtDir(destination string) error

func (*Service) Unique

func (s *Service) Unique() string

Unique identifies a service within a project We use a REST like convention rather then a sub-domain one

type ServiceDependency

type ServiceDependency struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path,omitempty"`
	// Null application means self
	Application string `yaml:"application,omitempty"`

	Endpoints []*EndpointReference `yaml:"endpoints,omitempty"`
}

func (*ServiceDependency) AsReference

func (s *ServiceDependency) AsReference() *ServiceReference

func (*ServiceDependency) String added in v0.0.13

func (s *ServiceDependency) String() string

func (*ServiceDependency) Unique added in v0.0.13

func (s *ServiceDependency) Unique() string

func (*ServiceDependency) Validate

func (s *ServiceDependency) Validate() error

type ServiceIdentity

type ServiceIdentity struct {
	Name        string
	Application string
	Namespace   string
	Domain      string
}

ServiceIdentity defines exactly the scope of the service Name: the name of the service It will be unique within an application Application: the name of the application the service belongs to Recall that application names are unique within a project This is a logical partitioning Namespace: the namespace the service belongs to This is a resource partitioning Domain: the domain of the service belongs to This is a responsibility partitioning

func Identity

func Identity(conf *Service) *ServiceIdentity

type ServiceReference

type ServiceReference struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path,omitempty"`
	Application  string `yaml:"application,omitempty"`

	RunningOptions RunningOptions `yaml:"options,omitempty"`
}

ServiceReference is a reference to a service used by Application configuration

func ParseServiceInput

func ParseServiceInput(input string) (*ServiceReference, error)

func (*ServiceReference) CreateReplicas

func (ref *ServiceReference) CreateReplicas() []string

func (*ServiceReference) Dir

func (ref *ServiceReference) Dir(opts ...Option) (string, error)

func (*ServiceReference) Validate

func (ref *ServiceReference) Validate() error

type ServiceRestRoute added in v0.0.13

type ServiceRestRoute struct {
	Routes      []*RestRoute
	Name        string
	Application string `yaml:"-"`
}

func (*ServiceRestRoute) Save added in v0.0.13

func (r *ServiceRestRoute) Save(ctx context.Context, dir string) error

type Workspace

type Workspace struct {
	Organization string `yaml:"organization"`
	Domain       string `yaml:"domain"`

	// Projects in the global configuration
	Projects       []*ProjectReference `yaml:"projects"`
	CurrentProject string              `yaml:"current-project,omitempty"`

	// Internal
	FullDir string `yaml:"-"`
}

Workspace configuration for codefly CLI

func Current

func Current() (*Workspace, error)

Current returns the current global configuration

func MustCurrent

func MustCurrent() *Workspace

MustCurrent returns the current global configuration

func (*Workspace) Dir

func (g *Workspace) Dir() string

Dir returns the absolute path to the global configuration directory

func (*Workspace) Relative

func (g *Workspace) Relative(dir string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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