Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning to remember how to configure a custom Gitlab host #2816

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/cosign/git/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"

"github.com/sigstore/cosign/v2/internal/ui"
"github.com/sigstore/cosign/v2/pkg/cosign"
"github.com/sigstore/cosign/v2/pkg/cosign/env"
"github.com/xanzy/go-gitlab"
Expand Down Expand Up @@ -70,6 +71,7 @@ func (g *Gl) PutSecret(ctx context.Context, ref string, pf cosign.PassFunc) erro
EnvironmentScope: gitlab.String("*"),
})
if err != nil {
ui.Warnf(ctx, "If you are using a self-hosted gitlab please set the \"GITLAB_HOST\" your server name.")
return fmt.Errorf("could not create \"COSIGN_PASSWORD\" variable: %w", err)
}

Expand All @@ -78,7 +80,7 @@ func (g *Gl) PutSecret(ctx context.Context, ref string, pf cosign.PassFunc) erro
return fmt.Errorf("%s", bodyBytes)
}

fmt.Fprintln(os.Stderr, "Password written to \"COSIGN_PASSWORD\" variable")
ui.Infof(ctx, "Password written to \"COSIGN_PASSWORD\" variable")

_, privateKeyResp, err := client.ProjectVariables.CreateVariable(ref, &gitlab.CreateProjectVariableOptions{
Key: gitlab.String("COSIGN_PRIVATE_KEY"),
Expand All @@ -96,7 +98,7 @@ func (g *Gl) PutSecret(ctx context.Context, ref string, pf cosign.PassFunc) erro
return fmt.Errorf("%s", bodyBytes)
}

fmt.Fprintln(os.Stderr, "Private key written to \"COSIGN_PRIVATE_KEY\" variable")
ui.Infof(ctx, "Private key written to \"COSIGN_PRIVATE_KEY\" variable")

_, publicKeyResp, err := client.ProjectVariables.CreateVariable(ref, &gitlab.CreateProjectVariableOptions{
Key: gitlab.String("COSIGN_PUBLIC_KEY"),
Expand All @@ -114,12 +116,12 @@ func (g *Gl) PutSecret(ctx context.Context, ref string, pf cosign.PassFunc) erro
return fmt.Errorf("%s", bodyBytes)
}

fmt.Fprintln(os.Stderr, "Public key written to \"COSIGN_PUBLIC_KEY\" variable")
ui.Infof(ctx, "Public key written to \"COSIGN_PUBLIC_KEY\" variable")

if err := os.WriteFile("cosign.pub", keys.PublicBytes, 0o600); err != nil {
return err
}
fmt.Fprintln(os.Stderr, "Public key also written to cosign.pub")
ui.Infof(ctx, "Public key also written to cosign.pub")

return nil
}
Expand Down