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
6 changed files
with
246 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package appscode | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/appscode/go/term" | ||
"github.com/howeyc/gopass" | ||
"github.com/skratchdot/open-golang/open" | ||
) | ||
|
||
func IssueToken() error { | ||
teamId := term.Read("Team Id:") | ||
endpoint := fmt.Sprintf("https://%v.appscode.io", teamId) | ||
err := open.Start(strings.Join([]string{endpoint, "conduit", "login"}, "/")) | ||
|
||
term.Print("Paste the token here: ") | ||
tokenBytes, err := gopass.GetPasswdMasked() | ||
if err != nil { | ||
term.Fatalln("Failed to retrieve token", err) | ||
} | ||
|
||
token := string(tokenBytes) | ||
client := &ConduitClient{ | ||
Url: strings.Join([]string{endpoint, "api", "user.whoami"}, "/"), | ||
Token: token, | ||
} | ||
result := &WhoAmIResponse{} | ||
err = client.Call().Into(result) | ||
if err != nil { | ||
term.Fatalln("Failed to validate token", err) | ||
} | ||
if result.ErrorCode != nil { | ||
term.Fatalln("Failed to validate token") | ||
} | ||
term.Successln("Token successfully generated") | ||
|
||
return err | ||
} |
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,57 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/appscode/go/ioutil" | ||
"github.com/appscode/go/term" | ||
"k8s.io/client-go/tools/clientcmd" | ||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" | ||
"k8s.io/client-go/util/homedir" | ||
) | ||
|
||
func AddAuthInfoToKubeConfig(email string, authInfo *clientcmdapi.AuthInfo) error { | ||
var konfig *clientcmdapi.Config | ||
if _, err := os.Stat(KubeConfigPath()); err == nil { | ||
// ~/.kube/config exists | ||
konfig, err = clientcmd.LoadFromFile(KubeConfigPath()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bakFile := KubeConfigPath() + ".bak." + time.Now().Format("2006-01-02T15-04") | ||
err = ioutil.CopyFile(bakFile, KubeConfigPath()) | ||
if err != nil { | ||
return err | ||
} | ||
term.Infoln(fmt.Sprintf("Current Kubeconfig is backed up as %s.", bakFile)) | ||
} else { | ||
konfig = &clientcmdapi.Config{ | ||
APIVersion: "v1", | ||
Kind: "Config", | ||
Preferences: clientcmdapi.Preferences{ | ||
Colors: true, | ||
}, | ||
} | ||
} | ||
|
||
konfig.AuthInfos[email] = authInfo | ||
|
||
err := os.MkdirAll(filepath.Dir(KubeConfigPath()), 0755) | ||
if err != nil { | ||
return err | ||
} | ||
err = clientcmd.WriteToFile(*konfig, KubeConfigPath()) | ||
if err != nil { | ||
return err | ||
} | ||
term.Successln("Configuration has been written to", KubeConfigPath()) | ||
return nil | ||
} | ||
|
||
func KubeConfigPath() string { | ||
return homedir.HomeDir() + "/.kube/config" | ||
} |
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,12 @@ | ||
package github | ||
|
||
import ( | ||
"github.com/appscode/go/term" | ||
"github.com/skratchdot/open-golang/open" | ||
) | ||
|
||
func IssueToken() { | ||
codeURurl := "https://github.com/settings/tokens/new" | ||
term.Infoln("Github url for personal access tokens:", codeURurl) | ||
open.Start(codeURurl) | ||
} |
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,12 @@ | ||
package gitlab | ||
|
||
import ( | ||
"github.com/appscode/go/term" | ||
"github.com/skratchdot/open-golang/open" | ||
) | ||
|
||
func IssueToken() { | ||
codeURurl := "https://gitlab.com/profile/personal_access_tokens" | ||
term.Infoln("Gitlab url for personal access tokens:", codeURurl) | ||
open.Start(codeURurl) | ||
} |
Oops, something went wrong.