Skip to content

Commit

Permalink
Merge pull request #2 from symbiosis-cloud/feature/refactor-adding-co…
Browse files Browse the repository at this point in the history
…mmands

major refactor and adding mvp commands
  • Loading branch information
thecodeassassin committed Nov 18, 2022
2 parents 0fbf231 + 572eda5 commit 22cb382
Show file tree
Hide file tree
Showing 47 changed files with 2,194 additions and 596 deletions.
Binary file removed .DS_Store
Binary file not shown.
55 changes: 55 additions & 0 deletions .github/workflows/release.yaml
@@ -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/goreleaser-action@v3.1.0
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
test/
kubeconfig.yaml
kubeconfig.yaml
.DS_Store
.symbiosis.project
20 changes: 19 additions & 1 deletion README.md
Expand Up @@ -33,4 +33,22 @@ to signup for a new account.
Once you are logged in you will need to create an API key with admin permissions.

1. Head over to https://app.symbiosis.host/api-keys to generate a new API key
2. run sym config init
2. run sym config init

## Functionality

Currently the CLI is in Beta. We only expose a limited number of CLI commands currently but are aiming for a more comprehensive set of features soon.

### Clusters

* Create cluster
* Delete cluster
* List clusters
* Describe cluster
* Get cluster identity

### Node pools

* Create node pool
* Delete node pool

56 changes: 56 additions & 0 deletions cmd/api-keys.go
@@ -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
}
79 changes: 79 additions & 0 deletions cmd/apikeys/create.go
@@ -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
}
53 changes: 53 additions & 0 deletions cmd/apikeys/delete.go
@@ -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
}
61 changes: 61 additions & 0 deletions cmd/apikeys/list.go
@@ -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
}

0 comments on commit 22cb382

Please sign in to comment.