MCPcopy Index your code
hub / github.com/coder/coder / buildTx

Method buildTx

coderd/wsbuilder/wsbuilder.go:372–628  ·  view source on GitHub ↗

buildTx contains the business logic of computing a new build. Attributes of the new database objects are computed in a functional style, rather than imperative, to emphasize the logic of how they are defined. A simple cache of database-fetched objects is stored on the struct to ensure we only fetc

(authFunc func(action policy.Action, object rbac.Objecter) bool)

Source from the content-addressed store, hash-verified

370//
371// In order to utilize this cache, the functions that compute build attributes use a pointer receiver type.
372func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Objecter) bool) (
373 *database.WorkspaceBuild, *database.ProvisionerJob, []database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow, error,
374) {
375 if authFunc != nil {
376 err := b.authorize(authFunc)
377 if err != nil {
378 return nil, nil, nil, err
379 }
380 }
381 err := b.checkTemplateVersionMatchesTemplate()
382 if err != nil {
383 return nil, nil, nil, err
384 }
385 err = b.checkTemplateJobStatus()
386 if err != nil {
387 return nil, nil, nil, err
388 }
389 err = b.checkUsage()
390 if err != nil {
391 return nil, nil, nil, err
392 }
393 err = b.checkRunningBuild()
394 if err != nil {
395 return nil, nil, nil, err
396 }
397
398 template, err := b.getTemplate()
399 if err != nil {
400 return nil, nil, nil, BuildError{http.StatusInternalServerError, "failed to fetch template", err}
401 }
402
403 templateVersionJob, err := b.getTemplateVersionJob()
404 if err != nil {
405 return nil, nil, nil, BuildError{
406 http.StatusInternalServerError, "failed to fetch template version job", err,
407 }
408 }
409
410 // if we haven't been told specifically who initiated, default to owner
411 if b.initiator == uuid.Nil {
412 b.initiator = b.workspace.OwnerID
413 }
414 // default reason is initiator
415 if b.reason == "" {
416 b.reason = database.BuildReasonInitiator
417 }
418
419 workspaceBuildID := uuid.New()
420 input, err := json.Marshal(provisionerdserver.WorkspaceProvisionJob{
421 WorkspaceBuildID: workspaceBuildID,
422 LogLevel: b.logLevel,
423 PrebuiltWorkspaceBuildStage: b.prebuiltWorkspaceBuildStage,
424 })
425 if err != nil {
426 return nil, nil, nil, BuildError{
427 http.StatusInternalServerError,
428 "marshal provision job",
429 err,

Callers 1

BuildMethod · 0.95

Calls 15

authorizeMethod · 0.95
checkUsageMethod · 0.95
checkRunningBuildMethod · 0.95
getTemplateMethod · 0.95
getTemplateVersionJobMethod · 0.95
getProvisionerTagsMethod · 0.95
getTemplateVersionIDMethod · 0.95
getBuildNumberMethod · 0.95
getStateMethod · 0.95
getParametersMethod · 0.95

Tested by

no test coverage detected