mirror of
https://github.com/vee1e/gittuf.git
synced 2026-09-04 19:57:04 +00:00
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// Copyright The gittuf Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package init
|
|
|
|
import (
|
|
"github.com/gittuf/gittuf/experimental/gittuf"
|
|
"github.com/gittuf/gittuf/internal/cmd/common"
|
|
"github.com/gittuf/gittuf/internal/cmd/policy/persistent"
|
|
"github.com/gittuf/gittuf/internal/policy"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type options struct {
|
|
p *persistent.Options
|
|
policyName string
|
|
}
|
|
|
|
func (o *options) AddFlags(cmd *cobra.Command) {
|
|
cmd.Flags().StringVar(
|
|
&o.policyName,
|
|
"policy-name",
|
|
policy.TargetsRoleName,
|
|
"name of policy file to create",
|
|
)
|
|
}
|
|
|
|
func (o *options) Run(cmd *cobra.Command, _ []string) error {
|
|
repo, err := gittuf.LoadRepository()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signer, err := gittuf.LoadSigner(repo, o.p.SigningKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return repo.InitializeTargets(cmd.Context(), signer, o.policyName, true)
|
|
}
|
|
|
|
func New(persistent *persistent.Options) *cobra.Command {
|
|
o := &options{p: persistent}
|
|
cmd := &cobra.Command{
|
|
Use: "init",
|
|
Short: "Initialize policy file",
|
|
PreRunE: common.CheckForSigningKeyFlag,
|
|
RunE: o.Run,
|
|
DisableAutoGenTag: true,
|
|
}
|
|
o.AddFlags(cmd)
|
|
|
|
return cmd
|
|
}
|