Skip to content

Commit 20e3168

Browse files
committed
chore: remove import export commands
1 parent 3475db3 commit 20e3168

71 files changed

Lines changed: 42 additions & 5051 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/config.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111

1212
"github.com/spf13/cobra"
1313
"github.com/spf13/pflag"
14-
"github.com/uselagoon/lagoon-cli/internal/lagoon"
15-
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
14+
"github.com/uselagoon/lagoon-cli/internal/config"
1615
"github.com/uselagoon/lagoon-cli/pkg/output"
16+
"github.com/uselagoon/machinery/api/lagoon"
17+
lclient "github.com/uselagoon/machinery/api/lagoon/client"
1718
"gopkg.in/yaml.v3"
1819
)
1920

@@ -284,11 +285,13 @@ var configLagoonVersionCmd = &cobra.Command{
284285
return err
285286
}
286287
current := lagoonCLIConfig.Current
287-
lc := client.New(
288+
289+
token := lagoonCLIConfig.Lagoons[current].Token
290+
lc := lclient.New(
288291
lagoonCLIConfig.Lagoons[current].GraphQL,
289-
lagoonCLIConfig.Lagoons[current].Token,
290-
lagoonCLIConfig.Lagoons[current].Version,
291292
lagoonCLIVersion,
293+
lagoonCLIConfig.Lagoons[current].Version,
294+
&token,
292295
debug)
293296
lagoonVersion, err := lagoon.GetLagoonAPIVersion(context.TODO(), lc)
294297
if err != nil {
@@ -347,21 +350,21 @@ func init() {
347350
}
348351

349352
// readLagoonConfig reads the lagoon config from specified file.
350-
func readLagoonConfig(lc *lagoon.Config, file string) error {
353+
func readLagoonConfig(lc *config.Config, file string) error {
351354
data, err := os.ReadFile(file)
352355
if err != nil {
353356
// if there is no file found in the specified location, prompt the user to create it with the default
354357
// configuration to point to the amazeeio lagoon instance
355358
if yesNo(fmt.Sprintf("Config file '%s' does not exist, do you want to create it with defaults?", file)) {
356-
l := lagoon.Context{
359+
l := config.Context{
357360
GraphQL: "https://api.amazeeio.cloud/graphql",
358361
HostName: "token.amazeeio.cloud",
359362
Token: "",
360363
Port: "22",
361364
UI: "https://dashboard.amazeeio.cloud",
362365
Kibana: "https://logs.amazeeio.cloud/",
363366
}
364-
lc.Lagoons = map[string]lagoon.Context{}
367+
lc.Lagoons = map[string]config.Context{}
365368
lc.Lagoons["amazeeio"] = l
366369
lc.Default = "amazeeio"
367370
return writeLagoonConfig(lc, file)
@@ -384,7 +387,7 @@ func readLagoonConfig(lc *lagoon.Config, file string) error {
384387
// functions to handle read/write of configuration file
385388

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

399-
func setConfigDefaultVersion(lc *lagoon.Config, lagoon string, version string) error {
400-
if lc.Lagoons[lagoon].Version == "" {
401-
l := lc.Lagoons[lagoon]
402-
l.Version = version
403-
lc.Lagoons[lagoon] = l
404-
if err := writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {
405-
return fmt.Errorf("couldn't write config: %v", err)
406-
}
407-
}
408-
return nil
409-
}
410-
411402
func removeConfig(key string) error {
412403
delete(lagoonCLIConfig.Lagoons, key)
413404
if err := writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {

cmd/config_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import (
55
"reflect"
66
"testing"
77

8-
"github.com/uselagoon/lagoon-cli/internal/lagoon"
8+
"github.com/uselagoon/lagoon-cli/internal/config"
99
)
1010

1111
func TestConfigRead(t *testing.T) {
1212
var testCases = map[string]struct {
1313
input string
1414
description string
1515
readfailallowed bool
16-
expect lagoon.Config
16+
expect config.Config
1717
}{
1818
"valid-yaml": {
1919
input: "testdata/lagoon.yml",
2020
description: "This test checks that a valid and complete configuration is parsed",
2121
readfailallowed: false,
22-
expect: lagoon.Config{
22+
expect: config.Config{
2323
Current: "amazeeio",
2424
Default: "amazeeio",
25-
Lagoons: map[string]lagoon.Context{
25+
Lagoons: map[string]config.Context{
2626
"amazeeio": {
2727
GraphQL: "https://api.amazeeio.cloud/graphql",
2828
HostName: "token.amazeeio.cloud",
@@ -39,16 +39,16 @@ func TestConfigRead(t *testing.T) {
3939
input: "testdata/lagoon.yml.invalid",
4040
description: "This test checks to see if an invalid yaml config is not parsed",
4141
readfailallowed: true,
42-
expect: lagoon.Config{},
42+
expect: config.Config{},
4343
},
4444
"missing-yaml": {
4545
input: "testdata/lagoon.yml.missing",
4646
description: "This test checks if a context is missing the required data (graphql, hostname, port)",
4747
readfailallowed: true,
48-
expect: lagoon.Config{
48+
expect: config.Config{
4949
Current: "amazeeio",
5050
Default: "amazeeio",
51-
Lagoons: map[string]lagoon.Context{
51+
Lagoons: map[string]config.Context{
5252
"amazeeio": {
5353
Kibana: "https://logs.amazeeio.cloud/",
5454
UI: "https://dashboard.amazeeio.cloud",
@@ -61,7 +61,7 @@ func TestConfigRead(t *testing.T) {
6161
}
6262
for name, tc := range testCases {
6363
t.Run(name, func(tt *testing.T) {
64-
lc := lagoon.Config{}
64+
lc := config.Config{}
6565
if err := readLagoonConfig(&lc, tc.input); err != nil {
6666
if tc.readfailallowed == false {
6767
tt.Fatal(err)

cmd/helpers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ func makeSafe(in string) string {
2020
return unsafeRegex.ReplaceAllString(strings.ToLower(in), "$1-$2")
2121
}
2222

23+
// convert a slice of strings to a set (as a map)
24+
func sliceToMap(s []string) map[string]bool {
25+
m := map[string]bool{}
26+
for _, ss := range s {
27+
m[ss] = true
28+
}
29+
return m
30+
}
31+
2332
// shortenEnvironment shortens the environment name down the same way that Lagoon does
2433
func shortenEnvironment(project, environment string) string {
2534
overlength := 58 - len(project)

cmd/import.go

Lines changed: 0 additions & 149 deletions
This file was deleted.

cmd/root.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import (
1515
"github.com/manifoldco/promptui"
1616
"github.com/spf13/cobra"
1717
"github.com/spf13/cobra/doc"
18-
lagooncli "github.com/uselagoon/lagoon-cli/internal/lagoon"
19-
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
18+
"github.com/uselagoon/lagoon-cli/internal/config"
2019
"github.com/uselagoon/lagoon-cli/pkg/app"
2120
"github.com/uselagoon/lagoon-cli/pkg/output"
2221
"github.com/uselagoon/lagoon-cli/pkg/updatecheck"
22+
llagoon "github.com/uselagoon/machinery/api/lagoon"
23+
lclient "github.com/uselagoon/machinery/api/lagoon/client"
2324
)
2425

2526
var cmdProject app.LagoonProject
@@ -45,7 +46,7 @@ var strictHostKeyCheck string
4546

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

5051
// version/build information (populated at build time by make file)
5152
var (
@@ -199,8 +200,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
199200
rootCmd.AddCommand(retrieveCmd)
200201
rootCmd.AddCommand(versionCmd)
201202
rootCmd.AddCommand(webCmd)
202-
rootCmd.AddCommand(importCmd)
203-
rootCmd.AddCommand(exportCmd)
204203
rootCmd.AddCommand(whoamiCmd)
205204
rootCmd.AddCommand(uploadCmd)
206205
rootCmd.AddCommand(rawCmd)
@@ -344,13 +343,14 @@ func validateTokenE(lagoon string) error {
344343
// check if we have a version set in config, if not get the version.
345344
// this checks whenever a token is refreshed
346345
func versionCheck(lagoon string) error {
347-
lc := client.New(
346+
token := lagoonCLIConfig.Lagoons[lagoon].Token
347+
lc := lclient.New(
348348
lagoonCLIConfig.Lagoons[lagoon].GraphQL,
349-
lagoonCLIConfig.Lagoons[lagoon].Token,
350-
lagoonCLIConfig.Lagoons[lagoon].Version,
351349
lagoonCLIVersion,
350+
lagoonCLIConfig.Lagoons[lagoon].Version,
351+
&token,
352352
debugEnable)
353-
lagoonVersion, err := lagooncli.GetLagoonAPIVersion(context.TODO(), lc)
353+
lagoonVersion, err := llagoon.GetLagoonAPIVersion(context.TODO(), lc)
354354
if err != nil {
355355
return err
356356
}
@@ -393,7 +393,7 @@ func getLagoonConfigFile(configPath *string, configName *string, configExtension
393393
return nil
394394
}
395395

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

426-
func checkContextExists(lagoonCLIConfig *lagooncli.Config) error {
426+
func checkContextExists(lagoonCLIConfig *config.Config) error {
427427
contextExists := false
428428
for l := range lagoonCLIConfig.Lagoons {
429429
if l == lagoonCLIConfig.Current {
@@ -437,7 +437,7 @@ func checkContextExists(lagoonCLIConfig *lagooncli.Config) error {
437437
}
438438

439439
// VerifyTokenExpiry verfies if the current token is valid or not
440-
func VerifyTokenExpiry(lc *lagooncli.Config, lagoon string) bool {
440+
func VerifyTokenExpiry(lc *config.Config, lagoon string) bool {
441441
var p jwt.Parser
442442
token, _, err := p.ParseUnverified(
443443
lc.Lagoons[lagoon].Token, &jwt.StandardClaims{})

docs/commands/lagoon.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ lagoon [flags]
4040
* [lagoon config](lagoon_config.md) - Configure Lagoon CLI
4141
* [lagoon delete](lagoon_delete.md) - Delete a project, or delete notifications and variables from projects or environments
4242
* [lagoon deploy](lagoon_deploy.md) - Actions for deploying or promoting branches or environments in lagoon
43-
* [lagoon export](lagoon_export.md) - Export lagoon output to yaml
4443
* [lagoon get](lagoon_get.md) - Get info on a resource
45-
* [lagoon import](lagoon_import.md) - Import a config from a yaml file
4644
* [lagoon kibana](lagoon_kibana.md) - Launch the kibana interface
4745
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
4846
* [lagoon login](lagoon_login.md) - Login or refresh an authentication token

0 commit comments

Comments
 (0)