Skip to content

Commit

Permalink
chore: remove import export commands
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Feb 4, 2025
1 parent 447b638 commit 3a310c2
Show file tree
Hide file tree
Showing 71 changed files with 42 additions and 5,051 deletions.
33 changes: 12 additions & 21 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
"github.com/uselagoon/lagoon-cli/internal/config"
"github.com/uselagoon/lagoon-cli/pkg/output"
"github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -284,11 +285,13 @@ var configLagoonVersionCmd = &cobra.Command{
return err
}
current := lagoonCLIConfig.Current
lc := client.New(

token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)
lagoonVersion, err := lagoon.GetLagoonAPIVersion(context.TODO(), lc)
if err != nil {
Expand Down Expand Up @@ -347,21 +350,21 @@ func init() {
}

// readLagoonConfig reads the lagoon config from specified file.
func readLagoonConfig(lc *lagoon.Config, file string) error {
func readLagoonConfig(lc *config.Config, file string) error {
data, err := os.ReadFile(file)
if err != nil {
// if there is no file found in the specified location, prompt the user to create it with the default
// configuration to point to the amazeeio lagoon instance
if yesNo(fmt.Sprintf("Config file '%s' does not exist, do you want to create it with defaults?", file)) {
l := lagoon.Context{
l := config.Context{
GraphQL: "https://api.amazeeio.cloud/graphql",
HostName: "token.amazeeio.cloud",
Token: "",
Port: "22",
UI: "https://dashboard.amazeeio.cloud",
Kibana: "https://logs.amazeeio.cloud/",
}
lc.Lagoons = map[string]lagoon.Context{}
lc.Lagoons = map[string]config.Context{}
lc.Lagoons["amazeeio"] = l
lc.Default = "amazeeio"
return writeLagoonConfig(lc, file)
Expand All @@ -384,7 +387,7 @@ func readLagoonConfig(lc *lagoon.Config, file string) error {
// functions to handle read/write of configuration file

// writeLagoonConfig writes the lagoon config to specified file.
func writeLagoonConfig(lc *lagoon.Config, file string) error {
func writeLagoonConfig(lc *config.Config, file string) error {
d, err := yaml.Marshal(&lc)
if err != nil {
return fmt.Errorf("unable to marshal config into valid yaml: %v", err)
Expand All @@ -396,18 +399,6 @@ func writeLagoonConfig(lc *lagoon.Config, file string) error {
return nil
}

func setConfigDefaultVersion(lc *lagoon.Config, lagoon string, version string) error {
if lc.Lagoons[lagoon].Version == "" {
l := lc.Lagoons[lagoon]
l.Version = version
lc.Lagoons[lagoon] = l
if err := writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {
return fmt.Errorf("couldn't write config: %v", err)
}
}
return nil
}

func removeConfig(key string) error {
delete(lagoonCLIConfig.Lagoons, key)
if err := writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import (
"reflect"
"testing"

"github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/config"
)

func TestConfigRead(t *testing.T) {
var testCases = map[string]struct {
input string
description string
readfailallowed bool
expect lagoon.Config
expect config.Config
}{
"valid-yaml": {
input: "testdata/lagoon.yml",
description: "This test checks that a valid and complete configuration is parsed",
readfailallowed: false,
expect: lagoon.Config{
expect: config.Config{
Current: "amazeeio",
Default: "amazeeio",
Lagoons: map[string]lagoon.Context{
Lagoons: map[string]config.Context{
"amazeeio": {
GraphQL: "https://api.amazeeio.cloud/graphql",
HostName: "token.amazeeio.cloud",
Expand All @@ -39,16 +39,16 @@ func TestConfigRead(t *testing.T) {
input: "testdata/lagoon.yml.invalid",
description: "This test checks to see if an invalid yaml config is not parsed",
readfailallowed: true,
expect: lagoon.Config{},
expect: config.Config{},
},
"missing-yaml": {
input: "testdata/lagoon.yml.missing",
description: "This test checks if a context is missing the required data (graphql, hostname, port)",
readfailallowed: true,
expect: lagoon.Config{
expect: config.Config{
Current: "amazeeio",
Default: "amazeeio",
Lagoons: map[string]lagoon.Context{
Lagoons: map[string]config.Context{
"amazeeio": {
Kibana: "https://logs.amazeeio.cloud/",
UI: "https://dashboard.amazeeio.cloud",
Expand All @@ -61,7 +61,7 @@ func TestConfigRead(t *testing.T) {
}
for name, tc := range testCases {
t.Run(name, func(tt *testing.T) {
lc := lagoon.Config{}
lc := config.Config{}
if err := readLagoonConfig(&lc, tc.input); err != nil {
if tc.readfailallowed == false {
tt.Fatal(err)
Expand Down
9 changes: 9 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ func makeSafe(in string) string {
return unsafeRegex.ReplaceAllString(strings.ToLower(in), "$1-$2")
}

// convert a slice of strings to a set (as a map)
func sliceToMap(s []string) map[string]bool {
m := map[string]bool{}
for _, ss := range s {
m[ss] = true
}
return m
}

// shortenEnvironment shortens the environment name down the same way that Lagoon does
func shortenEnvironment(project, environment string) string {
overlength := 58 - len(project)
Expand Down
149 changes: 0 additions & 149 deletions cmd/import.go

This file was deleted.

24 changes: 12 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
lagooncli "github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
"github.com/uselagoon/lagoon-cli/internal/config"
"github.com/uselagoon/lagoon-cli/pkg/app"
"github.com/uselagoon/lagoon-cli/pkg/output"
"github.com/uselagoon/lagoon-cli/pkg/updatecheck"
llagoon "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
)

var cmdProject app.LagoonProject
Expand All @@ -45,7 +46,7 @@ var strictHostKeyCheck string

// global for the lagoon config that the cli uses
// @TODO: when lagoon-cli rewrite happens, do this a bit better
var lagoonCLIConfig lagooncli.Config
var lagoonCLIConfig config.Config

// version/build information (populated at build time by make file)
var (
Expand Down Expand Up @@ -199,8 +200,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
rootCmd.AddCommand(retrieveCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(webCmd)
rootCmd.AddCommand(importCmd)
rootCmd.AddCommand(exportCmd)
rootCmd.AddCommand(whoamiCmd)
rootCmd.AddCommand(uploadCmd)
rootCmd.AddCommand(rawCmd)
Expand Down Expand Up @@ -344,13 +343,14 @@ func validateTokenE(lagoon string) error {
// check if we have a version set in config, if not get the version.
// this checks whenever a token is refreshed
func versionCheck(lagoon string) error {
lc := client.New(
token := lagoonCLIConfig.Lagoons[lagoon].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[lagoon].GraphQL,
lagoonCLIConfig.Lagoons[lagoon].Token,
lagoonCLIConfig.Lagoons[lagoon].Version,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[lagoon].Version,
&token,
debugEnable)
lagoonVersion, err := lagooncli.GetLagoonAPIVersion(context.TODO(), lc)
lagoonVersion, err := llagoon.GetLagoonAPIVersion(context.TODO(), lc)
if err != nil {
return err
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func getLagoonConfigFile(configPath *string, configName *string, configExtension
return nil
}

func getLagoonContext(lagoonCLIConfig *lagooncli.Config, lagoon *string, cmd *cobra.Command) error {
func getLagoonContext(lagoonCLIConfig *config.Config, lagoon *string, cmd *cobra.Command) error {
// check if we have an envvar or flag to define our lagoon context
var lagoonContext string
lagoonContext, err := cmd.Flags().GetString("lagoon")
Expand Down Expand Up @@ -423,7 +423,7 @@ func getLagoonContext(lagoonCLIConfig *lagooncli.Config, lagoon *string, cmd *co
return nil
}

func checkContextExists(lagoonCLIConfig *lagooncli.Config) error {
func checkContextExists(lagoonCLIConfig *config.Config) error {
contextExists := false
for l := range lagoonCLIConfig.Lagoons {
if l == lagoonCLIConfig.Current {
Expand All @@ -437,7 +437,7 @@ func checkContextExists(lagoonCLIConfig *lagooncli.Config) error {
}

// VerifyTokenExpiry verfies if the current token is valid or not
func VerifyTokenExpiry(lc *lagooncli.Config, lagoon string) bool {
func VerifyTokenExpiry(lc *config.Config, lagoon string) bool {
var p jwt.Parser
token, _, err := p.ParseUnverified(
lc.Lagoons[lagoon].Token, &jwt.StandardClaims{})
Expand Down
2 changes: 0 additions & 2 deletions docs/commands/lagoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ lagoon [flags]
* [lagoon config](lagoon_config.md) - Configure Lagoon CLI
* [lagoon delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments
* [lagoon deploy](lagoon_deploy.md) - Actions for deploying or promoting branches or environments in lagoon
* [lagoon export](lagoon_export.md) - Export lagoon output to yaml
* [lagoon get](lagoon_get.md) - Get info on a resource
* [lagoon import](lagoon_import.md) - Import a config from a yaml file
* [lagoon kibana](lagoon_kibana.md) - Launch the kibana interface
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
* [lagoon login](lagoon_login.md) - Login or refresh an authentication token
Expand Down
Loading

0 comments on commit 3a310c2

Please sign in to comment.