Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 14 additions & 9 deletions app/cli/cmd/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func newAttestationInitCmd() *cobra.Command {
contractRevision int
attestationDryRun bool
workflowName string
projectName string
)

cmd := &cobra.Command{
Expand All @@ -37,14 +38,14 @@ func newAttestationInitCmd() *cobra.Command {
Annotations: map[string]string{
useAPIToken: "true",
},
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(_ *cobra.Command, _ []string) error {
if workflowName == "" {
return errors.New("workflow name is required, set it via --name flag")
return errors.New("workflow name is required, set it via --workflow flag")
Copy link
Member Author

Choose a reason for hiding this comment

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

I got some feedback from @juamedgod that --name was confusing since it seemed the name of the attestation itself.

So I have changed it to workflow while keeping the existing --name as deprecated

}

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
a, err := action.NewAttestationInit(
&action.AttestationInitOpts{
ActionsOpts: actionOpts,
Expand All @@ -58,7 +59,7 @@ func newAttestationInitCmd() *cobra.Command {
}

// Initialize it
attestationID, err := a.Run(cmd.Context(), contractRevision, workflowName)
attestationID, err := a.Run(cmd.Context(), contractRevision, projectName, workflowName)
if err != nil {
if errors.Is(err, action.ErrAttestationAlreadyExist) {
return err
Expand Down Expand Up @@ -86,7 +87,11 @@ func newAttestationInitCmd() *cobra.Command {
logger.Info().Msg("The attestation is being crafted in dry-run mode. It will not get stored once rendered")
}

return encodeOutput(res, simpleStatusTable)
if projectName == "" {
logger.Warn().Msg("DEPRECATION WARNING: --project not set, this will be required in the near future")
}

return encodeOutput(res, fullStatusTable)
},
}

Expand All @@ -96,10 +101,10 @@ func newAttestationInitCmd() *cobra.Command {
cmd.Flags().IntVar(&contractRevision, "contract-revision", 0, "revision of the contract to retrieve, \"latest\" by default")
cmd.Flags().BoolVar(&useAttestationRemoteState, "remote-state", false, "Store the attestation state remotely")

// workflow-name has been replaced by --name flag
cmd.Flags().StringVar(&workflowName, "workflow-name", "", "name of the workflow to run the attestation")
cobra.CheckErr(cmd.Flags().MarkHidden("workflow-name"))
// name has been replaced by --workflow flag
cmd.Flags().StringVar(&workflowName, "workflow", "", "name of the workflow to run the attestation")
cmd.Flags().StringVar(&workflowName, "name", "", "name of the workflow to run the attestation")

cobra.CheckErr(cmd.Flags().MarkDeprecated("name", "please use --workflow instead"))
cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow")
Copy link
Member Author

Choose a reason for hiding this comment

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

project is not yet fully enforced in the attestation init

return cmd
}
2 changes: 1 addition & 1 deletion app/cli/cmd/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b
gt.AppendSeparator()
meta := status.WorkflowMeta
gt.AppendRow(table.Row{"Attestation ID", status.AttestationID})
gt.AppendRow(table.Row{"Organization", meta.Organization})
gt.AppendRow(table.Row{"Name", meta.Name})
gt.AppendRow(table.Row{"Team", meta.Team})
Copy link
Member

Choose a reason for hiding this comment

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

Are we removing team in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, but I see no value in showing it, not sure

gt.AppendRow(table.Row{"Project", meta.Project})
gt.AppendRow(table.Row{"Contract Revision", meta.ContractRevision})
if status.RunnerContext.JobURL != "" {
Expand Down
9 changes: 6 additions & 3 deletions app/cli/cmd/workflow_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
)

func newWorkflowDeleteCmd() *cobra.Command {
var name string
var name, projectName string

cmd := &cobra.Command{
Use: "delete",
Short: "Delete an existing workflow",
RunE: func(cmd *cobra.Command, args []string) error {
err := action.NewWorkflowDelete(actionOpts).Run(name)
err := action.NewWorkflowDelete(actionOpts).Run(name, projectName)
if err == nil {
logger.Info().Msg("Workload deleted!")
logger.Info().Msg("Workflow deleted!")
}
return err
},
Expand All @@ -38,5 +38,8 @@ func newWorkflowDeleteCmd() *cobra.Command {
cmd.Flags().StringVar(&name, "name", "", "workflow name")
cobra.CheckErr(cmd.MarkFlagRequired("name"))

cmd.Flags().StringVar(&projectName, "project", "", "project name")
cobra.CheckErr(cmd.MarkFlagRequired("project"))
Copy link
Member Author

Choose a reason for hiding this comment

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

but it is in the rest of the APIs.


return cmd
}
6 changes: 4 additions & 2 deletions app/cli/cmd/workflow_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
)

func newWorkflowDescribeCmd() *cobra.Command {
var workflowName string
var workflowName, projectName string

cmd := &cobra.Command{
Use: "describe",
Short: "Describe an existing workflow",
RunE: func(cmd *cobra.Command, args []string) error {
wf, err := action.NewWorkflowDescribe(actionOpts).Run(cmd.Context(), workflowName)
wf, err := action.NewWorkflowDescribe(actionOpts).Run(cmd.Context(), workflowName, projectName)
if err != nil {
return err
}
Expand All @@ -39,5 +39,7 @@ func newWorkflowDescribeCmd() *cobra.Command {
cmd.Flags().StringVar(&workflowName, "name", "", "workflow name")
cobra.CheckErr(cmd.MarkFlagRequired("name"))

cmd.Flags().StringVar(&projectName, "project", "", "project name")
cobra.CheckErr(cmd.MarkFlagRequired("project"))
return cmd
}
10 changes: 4 additions & 6 deletions app/cli/cmd/workflow_update.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,9 +34,6 @@ func newWorkflowUpdateCmd() *cobra.Command {
if cmd.Flags().Changed("team") {
opts.Team = &team
}
if cmd.Flags().Changed("project") {
opts.Project = &project
}
if cmd.Flags().Changed("public") {
opts.Public = &public
}
Expand All @@ -49,7 +46,7 @@ func newWorkflowUpdateCmd() *cobra.Command {
opts.ContractName = &contractName
}

res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), name, opts)
res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), name, project, opts)
if err != nil {
return err
}
Expand All @@ -61,10 +58,11 @@ func newWorkflowUpdateCmd() *cobra.Command {

cmd.Flags().StringVar(&name, "name", "", "workflow name")
cobra.CheckErr(cmd.MarkFlagRequired("name"))
cmd.Flags().StringVar(&project, "project", "", "project name")
cobra.CheckErr(cmd.MarkFlagRequired("project"))

cmd.Flags().StringVar(&description, "description", "", "workflow description")
cmd.Flags().StringVar(&team, "team", "", "team name")
cmd.Flags().StringVar(&project, "project", "", "project name")
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")
cmd.Flags().StringVar(&contractName, "contract", "", "the name of an existing contract")

Expand Down
4 changes: 3 additions & 1 deletion app/cli/cmd/workflow_workflow_run_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
DefaultLimit: 20,
}

var workflowName, status string
var workflowName, projectName, status string

cmd := &cobra.Command{
Use: "list",
Expand All @@ -48,6 +48,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
res, err := action.NewWorkflowRunList(actionOpts).Run(
&action.WorkflowRunListOpts{
WorkflowName: workflowName,
ProjectName: projectName,
Pagination: &action.PaginationOpts{
Limit: paginationOpts.Limit,
NextCursor: paginationOpts.NextCursor,
Expand Down Expand Up @@ -79,6 +80,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
}

cmd.Flags().StringVar(&workflowName, "workflow", "", "workflow name")
cmd.Flags().StringVar(&projectName, "project", "", "project name")
cmd.Flags().BoolVar(&full, "full", false, "full report")
cmd.Flags().StringVar(&status, "status", "", fmt.Sprintf("filter by workflow run status: %v", listAvailableWorkflowStatusFlag()))
// Add pagination flags
Expand Down
4 changes: 3 additions & 1 deletion app/cli/internal/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
}

// returns the attestation ID
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, workflowName string) (string, error) {
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, projectName, workflowName string) (string, error) {
if action.dryRun && action.useRemoteState {
return "", errors.New("remote state is not compatible with dry-run mode")
}
Expand All @@ -89,6 +89,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, wo
contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{
ContractRevision: int32(contractRevision),
WorkflowName: workflowName,
ProjectName: projectName,
})
if err != nil {
return "", err
Expand Down Expand Up @@ -127,6 +128,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, wo
ContractRevision: int32(contractRevision),
// send the workflow name explicitly provided by the user to detect that functional case
WorkflowName: workflowName,
ProjectName: projectName,
},
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion app/cli/internal/action/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type AttestationResultRunnerContext struct {
}

type AttestationStatusWorkflowMeta struct {
WorkflowID, Name, Team, Project, ContractRevision string
WorkflowID, Name, Team, Project, ContractRevision, Organization string
}

type AttestationStatusResultMaterial struct {
Expand Down Expand Up @@ -94,6 +94,7 @@ func (action *AttestationStatus) Run(ctx context.Context, attestationID string)
WorkflowMeta: &AttestationStatusWorkflowMeta{
WorkflowID: workflowMeta.GetWorkflowId(),
Name: workflowMeta.GetName(),
Organization: workflowMeta.GetOrganization(),
Project: workflowMeta.GetProject(),
Team: workflowMeta.GetTeam(),
ContractRevision: workflowMeta.GetSchemaRevision(),
Expand Down
2 changes: 1 addition & 1 deletion app/cli/internal/action/workflow_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type NewWorkflowCreateOpts struct {
func (action *WorkflowCreate) Run(opts *NewWorkflowCreateOpts) (*WorkflowItem, error) {
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
resp, err := client.Create(context.Background(), &pb.WorkflowServiceCreateRequest{
Name: opts.Name, Project: opts.Project, Team: opts.Team, ContractName: opts.ContractName,
Name: opts.Name, ProjectName: opts.Project, Team: opts.Team, ContractName: opts.ContractName,
Description: opts.Description,
Public: opts.Public,
})
Expand Down
4 changes: 2 additions & 2 deletions app/cli/internal/action/workflow_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func NewWorkflowDelete(cfg *ActionsOpts) *WorkflowDelete {
return &WorkflowDelete{cfg}
}

func (action *WorkflowDelete) Run(name string) error {
func (action *WorkflowDelete) Run(name, projectName string) error {
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
if _, err := client.Delete(context.Background(), &pb.WorkflowServiceDeleteRequest{Name: name}); err != nil {
if _, err := client.Delete(context.Background(), &pb.WorkflowServiceDeleteRequest{Name: name, ProjectName: projectName}); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions app/cli/internal/action/workflow_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func NewWorkflowDescribe(cfg *ActionsOpts) *WorkflowDescribe {
return &WorkflowDescribe{cfg}
}

func (action *WorkflowDescribe) Run(ctx context.Context, name string) (*WorkflowItem, error) {
func (action *WorkflowDescribe) Run(ctx context.Context, name, projectName string) (*WorkflowItem, error) {
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)

req := &pb.WorkflowServiceViewRequest{Name: name}
req := &pb.WorkflowServiceViewRequest{Name: name, ProjectName: projectName}
resp, err := client.View(ctx, req)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions app/cli/internal/action/workflow_run_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func NewWorkflowRunList(cfg *ActionsOpts) *WorkflowRunList {
}

type WorkflowRunListOpts struct {
WorkflowName string
Pagination *PaginationOpts
Status string
WorkflowName, ProjectName string
Pagination *PaginationOpts
Status string
}
type PaginationOpts struct {
Limit int
Expand All @@ -76,6 +76,7 @@ func (action *WorkflowRunList) Run(opts *WorkflowRunListOpts) (*PaginatedWorkflo
client := pb.NewWorkflowRunServiceClient(action.cfg.CPConnection)
req := &pb.WorkflowRunServiceListRequest{
WorkflowName: opts.WorkflowName,
ProjectName: opts.ProjectName,
Pagination: &pb.CursorPaginationRequest{
Limit: int32(opts.Pagination.Limit),
Cursor: opts.Pagination.NextCursor,
Expand Down
8 changes: 4 additions & 4 deletions app/cli/internal/action/workflow_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ func NewWorkflowUpdate(cfg *ActionsOpts) *WorkflowUpdate {
}

type WorkflowUpdateOpts struct {
Description, Project, Team, ContractName *string
Public *bool
Description, Team, ContractName *string
Public *bool
}

func (action *WorkflowUpdate) Run(ctx context.Context, name string, opts *WorkflowUpdateOpts) (*WorkflowItem, error) {
func (action *WorkflowUpdate) Run(ctx context.Context, name, project string, opts *WorkflowUpdateOpts) (*WorkflowItem, error) {
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
resp, err := client.Update(ctx, &pb.WorkflowServiceUpdateRequest{
Name: name,
ProjectName: project,
Description: opts.Description,
Project: opts.Project,
Team: opts.Team,
Public: opts.Public,
ContractName: opts.ContractName,
Expand Down
Loading