From 155dc98076ad238c8ce5fbe5933a44676bd70f09 Mon Sep 17 00:00:00 2001 From: abdfnx Date: Tue, 25 May 2021 21:35:43 +0300 Subject: [PATCH] add user checker --- core/authflow/success.go | 2 +- core/container/main.go | 2 +- pkg/cmd/factory/default.go | 4 ++-- pkg/cmd/repo/repo.go | 26 ++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/authflow/success.go b/core/authflow/success.go index 9f0389b5197..ff0eb9f08e2 100644 --- a/core/authflow/success.go +++ b/core/authflow/success.go @@ -33,7 +33,7 @@ const oauthSuccessPage = ` } - +

Successfully authenticated Secman With Github 🔗

You may now close this tab and return to the terminal.

diff --git a/core/container/main.go b/core/container/main.go index 8395a36d4bc..f7dff1726ef 100644 --- a/core/container/main.go +++ b/core/container/main.go @@ -54,7 +54,7 @@ func mainRun() exitCode { hasDebug := os.Getenv("DEBUG") != "" - cmdFactory := factory.New(buildVersion) + cmdFactory := factory.New() stderr := cmdFactory.IOStreams.ErrOut if !cmdFactory.IOStreams.ColorEnabled() { surveyCore.DisableColor = true diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index e1433c89f40..de6938d2a0b 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -13,7 +13,7 @@ import ( "github.com/secman-team/gh-api/pkg/iostreams" ) -func New(appVersion string) *cmdutil.Factory { +func New() *cmdutil.Factory { io := iostreams.System() var cachedConfig config.Config @@ -52,7 +52,7 @@ func New(appVersion string) *cmdutil.Factory { return nil, err } - return NewHTTPClient(io, cfg, appVersion, true), nil + return NewHTTPClient(io, cfg, "x", true), nil }, BaseRepo: func() (ghrepo.Interface, error) { remotes, err := remotesFunc() diff --git a/pkg/cmd/repo/repo.go b/pkg/cmd/repo/repo.go index 96b6d8aa76b..099a78e4180 100644 --- a/pkg/cmd/repo/repo.go +++ b/pkg/cmd/repo/repo.go @@ -1,6 +1,8 @@ package repo import ( + "os" + "fmt" "github.com/MakeNowJust/heredoc" repoCloneCmd "github.com/secman-team/gh-api/pkg/cmd/repo/clone" repoCreateCmd "github.com/secman-team/gh-api/pkg/cmd/repo/create" @@ -11,8 +13,25 @@ import ( repoViewCmd "github.com/secman-team/gh-api/pkg/cmd/repo/view" "github.com/secman-team/gh-api/pkg/cmdutil" "github.com/spf13/cobra" + "github.com/abdfnx/git_config" + "github.com/secman-team/gh-api/pkg/cmd/factory" + "github.com/secman-team/gh-api/pkg/iostreams" ) +type ColorScheme struct { + IO *iostreams.IOStreams +} + +func opts(f *cmdutil.Factory) ColorScheme { + opts := ColorScheme{ + IO: f.IOStreams, + } + + return opts +} + +var cs = opts(factory.New()).IO.ColorScheme() + func NewCmdRepo(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "repo ", @@ -39,5 +58,12 @@ func NewCmdRepo(f *cmdutil.Factory) *cobra.Command { cmd.AddCommand(creditsCmd.NewCmdRepoCredits(f, nil)) cmd.AddCommand(gardenCmd.NewCmdGarden(f, nil)) + username := git_config.GitConfig() + if username == ":username" { + fmt.Println("You're not authenticated, to authenticate run " + cs.Bold("secman auth login")) + + os.Exit(0) + } + return cmd }