-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
1,498 additions
and
5,285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kyoh86/gogh/v2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var tokens gogh.TokenManager | ||
|
||
var authCommand = &cobra.Command{ | ||
Use: "auth", | ||
Short: "Manage tokens", | ||
PersistentPostRunE: func(*cobra.Command, []string) error { | ||
return saveTokens() | ||
}, | ||
} | ||
|
||
func init() { | ||
configCommand.AddCommand(authCommand) | ||
facadeCommand.AddCommand(authCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/apex/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var authListCommand = &cobra.Command{ | ||
Use: "list", | ||
Short: "Listup authenticated host and owners", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
ctx, cancel := context.WithCancel(cmd.Context()) | ||
defer cancel() | ||
entries := tokens.Entries() | ||
if len(entries) == 0 { | ||
log.FromContext(ctx).Warn("No valid token found: you need to set token by `gogh auth login`") | ||
return nil | ||
} | ||
for _, entry := range entries { | ||
fmt.Println(entry) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
authCommand.AddCommand(authListCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/apex/log" | ||
"github.com/kyoh86/gogh/v2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var logoutCommand = &cobra.Command{ | ||
Use: "logout", | ||
Short: "Logout from the host and owner", | ||
RunE: func(cmd *cobra.Command, indices []string) error { | ||
if len(indices) == 0 { | ||
configured := tokens.Entries() | ||
if len(configured) == 0 { | ||
return nil | ||
} | ||
indices = make([]string, 0, len(configured)) | ||
for _, c := range configured { | ||
indices = append(indices, c.String()) | ||
} | ||
|
||
var selected []string | ||
if err := survey.AskOne(&survey.MultiSelect{ | ||
Message: "Hosts to logout from", | ||
Options: indices, | ||
}, &selected); err != nil { | ||
return err | ||
} | ||
indices = selected | ||
} | ||
|
||
for _, target := range indices { | ||
log.FromContext(cmd.Context()).WithField("target", target).Info("logout from") | ||
target, err := gogh.ParseTokenTarget(target) | ||
if err != nil { | ||
log.FromContext(cmd.Context()).WithField("target", target).Error("invalid target") | ||
continue | ||
} | ||
tokens.Delete(target.Host, target.Owner) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
authCommand.AddCommand(logoutCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.