Skip to content

feat: auto-create workflow during attestation #1416

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

Merged
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
14 changes: 8 additions & 6 deletions app/cli/cmd/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (

func newAttestationInitCmd() *cobra.Command {
var (
force bool
contractRevision int
attestationDryRun bool
workflowName string
projectName string
force bool
contractRevision int
attestationDryRun bool
workflowName string
projectName string
newWorkflowcontractName string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -59,7 +60,7 @@ func newAttestationInitCmd() *cobra.Command {
}

// Initialize it
attestationID, err := a.Run(cmd.Context(), contractRevision, projectName, workflowName)
attestationID, err := a.Run(cmd.Context(), contractRevision, projectName, workflowName, newWorkflowcontractName)
if err != nil {
if errors.Is(err, action.ErrAttestationAlreadyExist) {
return err
Expand Down Expand Up @@ -110,6 +111,7 @@ func newAttestationInitCmd() *cobra.Command {

cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow")
cobra.CheckErr(cmd.MarkFlagRequired("project"))
cmd.Flags().StringVar(&newWorkflowcontractName, "contract", "", "name of an existing contract to attach it to the auto-created workflow (it doesn't update an existing one)")

return cmd
}
20 changes: 14 additions & 6 deletions 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, projectName, workflowName string) (string, error) {
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, projectName, workflowName, newWorkflowContractName string) (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.

This changes the current behaviour a little bit. Currently, contract is not mandatory.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not mandatory here either. The name can be empty string

if action.dryRun && action.useRemoteState {
return "", errors.New("remote state is not compatible with dry-run mode")
}
Expand All @@ -85,7 +85,18 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr

action.Logger.Debug().Msg("Retrieving attestation definition")
client := pb.NewAttestationServiceClient(action.ActionsOpts.CPConnection)
// get information of the workflow
// 1 - Find or create the workflow
workflowsResp, err := client.FindOrCreateWorkflow(ctx, &pb.FindOrCreateWorkflowRequest{
ProjectName: projectName,
WorkflowName: workflowName,
ContractName: newWorkflowContractName,
})
if err != nil {
return "", err
}
workflow := workflowsResp.GetResult()

// 2 - Get contract
contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{
ContractRevision: int32(contractRevision),
WorkflowName: workflowName,
Expand All @@ -95,10 +106,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
return "", err
}

workflow := contractResp.GetResult().GetWorkflow()
contractVersion := contractResp.Result.GetContract()
contract := contractResp.GetResult().GetContract().GetV1()

workflowMeta := &clientAPI.WorkflowMetadata{
WorkflowId: workflow.GetId(),
Name: workflow.GetName(),
Expand All @@ -110,7 +118,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, pr
action.Logger.Debug().Msg("workflow contract and metadata retrieved from the control plane")

// Auto discover the runner context and enforce against the one in the contract if needed
discoveredRunner, err := crafter.DiscoverAndEnforceRunner(contract.GetRunner().GetType(), action.dryRun, action.Logger)
discoveredRunner, err := crafter.DiscoverAndEnforceRunner(contractVersion.GetV1().GetRunner().GetType(), action.dryRun, action.Logger)
if err != nil {
return "", ErrRunnerContextNotFound{err.Error()}
}
Expand Down
Loading
Loading