MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Run

Method Run

app/cli/pkg/action/attestation_init.go:110–368  ·  view source on GitHub ↗
(ctx context.Context, opts *AttestationInitRunOpts)

Source from the content-addressed store, hash-verified

108}
109
110func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRunOpts) (string, error) {
111 if action.dryRun && action.useRemoteState {
112 return "", errors.New("remote state is not compatible with dry-run mode")
113 }
114
115 // During local initializations we need to make sure if there is already an attestation in progress
116 // If it is and we are not "forcing" the initialization, we should return an error
117 if !action.useRemoteState && !action.force {
118 if initialized, _ := action.c.AlreadyInitialized(ctx, ""); initialized {
119 return "", ErrAttestationAlreadyExist
120 }
121 }
122
123 action.Logger.Debug().Msg("Retrieving attestation definition")
124 client := pb.NewAttestationServiceClient(action.CPConnection)
125
126 req := &pb.FindOrCreateWorkflowRequest{
127 ProjectName: opts.ProjectName,
128 WorkflowName: opts.WorkflowName,
129 }
130
131 // contractRef can be either the name of an existing contract or a file or URL of a contract to be created or updated
132 // we'll try to figure out which one of those cases we are dealing with
133 if opts.NewWorkflowContractRef != "" {
134 raw, err := LoadFileOrURL(opts.NewWorkflowContractRef)
135 if err != nil {
136 req.ContractName = opts.NewWorkflowContractRef
137 } else {
138 req.ContractBytes = raw
139 }
140 }
141
142 // 1 - Find or create the workflow
143 workflowsResp, err := client.FindOrCreateWorkflow(ctx, req)
144 if err != nil {
145 return "", err
146 }
147 workflow := workflowsResp.GetResult()
148
149 // Show warning if newer contract revision exists
150 if opts.ContractRevision > 0 && int32(opts.ContractRevision) < workflow.ContractRevisionLatest {
151 action.Logger.Warn().
152 Msgf("Newer contract revision available: %d, pinned version: %d", workflow.ContractRevisionLatest, opts.ContractRevision)
153 }
154
155 // 2 - Get contract
156 contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{
157 ContractRevision: int32(opts.ContractRevision),
158 WorkflowName: opts.WorkflowName,
159 ProjectName: opts.ProjectName,
160 })
161 if err != nil {
162 return "", err
163 }
164
165 contractVersion := contractResp.Result.GetContract()
166 workflowMeta := &clientAPI.WorkflowMetadata{
167 WorkflowId: workflow.GetId(),

Callers 1

newAttestationInitCmdFunction · 0.95

Calls 15

FindOrCreateWorkflowMethod · 0.95
GetContractMethod · 0.95
InitMethod · 0.95
RenderStatementMethod · 0.95
DiscoverAndEnforceRunnerFunction · 0.92
NewPRMetadataCollectorFunction · 0.92
NewAttestationRendererFunction · 0.92
WithLoggerFunction · 0.92
LoadFileOrURLFunction · 0.85
parseContractV2Function · 0.85

Tested by

no test coverage detected