Skip to content

Commit

Permalink
fix: extract key value
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufhm committed May 7, 2022
1 parent a71e549 commit 2afb1e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/rockpool/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *Rockpool) CreateRegistry() {
return
}

fmt.Println("[rockpool] creating registry...")
fmt.Println("[rockpool] creating registry")
_, err := exec.Command("k3d", "registry", "create", "rockpool-registry").Output()
if err != nil {
fmt.Println("[rockpool] unable to create registry: ", err)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (r *Rockpool) StartCluster(cn string) {
fmt.Printf("[%s] cluster does not exist\n", cn)
return
}
fmt.Printf("[%s] starting cluster...\n", cn)
fmt.Printf("[%s] starting cluster\n", cn)
// _, err := exec.Command(r.State.BinaryPaths["k3d"], "cluster", "start", cn).Output()
_, err := internal.RunCmdWithProgress(exec.Command(r.State.BinaryPaths["k3d"], "cluster", "start", cn))
if err != nil {
Expand All @@ -142,7 +142,7 @@ func (r *Rockpool) StopCluster(cn string) {
fmt.Printf("[%s] cluster does not exist\n", cn)
return
}
fmt.Printf("[%s] stopping cluster...\n", cn)
fmt.Printf("[%s] stopping cluster\n", cn)
_, err := internal.RunCmdWithProgress(exec.Command(r.State.BinaryPaths["k3d"], "cluster", "stop", cn))
if err != nil {
fmt.Printf("[%s] unable to stop cluster: %s\n", cn, internal.GetCmdStdErr(err))
Expand All @@ -163,7 +163,7 @@ func (r *Rockpool) DeleteCluster(cn string) {
return
}
r.StopCluster(cn)
fmt.Printf("[%s] deleting cluster...\n", cn)
fmt.Printf("[%s] deleting cluster\n", cn)
_, err := exec.Command(r.State.BinaryPaths["k3d"], "cluster", "delete", cn).Output()
if err != nil {
fmt.Printf("[%s] unable to delete cluster: %s\n", cn, err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/rockpool/lagoon-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var lagoonUserinfo struct {
}

func (r *Rockpool) lagoonFetchApiToken() string {
fmt.Println("[rockpool] fetching lagoon api token...")
fmt.Println("[rockpool] fetching lagoon api token")
_, password := r.KubeGetSecret(r.ControllerClusterName(),
"lagoon-core",
"lagoon-core-keycloak",
Expand Down Expand Up @@ -97,6 +97,7 @@ func (r *Rockpool) LagoonApiAddSshKey() {
r.LagoonApiFetchUserInfo()
for _, k := range lagoonUserinfo.Me.SshKeys {
if k.KeyFingerprint == keyFingerpint {
fmt.Println("[rockpool] lagoon ssh key had already been added")
return
}
}
Expand All @@ -116,6 +117,7 @@ func (r *Rockpool) LagoonApiAddSshKey() {
"userEmail": graphql.String(lagoonUserinfo.Me.Email),
"userId": graphql.String(lagoonUserinfo.Me.Id),
}
fmt.Println("[rockpool] adding lagoon ssh key")
err := r.GqlClient.Mutate(context.Background(), &m, vars)
if err != nil {
fmt.Printf("[rockpool] error adding Lagoon ssh key %s: %#v\n", cmt, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/rockpool/lagoon-components.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *Rockpool) AddHarborHostEntries(cn string) {

hostsContent, _ := r.DockerExec(n.Name, "cat /etc/hosts")
if !strings.Contains(string(hostsContent), entry) {
fmt.Printf("[%s] adding harbor host entries...\n", n.Name)
fmt.Printf("[%s] adding harbor host entries\n", n.Name)
_, err := r.DockerExec(n.Name, entryCmdStr)
if err != nil {
fmt.Printf("[%s] error adding harbor host entry: %s\n", cn, internal.GetCmdStdErr(err))
Expand Down
4 changes: 2 additions & 2 deletions pkg/rockpool/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"golang.org/x/crypto/ssh"
)
Expand All @@ -30,10 +31,9 @@ func (r *Rockpool) SshGetPublicKey() []byte {

func (r *Rockpool) SshGetPublicKeyFingerprint() (string, string, string, string) {
key := r.SshGetPublicKey()

pk, comment, _, _, err := ssh.ParseAuthorizedKey(key)
if err != nil {
panic(err)
}
return string(key), pk.Type(), ssh.FingerprintSHA256(pk), comment
return strings.Split(string(key), " ")[1], pk.Type(), ssh.FingerprintSHA256(pk), comment
}

0 comments on commit 2afb1e7

Please sign in to comment.