Skip to content

Commit

Permalink
major refactor of executables and secret management
Browse files Browse the repository at this point in the history
  • Loading branch information
jahvon committed Oct 9, 2023
1 parent 162b790 commit af56a42
Show file tree
Hide file tree
Showing 46 changed files with 700 additions and 1,883 deletions.
58 changes: 4 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,60 +70,15 @@ Example autocompletion setup script: `flow completion zsh > ~/.oh-my-zsh/complet

## Install

You can install the pre-compiled binary (in several ways), use Docker or compile from source (when on OSS).
You can install the pre-compiled binary or compile from source.

Below you can find the steps for each of them.

<details>
<summary><h3>homebrew tap</h3></summary>

```bash
brew install jahvon/tap/flow
```

</details>

<details>
<summary><h3>apt</h3></summary>

```bash
echo 'deb [trusted=yes] https://apt.fury.io/jahvon/ /' | sudo tee /etc/apt/sources.list.d/jahvon.list
sudo apt update
sudo apt install flow
```

</details>

<details>
<summary><h3>yum</h3></summary>

```bash
echo '[jahvon]
name=Gemfury jahvon repository
baseurl=https://yum.fury.io/jahvon/
enabled=1
gpgcheck=0' | sudo tee /etc/yum.repos.d/jahvon.repo
sudo yum install goreleaser
```

</details>

<details>
<summary><h3>deb, rpm and apk packages</h3></summary>
Download the .deb, .rpm or .apk packages from the [release page](https://github.com/jahvon/flow/releases) and install them with the appropriate tools.
</details>

<details>
<summary><h3>go install</h3></summary>
### via Go Install

```bash
go install github.com/jahvon/flow@latest
```

</details>

<details>
<summary><h3>from the GitHub releases</h3></summary>
### via GitHub Releases

Download the pre-compiled binaries from the [release page](https://github.com/jahvon/flow/releases) page and copy them to the desired location.

Expand All @@ -137,16 +92,11 @@ $ sudo tar xvf ${TAR_FILE} flow -C /usr/local/bin
$ rm -f ${TAR_FILE}
```

</details>

<details>
<summary><h3>manually</h3></summary>
### via Source

```bash
$ git clone github.com/jahvon/flow
$ cd flow
$ go generate ./...
$ go install
```

</details>
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var createWorkspaceCmd = &cobra.Command{
}

func init() {
createWorkspaceCmd.Flags().StringP("path", "p", common.DataDirPath(), "Path to the directory where the workspace should be created")
createWorkspaceCmd.Flags().StringP("path", "p", common.ConfigDirPath(), "Path to the directory where the workspace should be created")
if err := createWorkspaceCmd.MarkFlagDirname("path"); err != nil {
log.Fatal().Err(err).Msg("Failed to mark path flag as a directory")
}
Expand Down
34 changes: 0 additions & 34 deletions cmd/login.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var openCmd = &cobra.Command{
log.Fatal().Msg("executable is nil")
}

err = agent.Exec(executable.Spec, nil)
err = agent.Exec(*executable)
if err != nil {
io.PrintErrorAndExit(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/jahvon/flow/internal/io"
)

var log = io.Log()

var rootCmd = &cobra.Command{
Use: "flow",
Short: "[Alpha] CLI script wrapper",
Expand All @@ -32,8 +34,6 @@ var rootCmd = &cobra.Command{
Version: version.String(),
}

var log = io.Log()

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var runCmd = &cobra.Command{
log.Fatal().Msg("executable is nil")
}

err = agent.Exec(executable.Spec, nil)
err = agent.Exec(*executable)
if err != nil {
io.PrintErrorAndExit(err)
}
Expand Down
215 changes: 0 additions & 215 deletions cmd/set.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/jahvon/flow/internal/backend/consts"
"github.com/jahvon/flow/internal/cmd/flags"
"github.com/jahvon/flow/internal/cmd/set"
"github.com/jahvon/flow/internal/cmd/utils"
"github.com/jahvon/flow/internal/config"
"github.com/jahvon/flow/internal/io"
)
Expand Down Expand Up @@ -41,216 +35,7 @@ var setWorkspaceCmd = &cobra.Command{
},
}

// setAuthCmd represents the set auth subcommand
var setAuthCmd = &cobra.Command{
Use: "auth",
Aliases: []string{"a"},
Short: "Options for updating auth config and data.",
}

// setAuthBackendCmd represents the set backend auth subcommand
var setAuthBackendCmd = &cobra.Command{
Use: "backend",
Aliases: []string{"b"},
Short: "Update the authentication backend configurations.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
rootCfg := config.LoadConfig()
if rootCfg == nil {
log.Fatal().Msg("failed to load config")
}
authConfig, err := set.FlagsToAuthConfig(cmd, rootCfg.Backends.Auth)
if err != nil {
io.PrintErrorAndExit(err)
}

if err := config.SetAuthBackend(rootCfg, authConfig); err != nil {
io.PrintErrorAndExit(err)
}

io.PrintSuccess("Authentication backend configurations updated")
},
}

// setSecretCmd represents the set secret subcommand
var setSecretCmd = &cobra.Command{
Use: "secret",
Aliases: []string{"s"},
Short: "Options for updating secret config and data.",
}

// setSecretBackendCmd represents the set secret subcommand
var setSecretBackendCmd = &cobra.Command{
Use: "backend",
Aliases: []string{"b"},
Short: "Update the secret backend configurations.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
rootCfg := config.LoadConfig()
if rootCfg == nil {
log.Fatal().Msg("failed to load config")
}
secretConfig, err := set.FlagsToSecretConfig(cmd, rootCfg.Backends.Secret)
if err != nil {
io.PrintErrorAndExit(err)
}

if err := config.SetSecretBackend(rootCfg, secretConfig); err != nil {
io.PrintErrorAndExit(err)
}

io.PrintSuccess("Secret backend configurations updated")
},
}

// setSecretDataCmd represents the set secret data subcommand
var setSecretDataCmd = &cobra.Command{
Use: "data <key> <value>",
Aliases: []string{"d"},
Short: "Create or update a secret.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
rootCfg := config.LoadConfig()
if rootCfg == nil {
log.Fatal().Msg("failed to load config")
}

key, value, err := set.ArgsToSecretKV(args)
if err != nil {
io.PrintErrorAndExit(err)
}

context, err := utils.ValidateAndGetContext(cmd, rootCfg)
if err != nil {
io.PrintErrorAndExit(err)
}

if err := rootCfg.Backends.Secret.CurrentBackend().SetSecret(context, key, value); err != nil {
io.PrintErrorAndExit(err)
}

io.PrintSuccess(fmt.Sprintf("Secret '%s' set within '%s' context", key, context))
},
}

// setParamCmd represents the set param subcommand
var setParamCmd = &cobra.Command{
Use: "param <key>",
Aliases: []string{"p"},
Short: "Create or update a parameter.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
rootCfg := config.LoadConfig()
if rootCfg == nil {
log.Fatal().Msg("failed to load config")
}

// todo
// context, err := utils.ValidateAndGetContext(cmd, rootCfg)
// if err != nil {
// io.PrintErrorAndExit(err)
// }
//
// if context == "global" {
// param, err := set.FlagsToParameter(cmd)
// if err != nil {
// io.PrintErrorAndExit(err)
// }
// io.PrintSuccess(fmt.Sprintf("Parameter '%s' set with global scope", key))
// } else {
// for ws, wsPath := range currentConfig.Workspaces {
// if ws == context {
//
// io.PrintSuccess(fmt.Sprintf("Parameter '%s' set in workspace '%s' config", key, currentWorkspaceName))
// }
// }
// }
log.Panic().Msg("not implemented")
},
}

func init() {
// Auth sub commands
setAuthBackendCmd.Flags().StringP(
flags.BackendFlagName,
"n",
"",
fmt.Sprintf("Set the authentication backend to use. Valid options are: %s", consts.AuthBackends),
)
setAuthBackendCmd.Flags().StringP(
flags.PreferredModeFlagName,
"m",
"",
fmt.Sprintf("Set the preferred authentication mode to use. Valid options are: %s", consts.AuthModes),
)
setAuthBackendCmd.Flags().BoolP(
flags.RememberMeFlagName,
"r",
false,
"Save auth session for a given duration.",
)
setAuthBackendCmd.Flags().DurationP(
flags.RememberMeDurationFlagName,
"d",
0,
"Set the duration to remember the user",
)
setAuthCmd.AddCommand(setAuthBackendCmd)
setCmd.AddCommand(setAuthCmd)

// Param sub commands
setParamCmd.Flags().StringP(
flags.WorkspaceContextFlagName,
"w",
"",
"Workspace to set the parameter in, defaults to current workspace if not set",
)
setParamCmd.Flags().BoolP(
flags.GlobalContextFlagName,
"g",
false,
"Set the parameter to be globally accessible",
)
setParamCmd.Flags().StringP(
flags.TextValueFlagName,
"t",
"",
"Set the parameter value to the specified text",
)
setParamCmd.Flags().StringP(
flags.SecretRefFlagName,
"r",
"",
"Set the parameter value to the specified secret reference (key)",
)
setParamCmd.MarkFlagsMutuallyExclusive(flags.TextValueFlagName, flags.SecretRefFlagName)
setCmd.AddCommand(setParamCmd)

// Secret sub commands
setSecretBackendCmd.Flags().StringP(
flags.BackendFlagName,
"n",
"",
fmt.Sprintf("Set the secret backend to use. Valid options are: %s", consts.SecretBackends),
)
setSecretDataCmd.Flags().StringP(
flags.WorkspaceContextFlagName,
"w",
"",
"Workspace to set the parameter in, defaults to current workspace if not set",
)
setSecretDataCmd.Flags().BoolP(
flags.GlobalContextFlagName,
"g",
false,
"Set the parameter to be globally accessible",
)
setSecretDataCmd.MarkFlagsMutuallyExclusive("workspace", "global")
setSecretCmd.AddCommand(setSecretBackendCmd)
setSecretCmd.AddCommand(setSecretDataCmd)
setCmd.AddCommand(setSecretCmd)

setCmd.AddCommand(setWorkspaceCmd)

rootCmd.AddCommand(setCmd)
}
Loading

0 comments on commit af56a42

Please sign in to comment.