buildr/internal/cmd/api.go

137 lines
3.2 KiB
Go
Raw Normal View History

package cmd
import (
"context"
"flag"
"io"
2023-06-18 12:34:20 +00:00
"code.icb4dc0.de/buildr/buildr/internal/config"
"code.icb4dc0.de/buildr/buildr/internal/rpc"
"code.icb4dc0.de/buildr/buildr/modules"
"github.com/spf13/cobra"
)
type InitLevel int
const (
InitLevelNone InitLevel = iota
InitLevelBasic
InitLevelBuildRConfig
InitLevelParseConfig
)
2023-06-22 16:06:56 +00:00
const (
defaultPasswordLength = 32
)
type LevelInitializer interface {
2023-06-22 16:06:56 +00:00
InitAt(ctx context.Context, lvl InitLevel) error
}
type VaultInitConfig struct {
PassphraseLength uint `mapstructure:"vault-pw-length"`
}
func (c *VaultInitConfig) Flags() *flag.FlagSet {
fs := flag.NewFlagSet("vault-init", flag.ExitOnError)
fs.UintVar(
&c.PassphraseLength,
"vault.pw-length",
2023-06-22 16:06:56 +00:00
defaultPasswordLength,
"Length of the passphrase to generate",
)
return fs
}
2023-06-18 12:34:20 +00:00
type BuildrConfigAccessor interface {
BuildrConfig() config.Buildr
}
type AppConfigAccessor interface {
AppConfig() AppConfig
}
type TypeRegistryAccessor interface {
TypeRegistry() *modules.TypeRegistry
}
type ModuleRepositoryAccessor interface {
Repository() *modules.Repository
}
type VaultCommander interface {
2023-06-22 16:06:56 +00:00
Init(ctx context.Context, cfg VaultInitConfig) error
List(ctx context.Context, writer io.Writer) error
Get(ctx context.Context, key string, writer io.Writer) error
Set(ctx context.Context, key string, value []byte) error
Remove(ctx context.Context, key string) error
}
type PluginCommander interface {
ListPlugins(ctx context.Context, writer io.Writer) error
UpdatePlugins(ctx context.Context) error
}
type ServerCommander interface {
ServeAPI(ctx context.Context, cfg *rpc.GrpcConfig) error
}
type ModuleCommander interface {
RunModule(ctx context.Context, cat modules.Category, name string) error
}
type BootstrapModuleCommander interface {
2023-06-22 16:06:56 +00:00
BootstrapModule(ctx context.Context, cat modules.Category, typeName, moduleName string) error
}
2023-06-18 12:34:20 +00:00
type KnownTasksArgProvider interface {
ValidTasksArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
}
type KnownModulesArgProvider interface {
ValidModulesArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
}
type ManCommander interface {
DisplayModuleManual(ctx context.Context, pager Pager, cat modules.Category, name string) error
DisplayModulesManual(pager Pager) error
}
2023-06-18 12:34:20 +00:00
type KnownTasksArgProviderFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
2023-06-22 16:06:56 +00:00
func (f KnownTasksArgProviderFunc) ValidTasksArgs(
cmd *cobra.Command,
args []string,
toComplete string,
) ([]string, cobra.ShellCompDirective) {
2023-06-18 12:34:20 +00:00
return f(cmd, args, toComplete)
}
type KnownModulesArgProviderFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
2023-06-22 16:06:56 +00:00
func (f KnownModulesArgProviderFunc) ValidModulesArgs(
cmd *cobra.Command,
args []string,
toComplete string,
) ([]string, cobra.ShellCompDirective) {
return f(cmd, args, toComplete)
}
type AppInitializer interface {
Init(ctx context.Context) error
}
type AppInitializerFunc func(ctx context.Context) error
func (f AppInitializerFunc) Init(ctx context.Context) error {
return f(ctx)
}
type EnvCommander interface {
2023-06-22 16:06:56 +00:00
PrintPath(ctx context.Context, writer io.Writer) error
}