Skip to content

Commit

Permalink
added a command to test sm authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillezi committed Sep 19, 2024
1 parent e73eac9 commit 952a9e0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/cli_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/Phillezi/kthcloud-cli/pkg/v1/commands/compose"
"github.com/Phillezi/kthcloud-cli/pkg/v1/commands/compose/storage"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -35,6 +36,15 @@ var composeDownCmd = &cobra.Command{
},
}

var testSMAuthCmd = &cobra.Command{
Use: "sm check",
Short: "Test authentication against storage manager",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
storage.Check()
},
}

func init() {
composeUpCmd.Flags().BoolP("try-volumes", "", false, "Try uploading local files and dirs that should be mounted on the deployment.\nIf enabled it will \"steal\" cookies from your browser to authenticate.")
composeUpCmd.Flags().BoolP("detached", "d", false, "doesn't do anything, just here for parity with Docker Compose up")
Expand All @@ -44,6 +54,7 @@ func init() {
composeCmd.AddCommand(composeParseCmd)
composeCmd.AddCommand(composeUpCmd)
composeCmd.AddCommand(composeDownCmd)
composeCmd.AddCommand(testSMAuthCmd)

// Register the compose command in root
rootCmd.AddCommand(composeCmd)
Expand Down
33 changes: 33 additions & 0 deletions pkg/v1/commands/compose/storage/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package storage

import (
"github.com/Phillezi/kthcloud-cli/pkg/v1/auth/client"
storageclient "github.com/Phillezi/kthcloud-cli/pkg/v1/auth/storage-client"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

func Check() {
c := client.Get()
if !c.HasValidSession() {
logrus.Fatal("not logged in")
}
user, err := c.User()
if err != nil {
logrus.Fatal(err)
}
if user.StorageURL == nil {
logrus.Fatal("user doesnt have storageurl")
}
if c.StorageClient == nil {
c.StorageClient = storageclient.GetInstance(*user.StorageURL, viper.GetString("keycloak-host"))
}
isAuth, err := c.StorageClient.Auth()
if err != nil {
logrus.Fatal(err)
}
if !isAuth {
logrus.Fatal("not authenticated on storage url" + *user.StorageURL)
}
logrus.Infoln("Passed :)")
}

0 comments on commit 952a9e0

Please sign in to comment.