|
| 1 | +// Copyright 2022 SLSA Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package main |
| 16 | + |
| 17 | +import ( |
| 18 | + "errors" |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | + |
| 22 | + // Enable the github OIDC auth provider. |
| 23 | + _ "github.com/sigstore/cosign/pkg/providers/github" |
| 24 | + "github.com/slsa-framework/slsa-github-generator/signing/sigstore" |
| 25 | + |
| 26 | + "github.com/spf13/cobra" |
| 27 | +) |
| 28 | + |
| 29 | +func checkExit(err error) { |
| 30 | + if err != nil { |
| 31 | + fmt.Fprintln(os.Stderr, err) |
| 32 | + os.Exit(1) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func rootCmd() *cobra.Command { |
| 37 | + c := &cobra.Command{ |
| 38 | + Use: "slsa-github-generator", |
| 39 | + Short: "Generate SLSA provenance for Github Actions", |
| 40 | + Long: `Generate SLSA provenance for Github Actions. |
| 41 | +For more information on SLSA, visit https://slsa.dev`, |
| 42 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 43 | + return errors.New("expected command") |
| 44 | + }, |
| 45 | + } |
| 46 | + c.AddCommand(versionCmd()) |
| 47 | + c.AddCommand(provenanceCmd(nil, checkExit, sigstore.NewDefaultFulcio(), sigstore.NewDefaultRekor())) |
| 48 | + c.AddCommand(ciCmd(checkExit)) |
| 49 | + c.AddCommand(packCmd(checkExit)) |
| 50 | + c.AddCommand(publishCmd(checkExit)) |
| 51 | + c.AddCommand(runCmd(checkExit)) |
| 52 | + return c |
| 53 | +} |
| 54 | + |
| 55 | +func main() { |
| 56 | + checkExit(rootCmd().Execute()) |
| 57 | +} |
0 commit comments