Skip to content

Commit

Permalink
refactor: use publicKey field to avoid permission errors on privateKey (
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jan 17, 2024
1 parent da49567 commit af1bc20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type Project struct {
Name string `json:"name,omitempty"`
GitURL string `json:"gitUrl,omitempty"`
PrivateKey string `json:"privateKey,omitempty"`
PublicKey string `json:"publicKey,omitempty"`
Subfolder string `json:"subfolder,omitempty"`
RouterPattern string `json:"routerPattern,omitempty"`
Branches string `json:"branches,omitempty"`
Expand Down
17 changes: 8 additions & 9 deletions pkg/lagoon/projects/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/uselagoon/lagoon-cli/pkg/api"
"github.com/uselagoon/lagoon-cli/pkg/graphql"
"github.com/uselagoon/lagoon-cli/pkg/output"
"golang.org/x/crypto/ssh"
)

// Projects .
Expand Down Expand Up @@ -233,8 +232,14 @@ func (p *Projects) GetProjectKey(projectName string, revealValue bool) ([]byte,
Name: projectName,
}
keyFragment := `fragment Project on Project {
privateKey
publicKey
}`
if revealValue {
keyFragment = `fragment Project on Project {
privateKey
publicKey
}`
}
projectByName, err := p.api.GetProjectByName(project, keyFragment)
if err != nil {
return []byte(""), err
Expand All @@ -252,15 +257,9 @@ func processProjectKey(projectByName []byte, revealValue bool) ([]byte, error) {
if err != nil {
return []byte(""), err
}
signer, err := ssh.ParsePrivateKey([]byte(project.PrivateKey))
if err != nil {
fmt.Println("Error was:", err.Error())
return []byte(""), err
}
publicKey := signer.PublicKey()
// get the key, but strip the newlines we don't need
projectData := []string{
strings.TrimSuffix(string(ssh.MarshalAuthorizedKey(publicKey)), "\n"),
strings.TrimSuffix(project.PublicKey, "\n"),
}
if revealValue {
projectData = append(projectData, strings.TrimSuffix(project.PrivateKey, "\n"))
Expand Down

0 comments on commit af1bc20

Please sign in to comment.