Skip to content

Commit 36efff6

Browse files
committed
verify key
1 parent 12ed8d1 commit 36efff6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/up/context.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,30 @@ func backfillConsoleContext(man *manifest.ProjectManifest) error {
152152
return fmt.Errorf("found non-ssh upstream url %s, please reclone the repo with SSH and retry", url)
153153
}
154154

155+
if err := verifySSHKey(contents, url); err != nil {
156+
return err
157+
}
158+
155159
console["repo_url"] = url
156160
console["private_key"] = contents
157161
ctx.Configuration["console"] = console
158162
return ctx.Write(path)
159163
}
164+
165+
func verifySSHKey(key, url string) error {
166+
dir, err := os.MkdirTemp("", "repo")
167+
if err != nil {
168+
return err
169+
}
170+
defer func(path string) {
171+
err := os.RemoveAll(path)
172+
if err != nil {
173+
return
174+
}
175+
}(dir)
176+
auth, _ := git.SSHAuth("git", key, "")
177+
if _, err := git.Clone(auth, url, dir); err != nil {
178+
return err
179+
}
180+
return nil
181+
}

0 commit comments

Comments
 (0)