Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from tharinduwijewardane/release-0.0.2_logincheck
Browse files Browse the repository at this point in the history
Validate whether the user is logged in first
  • Loading branch information
tharinduwijewardane authored Oct 11, 2019
2 parents 248a977 + 58e6c6b commit fd6aef8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ var EnvConfigs = map[string]string{
}

var UserConfigs = map[string]string{
AccessToken: "login.oauth2.accessToken",
AccessToken: "",
}
6 changes: 6 additions & 0 deletions internal/pkg/client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ func NewRequest(cliContext runtime.CliContext, method, path string, body io.Read

return req, err
}

func IsUserLoggedIn(cliContext runtime.UserConfigHolder) bool {

token := cliContext.UserConfig().GetString(AccessToken)
return token != ""
}
4 changes: 4 additions & 0 deletions internal/pkg/cmd/application/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func NewCreateCommand(cliContext runtime.CliContext) *cobra.Command {
func runCreateAppCommand(cliContext runtime.CliContext) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {

if !client.IsUserLoggedIn(cliContext) {
common.ExitWithErrorMessage(cliContext.Out(), "Please login first")
}

description, _ := cmd.Flags().GetString("description")

app := Application{args[0], description}
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/cmd/application/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func NewListCommand(cliContext runtime.CliContext) *cobra.Command {
func runListAppCommand(cliContext runtime.CliContext) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {

if !client.IsUserLoggedIn(cliContext) {
common.ExitWithErrorMessage(cliContext.Out(), "Please login first")
}

listApps(cliContext)
}
}
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/cmd/auth/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package auth
import (
"fmt"
"github.com/spf13/cobra"
"github.com/wso2/choreo-cli/internal/pkg/client"
"github.com/wso2/choreo-cli/internal/pkg/cmd/common"
"github.com/wso2/choreo-cli/internal/pkg/cmd/runtime"
"github.com/wso2/choreo-cli/internal/pkg/source/github"
Expand All @@ -36,6 +37,11 @@ func runConnectCommand(cliContext runtime.CliContext) func(cmd *cobra.Command, a
consoleWriter := cliContext.Out()

return func(cmd *cobra.Command, args []string) {

if !client.IsUserLoggedIn(cliContext) {
common.ExitWithErrorMessage(consoleWriter, "Please login first")
}

if strings.ToLower(args[0]) == sourceProviderGithub {
if github.PerformGithubAuthorization(cliContext) {
common.PrintInfo(consoleWriter, "GitHub authorization successful.")
Expand Down

0 comments on commit fd6aef8

Please sign in to comment.