Skip to content

feat(policy): add policy develop init #2229

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Piskoo
Copy link
Collaborator

@Piskoo Piskoo commented Jul 9, 2025

This PR adds policy develop init command

Usage:

$ chainloop policy develop init ./mypolicy

$ chainloop policy develop init ./mypolicy \
  --name="custom-policy" \
  --description="SBOM validation" \
  --embedded

Flags:

  • --name: Policy name
  • --description: Policy description
  • --embedded: Generate single-file policy with embedded rego script
  • --force, -f: Overwrite existing files

Part of #1108

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo marked this pull request as ready for review July 9, 2025 12:20
@Piskoo Piskoo changed the title feat(policy): add develop init feat(policy): add policy develop init Jul 9, 2025
func newPolicyDevelopCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "develop",
Aliases: []string{"dev"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Aliases: []string{"dev"},
Aliases: []string{"devel"},

this sounds a little bit better to me since it might represent a verb

chainloop policy develop init
# Initialize in specific directory with embedded format
chainloop policy develop init ./policies --embedded`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing that we do not do in any command in chainloop is to use arguments, we always use flags. The reason being that they are more flexible and easier to change in the future.

cmd := &cobra.Command{
Use: "develop",
Aliases: []string{"dev"},
Short: "Tools for policy development",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, it might make sense to add this link https://docs.chainloop.dev/guides/custom-policies

// See the License for the specific language governing permissions and
// limitations under the License.

package policy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might be able to simplify a little this package structure, I do not think you need to levels.

I'd just make

`internal/policy-devel`

and inside you can have an init.go file, same package but organized by functionality, would that work?

}

// Add custom template functions
func executeTemplate(content string, data *TemplateData) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding some unit tests?

@@ -0,0 +1,20 @@
apiVersion: policy.chainloop.dev/v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add some headers indicating that this is generated by the CLI, the link to the docs, etc, at the top

Other than that this is nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants