Skip to content

feat(policy): add policy develop init#2229

Merged
migmartri merged 6 commits into
chainloop-dev:mainfrom
Piskoo:feat-add-policy-develop-init
Jul 16, 2025
Merged

feat(policy): add policy develop init#2229
migmartri merged 6 commits into
chainloop-dev:mainfrom
Piskoo:feat-add-policy-develop-init

Conversation

@Piskoo

@Piskoo Piskoo commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

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
Comment thread app/cli/cmd/policy_develop.go Outdated
func newPolicyDevelopCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "develop",
Aliases: []string{"dev"},

Copy link
Copy Markdown
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

Comment thread app/cli/cmd/policy_develop_init.go Outdated
chainloop policy develop init

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

Copy link
Copy Markdown
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.

Comment thread app/cli/cmd/policy_develop.go Outdated
cmd := &cobra.Command{
Use: "develop",
Aliases: []string{"dev"},
Short: "Tools for policy development",

Copy link
Copy Markdown
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

Comment thread app/cli/internal/policy/init/init.go Outdated
// See the License for the specific language governing permissions and
// limitations under the License.

package policy

Copy link
Copy Markdown
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?

Comment thread app/cli/internal/policy/init/init.go
}

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

Copy link
Copy Markdown
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
Copy Markdown
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

Piskoo added 4 commits July 14, 2025 14:35
…ackage structure

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@migmartri migmartri requested a review from javirln July 15, 2025 10:11
@migmartri

Copy link
Copy Markdown
Member

@javirln ptal once you have a sec

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@migmartri migmartri merged commit 04ddb1b into chainloop-dev:main Jul 16, 2025
13 checks passed
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