core

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeService              = "service"
	NodeDevice               = "device"
	KeyServiceKind           = "kind"
	KeyDeviceName            = "name"
	PathTypeService PathType = NodeService
	PathTypeDevice  PathType = NodeDevice
)
View Source
const (
	ServiceKind = "services"
	DeviceKind  = "devices"
)

Variables

View Source
var UpdateCheckDuration = 5 * time.Second // TODO parameterize

Functions

func CheckGitFileIsStagedOrUnmodified

func CheckGitFileIsStagedOrUnmodified(path string, st extgogit.FileStatus) error

CheckGitFileIsStagedOrUnmodified checks the given file status is modified and staged, or unmodified.

func CheckGitFileStatus

func CheckGitFileStatus(path string, st extgogit.FileStatus) error

CheckGitFileStatus checks the given file status is in the proper status for service apply operation.

func CheckGitIsStagedOrUnmodified

func CheckGitIsStagedOrUnmodified(stmap extgogit.Status) error

CheckGitIsStagedOrUnmodified checks all tracked files are modified and staged, or unmodified.

func CheckGitStatus

func CheckGitStatus(stmap extgogit.Status) error

CheckGitStatus checks all git tracked files are in the proper status for service apply operation.

func CollectPartialDeviceConfig

func CollectPartialDeviceConfig(dir, device string) ([]string, error)

CollectPartialDeviceConfig returns list of partial device configs for the given device.

func ConvertMapKeyToString

func ConvertMapKeyToString(path string, in io.Reader, out io.Writer) error

ConvertMapKeyToString converts all go structs in the given go file to the structure supported by kuesta. It extracts go structs and converts all map keys to string if the go struct contains maps with non-string key.

func GetGNMIServiceVersion

func GetGNMIServiceVersion() (string, error)

GetGNMIServiceVersion returns a pointer to the gNMI service version string. The method is non-trivial because of the way it is defined in the proto file.

func HttpCapabilities added in v0.9.0

func HttpCapabilities(c echo.Context, path string) error

Capabilities responds the server capabilities containing the available services.

func HttpGet added in v0.9.0

func HttpGet(c echo.Context, rootpath string) error

Get responds the multiple service inputs requested by GetRequest.

func HttpSet added in v0.9.0

func HttpSet(c echo.Context, ctx context.Context, gogit *gogit.Git, scfg *ServeCfg) error

Set executes specified Replace/Update/Delete operations and responds what is done by SetRequest.

func MakeCommitMessage

func MakeCommitMessage(stmap extgogit.Status) string

MakeCommitMessage returns the commit message that shows the summary of service and device updates.

func MakeSyncCommitMessage

func MakeSyncCommitMessage(stmap git.Status) string

MakeSyncCommitMessage returns the commit message that shows the device actual config updates.

func RunCueGet

func RunCueGet(ctx context.Context, cfg *CueGetCfg) error

RunCueGet runs the main process of the `cue get` command.

func RunCueGetImpl

func RunCueGetImpl(ctx context.Context, path string, getter CueGetter) error

func RunDeviceAggregate

func RunDeviceAggregate(ctx context.Context, cfg *DeviceAggregateCfg) error

RunDeviceAggregate runs the main process of the `device aggregate` command.

func RunDeviceComposite

func RunDeviceComposite(ctx context.Context, cfg *DeviceCompositeCfg) error

RunDeviceComposite runs the main process of the `device composite` command.

func RunGitCommit

func RunGitCommit(ctx context.Context, cfg *GitCommitCfg) error

RunGitCommit runs the main process of the `git commit` command.

func RunServe

func RunServe(ctx context.Context, cfg *ServeCfg) error

func RunServeHttp added in v0.9.0

func RunServeHttp(ctx context.Context, cfg *ServeCfg) error

func RunServiceApply

func RunServiceApply(ctx context.Context, cfg *ServiceApplyCfg) error

RunServiceApply runs the main process of the `service apply` command.

func RunServiceCompile

func RunServiceCompile(ctx context.Context, cfg *ServiceCompileCfg) error

RunServiceCompile runs the main process of the `service compile` command.

func SetupGitRepoWithRemote

func SetupGitRepoWithRemote(t *testing.T, remote string) (*git.Repository, string, string)

func WithWriter

func WithWriter(parent context.Context, w io.Writer) context.Context

WithWriter sets io.Writer to context for outputting message from command.

func WriterFromContext

func WriterFromContext(ctx context.Context) io.Writer

WriterFromContext extract io.Writer from context.

Types

type CueGetCfg

type CueGetCfg struct {
	RootCfg

	FilePath string
}

func (*CueGetCfg) Mask

func (c *CueGetCfg) Mask() *CueGetCfg

Mask returns the copy whose sensitive data are masked.

func (*CueGetCfg) Validate

func (c *CueGetCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type CueGetFunc

type CueGetFunc func(modPath, outDir string) error

func (CueGetFunc) Exec

func (fn CueGetFunc) Exec(modPath, outDir string) error

type CueGetter

type CueGetter interface {
	Exec(modPath, outDir string) error
}

type DeviceAggregateCfg

type DeviceAggregateCfg struct {
	RootCfg

	Addr         string
	NoTLS        bool
	Insecure     bool
	TLSCrtPath   string
	TLSKeyPath   string
	TLSCACrtPath string
}

func (*DeviceAggregateCfg) Mask

Mask returns the copy whose sensitive data are masked.

func (*DeviceAggregateCfg) TLSServerConfig

func (c *DeviceAggregateCfg) TLSServerConfig() *credentials.TLSServerConfig

func (*DeviceAggregateCfg) Validate

func (c *DeviceAggregateCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type DeviceAggregateServer

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

DeviceAggregateServer runs saver loop and committer loop along with serving commit API to persist device config to git. Device config are written locally and added to git just after commit API call. Updated configs are aggregated and git-pushed as batch commit periodically.

func NewDeviceAggregateServer

func NewDeviceAggregateServer(cfg *DeviceAggregateCfg) *DeviceAggregateServer

NewDeviceAggregateServer creates new DeviceAggregateServer.

func (*DeviceAggregateServer) GitPushDeviceConfig

func (s *DeviceAggregateServer) GitPushDeviceConfig(ctx context.Context) error

GitPushDeviceConfig runs git-commit all unstaged device config updates as batch commit then git-push to remote origin.

func (*DeviceAggregateServer) HandleFunc

func (s *DeviceAggregateServer) HandleFunc(w http.ResponseWriter, r *http.Request)

HandleFunc handles API call to persist actual device config.

func (*DeviceAggregateServer) Run

func (*DeviceAggregateServer) SaveConfig

SaveConfig writes device config contained in supplied SaveConfigRequest.

type DeviceCompositeCfg

type DeviceCompositeCfg struct {
	RootCfg

	Device string `validate:"required"`
}

func (*DeviceCompositeCfg) Mask

Mask returns the copy whose sensitive data are masked.

func (*DeviceCompositeCfg) Validate

func (c *DeviceCompositeCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type DeviceCompositePlan

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

func NewDeviceCompositePlan

func NewDeviceCompositePlan(stmap extgogit.Status, root string) *DeviceCompositePlan

NewDeviceCompositePlan creates new DeviceCompositePlan from the given git file statuses.

func (*DeviceCompositePlan) Do

func (p *DeviceCompositePlan) Do(ctx context.Context, compositeFunc DeviceFunc) error

Do executes given composite DeviceFunc according to its execution plan.

func (*DeviceCompositePlan) IsEmpty

func (p *DeviceCompositePlan) IsEmpty() bool

IsEmpty returns True when there are no planned targets.

type DeviceFunc

type DeviceFunc func(ctx context.Context, sp kuesta.DevicePath) error

type DevicePathReq

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

func (DevicePathReq) Path

func (s DevicePathReq) Path() *kuesta.DevicePath

func (DevicePathReq) String

func (s DevicePathReq) String() string

func (DevicePathReq) Type

func (DevicePathReq) Type() PathType

type ErrConfigValue

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

func (*ErrConfigValue) Error

func (e *ErrConfigValue) Error() string

type GitCommitCfg

type GitCommitCfg struct {
	RootCfg
}

func (*GitCommitCfg) Mask

func (c *GitCommitCfg) Mask() *GitCommitCfg

Mask returns the copy whose sensitive data are masked.

func (*GitCommitCfg) Validate

func (c *GitCommitCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type GnmiPathConverter

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

func NewGnmiPathConverter

func NewGnmiPathConverter(cfg *ServeCfg) *GnmiPathConverter

func (*GnmiPathConverter) Convert

func (c *GnmiPathConverter) Convert(prefix, path *gnmi.Path) (PathReq, error)

Convert converts gNMI Path to PathReq.

type GnmiRequestHandler

type GnmiRequestHandler interface {
	Capabilities(ctx context.Context, req *pb.CapabilityRequest) (*pb.CapabilityResponse, error)
	Get(ctx context.Context, prefix, path *pb.Path) (*pb.Notification, error)
	Delete(ctx context.Context, prefix, path *pb.Path) (*pb.UpdateResult, error)
	Update(ctx context.Context, prefix, path *pb.Path, val *pb.TypedValue) (*pb.UpdateResult, error)
	Replace(ctx context.Context, prefix, path *pb.Path, val *pb.TypedValue) (*pb.UpdateResult, error)
}

type HttpGetBody added in v0.9.0

type HttpGetBody struct {
	Paths []string `json:"paths"`
}

type HttpSetBody added in v0.9.0

type HttpSetBody struct {
	Path  string                 `json:"path"`
	Value map[string]interface{} `json:"value"`
}

type HttpSetRes added in v0.9.0

type HttpSetRes struct {
	Before map[string]interface{} `json:"before"`
	After  map[string]interface{} `json:"after"`
}

type NorthboundServer

type NorthboundServer struct {
	pb.UnimplementedGNMIServer
	// contains filtered or unexported fields
}

func NewNorthboundServer

func NewNorthboundServer(cfg *ServeCfg) (*NorthboundServer, error)

NewNorthboundServer creates new NorthboundServer with supplied ServeCfg.

func NewNorthboundServerWithGit

func NewNorthboundServerWithGit(cfg *ServeCfg, cGit, sGit *gogit.Git) *NorthboundServer

func (*NorthboundServer) Capabilities

Capabilities responds the server capabilities containing the available services.

func (*NorthboundServer) Get

Get responds the multiple service inputs requested by GetRequest.

func (*NorthboundServer) RunConfigSyncLoop

func (s *NorthboundServer) RunConfigSyncLoop(ctx context.Context, dur time.Duration)

func (*NorthboundServer) RunStatusSyncLoop

func (s *NorthboundServer) RunStatusSyncLoop(ctx context.Context, dur time.Duration)

func (*NorthboundServer) Set

Set executes specified Replace/Update/Delete operations and responds what is done by SetRequest.

type NorthboundServerImpl

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

func NewNorthboundServerImpl

func NewNorthboundServerImpl(cfg *ServeCfg) *NorthboundServerImpl

func (*NorthboundServerImpl) Capabilities

Capabilities responds the server capabilities containing the available services.

func (*NorthboundServerImpl) Delete

func (s *NorthboundServerImpl) Delete(ctx context.Context, prefix, path *pb.Path) (*pb.UpdateResult, error)

Delete deletes the service input stored at the supplied path.

func (*NorthboundServerImpl) Get

func (s *NorthboundServerImpl) Get(ctx context.Context, prefix, path *pb.Path) (*pb.Notification, error)

Get returns the service input stored at the supplied path.

func (*NorthboundServerImpl) Replace

func (s *NorthboundServerImpl) Replace(ctx context.Context, prefix, path *pb.Path, val *pb.TypedValue) (*pb.UpdateResult, error)

Replace replaces the service input stored at the supplied path.

func (*NorthboundServerImpl) Update

func (s *NorthboundServerImpl) Update(ctx context.Context, prefix, path *pb.Path, val *pb.TypedValue) (*pb.UpdateResult, error)

Update updates the service input stored at the supplied path.

type PathReq

type PathReq interface {
	Type() PathType
	String() string
}

type PathType

type PathType string

type RootCfg

type RootCfg struct {
	Verbose        uint8 `validate:"min=0,max=3"`
	Devel          bool
	ConfigRootPath string
	StatusRootPath string
	ConfigRepoUrl  string
	StatusRepoUrl  string
	GitTrunk       string
	GitRemote      string
	GitToken       string
	GitUser        string
	GitEmail       string
	PushToMain     bool
}

func (*RootCfg) ConfigGitOptions

func (c *RootCfg) ConfigGitOptions() *gogit.GitOptions

func (*RootCfg) Mask

func (c *RootCfg) Mask() *RootCfg

Mask returns the copy whose sensitive data are masked.

func (*RootCfg) StatusGitOptions

func (c *RootCfg) StatusGitOptions() *gogit.GitOptions

func (*RootCfg) Validate

func (c *RootCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type SaveConfigRequest

type SaveConfigRequest struct {
	Device string  `json:"device" validate:"required"`
	Config *string `json:"config" validate:"required"`
}

func DecodeSaveConfigRequest

func DecodeSaveConfigRequest(r io.Reader) (*SaveConfigRequest, error)

DecodeSaveConfigRequest decodes supplied payload to SaveConfigRequest.

func (*SaveConfigRequest) Validate

func (r *SaveConfigRequest) Validate() error

type ServeCfg

type ServeCfg struct {
	RootCfg

	Addr            string `validate:"required"`
	HttpAddr        string
	SyncPeriod      int `validate:"required"`
	PersistGitState bool
	NoTLS           bool
	Insecure        bool
	TLSCrtPath      string
	TLSKeyPath      string
	TLSCACrtPath    string
}

func (*ServeCfg) Mask

func (c *ServeCfg) Mask() *ServeCfg

Mask returns the copy whose sensitive data are masked.

func (*ServeCfg) TLSServerConfig

func (c *ServeCfg) TLSServerConfig() *credentials.TLSServerConfig

func (*ServeCfg) Validate

func (c *ServeCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type ServiceApplyCfg

type ServiceApplyCfg struct {
	RootCfg
}

func (*ServiceApplyCfg) Mask

func (c *ServiceApplyCfg) Mask() *ServiceApplyCfg

Mask returns the copy whose sensitive data are masked.

func (*ServiceApplyCfg) Validate

func (c *ServiceApplyCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type ServiceCompileCfg

type ServiceCompileCfg struct {
	RootCfg

	Service string   `validate:"required"`
	Keys    []string `validate:"gt=0,dive,required"`
}

func (*ServiceCompileCfg) Mask

Mask returns the copy whose sensitive data are masked.

func (*ServiceCompileCfg) Validate

func (c *ServiceCompileCfg) Validate() error

Validate validates exposed fields according to the `validate` tag.

type ServiceCompilePlan

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

func NewServiceCompilePlan

func NewServiceCompilePlan(stmap extgogit.Status, root string) *ServiceCompilePlan

NewServiceCompilePlan creates new ServiceCompilePlan from the given git file statuses.

func (*ServiceCompilePlan) Do

func (p *ServiceCompilePlan) Do(ctx context.Context, deleteFunc ServiceFunc, updateFunc ServiceFunc) error

Do executes given delete ServiceFunc and update ServiceFunc according to its execution plan.

func (*ServiceCompilePlan) IsEmpty

func (p *ServiceCompilePlan) IsEmpty() bool

IsEmpty returns True when there are no planned targets.

type ServiceFunc

type ServiceFunc func(ctx context.Context, sp kuesta.ServicePath) error

type ServicePathReq

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

func (*ServicePathReq) Keys

func (s *ServicePathReq) Keys() map[string]string

func (*ServicePathReq) Path

func (s *ServicePathReq) Path() *kuesta.ServicePath

func (ServicePathReq) String

func (s ServicePathReq) String() string

func (ServicePathReq) Type

func (ServicePathReq) Type() PathType

type VisitFunc

type VisitFunc func(n ast.Node) ast.Visitor

func (VisitFunc) Visit

func (v VisitFunc) Visit(n ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

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