ctl

package
v0.9.2-beta.24 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateUserCmd = &cobra.Command{
	Use:   "createuser",
	Short: "create user.",
	Example: `
lorryctl  createuser --username xxx --password xxx 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(createUserOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		err = lorryClient.CreateUser(context.TODO(), createUserOptions.userName, createUserOptions.password, "", "")
		if err != nil {
			fmt.Printf("create user failed: %v\n", err)
			return
		}
		fmt.Printf("create user success")
	},
}
View Source
var DeleteUserCmd = &cobra.Command{
	Use:   "deleteuser",
	Short: "delete user.",
	Example: `
lorryctl  deleteuser --username xxx 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(deleteUserOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		err = lorryClient.DeleteUser(context.TODO(), deleteUserOptions.userName)
		if err != nil {
			fmt.Printf("delete user failed: %v\n", err)
			return
		}
		fmt.Printf("delete user success")
	},
}
View Source
var DescribeUserCmd = &cobra.Command{
	Use:   "describeuser",
	Short: "describe user.",
	Example: `
lorryctl  describeuser --username xxx 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(describeUserOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		user, err := lorryClient.DescribeUser(context.TODO(), describeUserOptions.userName)
		if err != nil {
			fmt.Printf("describe user failed: %v\n", err)
			return
		}
		fmt.Println("describe user success:")
		for k, v := range user {
			fmt.Printf("%s: %v\n", k, v)
		}
	},
}
View Source
var GrantUserRoleCmd = &cobra.Command{
	Use:   "grant-role",
	Short: "grant user role.",
	Example: `
lorryctl  grant-role --username xxx --rolename xxx 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(grantUserRoleOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		err = lorryClient.GrantUserRole(context.TODO(), grantUserRoleOptions.userName, grantUserRoleOptions.roleName)
		if err != nil {
			fmt.Printf("grant user role failed: %v\n", err)
			return
		}
		fmt.Printf("grant user role success")
	},
}
View Source
var ListSystemAccountsCmd = &cobra.Command{
	Use:   "listsystemaccounts",
	Short: "list system accounts.",
	Example: `
lorryctl  listsystemaccounts 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(lorryAddr1)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		systemaccounts, err := lorryClient.ListSystemAccounts(context.TODO())
		if err != nil {
			fmt.Printf("list systemaccounts failed: %v\n", err)
			return
		}
		fmt.Printf("list systemaccounts:\n")
		for _, m := range systemaccounts {
			fmt.Println("-------------------------")
			for k, v := range m {
				fmt.Printf("%s: %v\n", k, v)
			}
		}
	},
}
View Source
var ListUsersCmd = &cobra.Command{
	Use:   "listusers",
	Short: "list normal users.",
	Example: `
lorryctl  listusers 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		users, err := lorryClient.ListUsers(context.TODO())
		if err != nil {
			fmt.Printf("list users failed: %v\n", err)
			return
		}
		fmt.Printf("list users:\n")
		for _, m := range users {
			fmt.Println("-------------------------")
			for k, v := range m {
				fmt.Printf("%s: %v\n", k, v)
			}
		}
	},
}
View Source
var RevokeUserRoleCmd = &cobra.Command{
	Use:   "revoke-role",
	Short: "revoke user role.",
	Example: `
lorryctl  revoke-role --username xxx --rolename xxx 
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		lorryClient, err := client.NewHTTPClientWithURL(revokeUserRoleOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		err = lorryClient.RevokeUserRole(context.TODO(), revokeUserRoleOptions.userName, revokeUserRoleOptions.roleName)
		if err != nil {
			fmt.Printf("revoke user role failed: %v\n", err)
			return
		}
		fmt.Printf("revoke user role success")
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "lorryctl",
	Short: "LORRY CLI",
	Long: `
   / /   ____  ____________  __   / ____/ /______/ /
  / /   / __ \/ ___/ ___/ / / /  / /   / __/ ___/ / 
 / /___/ /_/ / /  / /  / /_/ /  / /___/ /_/ /  / /  
/_____/\____/_/  /_/   \__, /   \____/\__/_/  /_/   
                      /____/                        
===============================
Lorry service client`,
	Run: func(cmd *cobra.Command, _ []string) {
		if versionFlag {
			printVersion()
		} else {
			_ = cmd.Help()
		}
	},
}
View Source
var RunCmd = &cobra.Command{
	Use:   "run",
	Short: "Run Lorry and db service.",
	Example: `
lorryctl run  -- mysqld
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			fmt.Println("WARNING: no DB Service found.")
		}
		ctx, cancel := context.WithCancel(context.Background())

		commands, err := newCommands(ctx, &Options{
			HTTPPort:         port,
			GRPCPort:         grpcPort,
			ConfigFile:       configFile,
			Arguments:        args,
			LogLevel:         logLevel,
			ComponentsPath:   componentsPath,
			EnableAppHealth:  enableAppHealth,
			InternalGRPCPort: internalGRPCPort,
		})
		if err != nil {
			fmt.Fprint(os.Stderr, err.Error())
			os.Exit(1)
		}

		sigCh := make(chan os.Signal, 1)
		signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)

		go commands.StartLorry()
		<-commands.LorryStarted

		go commands.StartDBService()
		<-commands.AppStarted
		go commands.RestartDBServiceIfExited()

		if commands.AppCMD != nil {
			appCommand := strings.Join(args, " ")
			fmt.Fprintf(os.Stdout, "Start DB Service with %s.\n", appCommand)
			fmt.Fprintf(os.Stdout, "Lorry logs and DB logs will appear here.\n")
		} else {
			fmt.Fprintf(os.Stdout, "Lorry logs will appear here.\n")
		}

		sig := <-sigCh
		fmt.Printf("\n %v signal received: shutting down\n", sig)
		cancel()
		commands.WaitGroup.Wait()

		exitWithError := commands.StopLorry() || commands.StopDBService()
		if exitWithError {
			os.Exit(1)
		}
	},
}
View Source
var SwitchCmd = &cobra.Command{
	Use:   "switchover",
	Short: "execute a switchover request.",
	Example: `
lorryctl switchover  --primary xxx --candidate xxx
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		if switchOptions.primary == "" && switchOptions.candidate == "" {
			fmt.Println("Primary or Candidate must be specified")
			return
		}

		lorryClient, err := client.NewHTTPClientWithURL(switchOptions.lorryAddr)
		if err != nil {
			fmt.Printf("new lorry http client failed: %v\n", err)
			return
		}

		lorryClient.ReconcileTimeout = 30 * time.Second
		err = lorryClient.Switchover(context.TODO(), switchOptions.primary, switchOptions.candidate, switchOptions.force)
		if err != nil {
			fmt.Printf("switchover failed: %v\n", err)
			return
		}
		fmt.Printf("switchover success\n")
	},
}
View Source
var VaultPluginCmd = &cobra.Command{
	Use:   "vault-plugin",
	Short: "run a vault-plugin service.",
	Example: `
lorryctl vault-plugin  --primary xxx --candidate xxx
  `,
	Args: cobra.MinimumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		err := Run()
		if err != nil {
			logger := hclog.New(&hclog.LoggerOptions{})

			logger.Error("plugin shutting down", "error", err)
			os.Exit(1)
		}
	},
}

Functions

func Execute

func Execute(cliVersion, apiVersion string)

Execute adds all child commands to the root command.

func GetRuntimeVersion

func GetRuntimeVersion() string

GetRuntimeVersion returns the version for the local lorry runtime.

func Printf

func Printf(format string, args ...any)

func Run

func Run() error

Run instantiates a lorry vault plugin object, and runs the RPC server for the plugin

Types

type Commands

type Commands struct {
	WaitGroup     sync.WaitGroup
	LorryCMD      *exec.Cmd
	LorryErr      error
	LorryHTTPPort int
	LorryGRPCPort int
	LorryStarted  chan bool
	AppCMD        *exec.Cmd
	AppErr        error
	AppStarted    chan bool
	Options       *Options
	SigCh         chan os.Signal
	// contains filtered or unexported fields
}

Commands represents the managed subprocesses.

func (*Commands) RestartDBService

func (commands *Commands) RestartDBService()

func (*Commands) RestartDBServiceIfExited

func (commands *Commands) RestartDBServiceIfExited()

func (*Commands) StartDBService

func (commands *Commands) StartDBService()

func (*Commands) StartLorry

func (commands *Commands) StartLorry()

func (*Commands) StopDBService

func (commands *Commands) StopDBService() bool

func (*Commands) StopLorry

func (commands *Commands) StopLorry() bool

func (*Commands) WaitDBService

func (commands *Commands) WaitDBService()

func (*Commands) WaitLorry

func (commands *Commands) WaitLorry()

type CreateUserOptions

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

type DeleteUserOptions

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

type DescribeUserOptions

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

type GrantUserRoleOptions

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

type Options

type Options struct {
	HTTPPort           int    `env:"DAPR_HTTP_PORT" arg:"dapr-http-port"`
	GRPCPort           int    `env:"DAPR_GRPC_PORT" arg:"dapr-grpc-port"`
	ConfigFile         string `arg:"config"`
	Protocol           string `arg:"app-protocol"`
	Arguments          []string
	LogLevel           string `arg:"log-level"`
	ComponentsPath     string `arg:"components-path"`
	InternalGRPCPort   int    `arg:"dapr-internal-grpc-port"`
	EnableAppHealth    bool   `arg:"enable-app-health-check"`
	AppHealthThreshold int    `arg:"app-health-threshold" ifneq:"0"`
}

Options represents the application configuration parameters.

type RevokeUserRoleOptions

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

type SwitchOptions

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

type VaultPluginOptions

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

Jump to

Keyboard shortcuts

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