Skip to content

Commit 6e0001c

Browse files
committed
Enhance SSL support for p4 provider
1 parent 603d9a1 commit 6e0001c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

agent/vcs/p4.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,32 @@ func (p *P4Provider) Checkout(ctx context.Context, url, ref, pipeline, destDir s
3838
p.p4.SetPassword(passwd)
3939
}
4040

41-
if _, err := p.p4.Connect(); err != nil {
41+
// For SSL servers, set up a trust file so the API can persist fingerprints.
42+
if strings.HasPrefix(url, "ssl:") {
43+
trustFile := os.Getenv("P4TRUST")
44+
if trustFile == "" {
45+
trustFile = filepath.Join(os.TempDir(), ".p4trust")
46+
os.Setenv("P4TRUST", trustFile)
47+
}
48+
p.p4.SetTrustFile(trustFile)
49+
}
50+
51+
if connected, err := p.p4.Connect(); !connected {
4252
return CheckoutResult{}, fmt.Errorf("p4 connect failed: %w", err)
4353
}
4454

55+
// Accept the server fingerprint for SSL connections.
56+
if strings.HasPrefix(url, "ssl:") {
57+
p.p4.Run("trust", "-y")
58+
}
59+
60+
// Authenticate using RunLogin() which feeds the password via SetInput.
61+
if os.Getenv("P4PASSWD") != "" {
62+
if _, err := p.p4.RunLogin(); err != nil {
63+
return CheckoutResult{}, fmt.Errorf("p4 login failed: %w", err)
64+
}
65+
}
66+
4567
// Normalize ref: ensure it ends with /
4668
depotBase := strings.TrimRight(ref, "/")
4769

0 commit comments

Comments
 (0)