-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major refactor and adding mvp commands
- Loading branch information
1 parent
0fbf231
commit 14b5607
Showing
47 changed files
with
2,187 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# This GitHub action can publish assets for release when a tag is created. | ||
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). | ||
# | ||
# This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your | ||
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` | ||
# secret. If you would rather own your own GPG handling, please fork this action | ||
# or use an alternative one for key handling. | ||
# | ||
# You will need to pass the `--batch` flag to `gpg` in your signing step | ||
# in `goreleaser` to indicate this is being used in a non-interactive mode. | ||
# | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
permissions: | ||
contents: write | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Unshallow | ||
run: git fetch --prune --unshallow | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: true | ||
- | ||
name: Import GPG key | ||
uses: crazy-max/ghaction-import-gpg@v5 | ||
id: import_gpg | ||
with: | ||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
passphrase: ${{ secrets.GPG_PASSPHRASE }} | ||
- | ||
name: export tty | ||
run: | | ||
export GPG_TTY=$(tty) | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/[email protected] | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
test/ | ||
kubeconfig.yaml | ||
kubeconfig.yaml | ||
.DS_Store | ||
.symbiosis.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/symbiosis-cloud/cli/cmd/apikeys" | ||
"github.com/symbiosis-cloud/cli/pkg/symcommand" | ||
"github.com/symbiosis-cloud/symbiosis-go" | ||
) | ||
|
||
type ApiKeysCommand struct { | ||
Client *symbiosis.Client | ||
CommandOpts *symcommand.CommandOpts | ||
} | ||
|
||
var apiKeysCommands []symcommand.Command | ||
|
||
func (n *ApiKeysCommand) Command() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "api-keys <command>", | ||
Short: "API key management", | ||
Long: ``, | ||
Run: n.Execute, | ||
PersistentPreRunE: func(command *cobra.Command, args []string) error { | ||
err := symcommand.Initialise(apiKeysCommands, command) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
apiKeysCommands = []symcommand.Command{ | ||
&apikeys.CreateApiKeyCommand{}, | ||
&apikeys.DeleteApiKeyCommand{}, | ||
&apikeys.ListApiKeysCommand{}, | ||
} | ||
|
||
for _, c := range apiKeysCommands { | ||
cmd.AddCommand(c.Command()) | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (n *ApiKeysCommand) Execute(command *cobra.Command, args []string) { | ||
fmt.Println("Available commands: [create, list, delete]") | ||
} | ||
|
||
func (c *ApiKeysCommand) Init(client *symbiosis.Client, opts *symcommand.CommandOpts) { | ||
c.Client = client | ||
c.CommandOpts = opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright © 2022 Symbiosis | ||
*/ | ||
package apikeys | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jedib0t/go-pretty/v6/text" | ||
"github.com/spf13/cobra" | ||
"github.com/symbiosis-cloud/cli/pkg/symcommand" | ||
"github.com/symbiosis-cloud/cli/pkg/util" | ||
"github.com/symbiosis-cloud/symbiosis-go" | ||
) | ||
|
||
type CreateApiKeyCommand struct { | ||
Client *symbiosis.Client | ||
CommandOpts *symcommand.CommandOpts | ||
} | ||
|
||
func (c *CreateApiKeyCommand) Command() *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "create <role> <description>", | ||
Short: "Create an API key", | ||
Long: ``, | ||
PreRunE: func(command *cobra.Command, args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("Please provide an API key name and description (sym api-key create <name> <description>") | ||
} | ||
|
||
role := args[0] | ||
err := symbiosis.ValidateRole(symbiosis.UserRole(role)) | ||
|
||
if err != nil { | ||
return fmt.Errorf("%s is not a valid role. You can run 'sym info roles' to list all available roles.", role) | ||
} | ||
|
||
return nil | ||
}, | ||
RunE: func(command *cobra.Command, args []string) error { | ||
|
||
role := args[0] | ||
description := args[1] | ||
|
||
apiKey, err := c.Client.ApiKeys.Create(symbiosis.ApiKeyInput{ | ||
Description: description, | ||
Role: symbiosis.UserRole(role), | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
defer text.EnableColors() | ||
|
||
c.CommandOpts.Logger.Info().Msgf("%s** NOTE ** This token will not be shown again.%s", text.FgRed.EscapeSeq(), text.FgWhite.EscapeSeq()) | ||
|
||
err = util.NewOutput(util.TableOutput{ | ||
Headers: []string{"ID", "Description", "Token", "Role"}, | ||
Data: [][]interface{}{{apiKey.ID, apiKey.Description, apiKey.Token, apiKey.Role}}, | ||
}, | ||
apiKey, | ||
).VariableOutput() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *CreateApiKeyCommand) Init(client *symbiosis.Client, opts *symcommand.CommandOpts) { | ||
c.Client = client | ||
c.CommandOpts = opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright © 2022 Symbiosis | ||
*/ | ||
package apikeys | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/symbiosis-cloud/cli/pkg/symcommand" | ||
"github.com/symbiosis-cloud/cli/pkg/util" | ||
"github.com/symbiosis-cloud/symbiosis-go" | ||
) | ||
|
||
type DeleteApiKeyCommand struct { | ||
Client *symbiosis.Client | ||
CommandOpts *symcommand.CommandOpts | ||
} | ||
|
||
func (c *DeleteApiKeyCommand) Command() *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete api-key", | ||
Long: ``, | ||
PreRunE: func(command *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("Please provide an api-key ID (sym api-key delete <id>") | ||
} | ||
|
||
return util.Confirmation(fmt.Sprintf("Are you sure you want want to delete api-key %s", args[0])) | ||
}, | ||
RunE: func(command *cobra.Command, args []string) error { | ||
apiKeyId := args[0] | ||
c.CommandOpts.Logger.Info().Msgf("Deleting api-key %s", apiKeyId) | ||
|
||
err := c.Client.ApiKeys.Delete(apiKeyId) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *DeleteApiKeyCommand) Init(client *symbiosis.Client, opts *symcommand.CommandOpts) { | ||
c.Client = client | ||
c.CommandOpts = opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright © 2022 Symbiosis | ||
*/ | ||
package apikeys | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/symbiosis-cloud/cli/pkg/symcommand" | ||
"github.com/symbiosis-cloud/cli/pkg/util" | ||
"github.com/symbiosis-cloud/symbiosis-go" | ||
) | ||
|
||
type ListApiKeysCommand struct { | ||
Client *symbiosis.Client | ||
CommandOpts *symcommand.CommandOpts | ||
} | ||
|
||
func (c *ListApiKeysCommand) Execute(command *cobra.Command, args []string) error { | ||
|
||
apiKeys, err := c.Client.ApiKeys.List() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
var data [][]interface{} | ||
|
||
for _, apiKey := range apiKeys { | ||
data = append(data, []interface{}{apiKey.ID, apiKey.Description, apiKey.Token, apiKey.Role}) | ||
} | ||
|
||
err = util.NewOutput(util.TableOutput{ | ||
Headers: []string{"ID", "Description", "Token", "Role"}, | ||
Data: data, | ||
}, | ||
apiKeys, | ||
).VariableOutput() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *ListApiKeysCommand) Command() *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List your api-keys", | ||
Long: ``, | ||
RunE: c.Execute, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *ListApiKeysCommand) Init(client *symbiosis.Client, opts *symcommand.CommandOpts) { | ||
c.Client = client | ||
c.CommandOpts = opts | ||
} |
Oops, something went wrong.