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

Function insertAgentApp

coderd/provisionerdserver/provisionerdserver.go:3646–3751  ·  view source on GitHub ↗
(ctx context.Context, db database.Store, agentID uuid.UUID, app *sdkproto.App, appSlugs map[string]struct{}, snapshot *telemetry.Snapshot)

Source from the content-addressed store, hash-verified

3644}
3645
3646func insertAgentApp(ctx context.Context, db database.Store, agentID uuid.UUID, app *sdkproto.App, appSlugs map[string]struct{}, snapshot *telemetry.Snapshot) error {
3647 // Similar logic is duplicated in terraform/resources.go.
3648 slug := app.Slug
3649 if slug == "" {
3650 return xerrors.Errorf("app must have a slug or name set")
3651 }
3652 // Unlike agent names, app slugs were never permitted to contain uppercase
3653 // letters or underscores.
3654 if !provisioner.AppSlugRegex.MatchString(slug) {
3655 return xerrors.Errorf("app slug %q does not match regex %q", slug, provisioner.AppSlugRegex.String())
3656 }
3657 if _, exists := appSlugs[slug]; exists {
3658 return xerrors.Errorf("duplicate app slug, must be unique per template: %q", slug)
3659 }
3660 appSlugs[slug] = struct{}{}
3661
3662 health := database.WorkspaceAppHealthDisabled
3663 healthcheck := app.GetHealthcheck()
3664 if healthcheck == nil {
3665 healthcheck = &sdkproto.Healthcheck{}
3666 }
3667 if healthcheck.Url != "" {
3668 health = database.WorkspaceAppHealthInitializing
3669 }
3670
3671 sharingLevel := database.AppSharingLevelOwner
3672 switch app.SharingLevel {
3673 case sdkproto.AppSharingLevel_AUTHENTICATED:
3674 sharingLevel = database.AppSharingLevelAuthenticated
3675 case sdkproto.AppSharingLevel_PUBLIC:
3676 sharingLevel = database.AppSharingLevelPublic
3677 }
3678
3679 displayGroup := sql.NullString{
3680 Valid: app.Group != "",
3681 String: app.Group,
3682 }
3683
3684 openIn := database.WorkspaceAppOpenInSlimWindow
3685 switch app.OpenIn {
3686 case sdkproto.AppOpenIn_TAB:
3687 openIn = database.WorkspaceAppOpenInTab
3688 case sdkproto.AppOpenIn_SLIM_WINDOW:
3689 openIn = database.WorkspaceAppOpenInSlimWindow
3690 }
3691
3692 var appID string
3693 if app.Id == "" || app.Id == uuid.Nil.String() {
3694 appID = uuid.NewString()
3695 } else {
3696 appID = app.Id
3697 }
3698 id, err := uuid.Parse(appID)
3699 if err != nil {
3700 return xerrors.Errorf("parse app uuid: %w", err)
3701 }
3702
3703 // If workspace apps are "persistent", the ID will not be regenerated across workspace builds, so we have to upsert.

Callers 2

InsertWorkspaceResourceFunction · 0.85

Calls 8

NowFunction · 0.92
ConvertWorkspaceAppFunction · 0.92
ParseMethod · 0.65
UpsertWorkspaceAppMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45
GetHealthcheckMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected