Skip to content

Commit 0b47fcc

Browse files
committed
refactor: cleanup backend code
1 parent 93cbbdc commit 0b47fcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+196
-133
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ blank_issues_enabled: false
22
contact_links:
33
- name: Track the Most Upvoted Features
44
url: https://upvotes.getarcane.app/
5+
about: Track the Most Upvoted Features
56
- name: 💬 Discord
67
url: https://discord.gg/WyXYpdyV3Z
78
about: For help and chatting with the community

backend/internal/api/diagnostics_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/getarcaneapp/arcane/backend/internal/middleware"
9-
ws "github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
9+
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
1010
"github.com/gin-gonic/gin"
1111
)
1212

backend/internal/api/ws_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/getarcaneapp/arcane/backend/internal/middleware"
2525
"github.com/getarcaneapp/arcane/backend/internal/services"
2626
docker "github.com/getarcaneapp/arcane/backend/pkg/dockerutil"
27-
ws "github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
27+
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
2828
httputil "github.com/getarcaneapp/arcane/backend/pkg/utils/httpx"
2929
systemtypes "github.com/getarcaneapp/arcane/types/system"
3030
"github.com/gin-gonic/gin"

backend/internal/api/ws_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
docker "github.com/getarcaneapp/arcane/backend/pkg/dockerutil"
16-
ws "github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
16+
"github.com/getarcaneapp/arcane/backend/pkg/libarcane/ws"
1717
systemtypes "github.com/getarcaneapp/arcane/types/system"
1818
"github.com/gin-gonic/gin"
1919
"github.com/gorilla/websocket"

backend/internal/bootstrap/jobs_bootstrap.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@ import (
88

99
"github.com/getarcaneapp/arcane/backend/internal/config"
1010
"github.com/getarcaneapp/arcane/backend/pkg/libarcane"
11-
pkg_scheduler "github.com/getarcaneapp/arcane/backend/pkg/scheduler"
11+
"github.com/getarcaneapp/arcane/backend/pkg/scheduler"
1212
)
1313

14-
func registerJobs(appCtx context.Context, newScheduler *pkg_scheduler.JobScheduler, appServices *Services, appConfig *config.Config) {
15-
autoUpdateJob := pkg_scheduler.NewAutoUpdateJob(appServices.Updater, appServices.Settings)
14+
func registerJobs(appCtx context.Context, newScheduler *scheduler.JobScheduler, appServices *Services, appConfig *config.Config) {
15+
autoUpdateJob := scheduler.NewAutoUpdateJob(appServices.Updater, appServices.Settings)
1616
newScheduler.RegisterJob(autoUpdateJob)
1717

18-
imagePollingJob := pkg_scheduler.NewImagePollingJob(appServices.ImageUpdate, appServices.Settings, appServices.Environment)
18+
imagePollingJob := scheduler.NewImagePollingJob(appServices.ImageUpdate, appServices.Settings, appServices.Environment)
1919
newScheduler.RegisterJob(imagePollingJob)
2020

21-
environmentHealthJob := pkg_scheduler.NewEnvironmentHealthJob(appServices.Environment, appServices.Settings)
21+
environmentHealthJob := scheduler.NewEnvironmentHealthJob(appServices.Environment, appServices.Settings)
2222
if !appConfig.AgentMode {
2323
newScheduler.RegisterJob(environmentHealthJob)
2424
}
2525

26-
analyticsJob := pkg_scheduler.NewAnalyticsJob(appServices.Settings, appServices.KV, nil, appConfig)
26+
analyticsJob := scheduler.NewAnalyticsJob(appServices.Settings, appServices.KV, nil, appConfig)
2727
newScheduler.RegisterJob(analyticsJob)
2828
// Send initial heartbeat on startup without blocking bootstrap.
2929
go analyticsJob.Run(appCtx)
3030

31-
eventCleanupJob := pkg_scheduler.NewEventCleanupJob(appServices.Event, appServices.Settings)
31+
eventCleanupJob := scheduler.NewEventCleanupJob(appServices.Event, appServices.Settings)
3232
newScheduler.RegisterJob(eventCleanupJob)
3333

34-
scheduledPruneJob := pkg_scheduler.NewScheduledPruneJob(appServices.System, appServices.Settings, appServices.Notification)
34+
scheduledPruneJob := scheduler.NewScheduledPruneJob(appServices.System, appServices.Settings, appServices.Notification)
3535
newScheduler.RegisterJob(scheduledPruneJob)
3636

37-
fsWatcherJob, err := pkg_scheduler.RegisterFilesystemWatcherJob(appCtx, appServices.Project, appServices.Template, appServices.Settings, appConfig.ProjectScanMaxDepth)
37+
fsWatcherJob, err := scheduler.RegisterFilesystemWatcherJob(appCtx, appServices.Project, appServices.Template, appServices.Settings, appConfig.ProjectScanMaxDepth)
3838
if err != nil {
3939
slog.ErrorContext(appCtx, "Failed to register filesystem watcher job", "error", err)
4040
}
4141

42-
gitOpsSyncJob := pkg_scheduler.NewGitOpsSyncJob(appServices.GitOpsSync, appServices.Settings)
42+
gitOpsSyncJob := scheduler.NewGitOpsSyncJob(appServices.GitOpsSync, appServices.Settings)
4343
newScheduler.RegisterJob(gitOpsSyncJob)
4444

45-
vulnerabilityScanJob := pkg_scheduler.NewVulnerabilityScanJob(appServices.Vulnerability, appServices.Settings)
45+
vulnerabilityScanJob := scheduler.NewVulnerabilityScanJob(appServices.Vulnerability, appServices.Settings)
4646
newScheduler.RegisterJob(vulnerabilityScanJob)
4747

48-
autoHealJob := pkg_scheduler.NewAutoHealJob(appServices.Docker, appServices.Settings, appServices.Event, appServices.Notification)
48+
autoHealJob := scheduler.NewAutoHealJob(appServices.Docker, appServices.Settings, appServices.Event, appServices.Notification)
4949
newScheduler.RegisterJob(autoHealJob)
5050

5151
setupJobScheduleCallbacks(
@@ -69,15 +69,15 @@ func setupJobScheduleCallbacks(
6969
lifecycleCtx context.Context,
7070
appServices *Services,
7171
appConfig *config.Config,
72-
newScheduler *pkg_scheduler.JobScheduler,
73-
imagePollingJob *pkg_scheduler.ImagePollingJob,
74-
autoUpdateJob *pkg_scheduler.AutoUpdateJob,
75-
environmentHealthJob *pkg_scheduler.EnvironmentHealthJob,
76-
eventCleanupJob *pkg_scheduler.EventCleanupJob,
77-
scheduledPruneJob *pkg_scheduler.ScheduledPruneJob,
78-
gitOpsSyncJob *pkg_scheduler.GitOpsSyncJob,
79-
vulnerabilityScanJob *pkg_scheduler.VulnerabilityScanJob,
80-
autoHealJob *pkg_scheduler.AutoHealJob,
72+
newScheduler *scheduler.JobScheduler,
73+
imagePollingJob *scheduler.ImagePollingJob,
74+
autoUpdateJob *scheduler.AutoUpdateJob,
75+
environmentHealthJob *scheduler.EnvironmentHealthJob,
76+
eventCleanupJob *scheduler.EventCleanupJob,
77+
scheduledPruneJob *scheduler.ScheduledPruneJob,
78+
gitOpsSyncJob *scheduler.GitOpsSyncJob,
79+
vulnerabilityScanJob *scheduler.VulnerabilityScanJob,
80+
autoHealJob *scheduler.AutoHealJob,
8181
) {
8282
if appServices.JobSchedule == nil {
8383
return
@@ -108,15 +108,15 @@ func handleJobScheduleChangeInternal(
108108
ctx context.Context,
109109
key string,
110110
appConfig *config.Config,
111-
newScheduler *pkg_scheduler.JobScheduler,
112-
imagePollingJob *pkg_scheduler.ImagePollingJob,
113-
autoUpdateJob *pkg_scheduler.AutoUpdateJob,
114-
environmentHealthJob *pkg_scheduler.EnvironmentHealthJob,
115-
eventCleanupJob *pkg_scheduler.EventCleanupJob,
116-
scheduledPruneJob *pkg_scheduler.ScheduledPruneJob,
117-
gitOpsSyncJob *pkg_scheduler.GitOpsSyncJob,
118-
vulnerabilityScanJob *pkg_scheduler.VulnerabilityScanJob,
119-
autoHealJob *pkg_scheduler.AutoHealJob,
111+
newScheduler *scheduler.JobScheduler,
112+
imagePollingJob *scheduler.ImagePollingJob,
113+
autoUpdateJob *scheduler.AutoUpdateJob,
114+
environmentHealthJob *scheduler.EnvironmentHealthJob,
115+
eventCleanupJob *scheduler.EventCleanupJob,
116+
scheduledPruneJob *scheduler.ScheduledPruneJob,
117+
gitOpsSyncJob *scheduler.GitOpsSyncJob,
118+
vulnerabilityScanJob *scheduler.VulnerabilityScanJob,
119+
autoHealJob *scheduler.AutoHealJob,
120120
) {
121121
switch key {
122122
case "pollingInterval":
@@ -157,7 +157,7 @@ func handleJobScheduleChangeInternal(
157157
}
158158
}
159159

160-
func setupSettingsCallbacks(lifecycleCtx context.Context, appServices *Services, appConfig *config.Config, newScheduler *pkg_scheduler.JobScheduler, imagePollingJob *pkg_scheduler.ImagePollingJob, autoUpdateJob *pkg_scheduler.AutoUpdateJob, environmentHealthJob *pkg_scheduler.EnvironmentHealthJob, fsWatcherJob *pkg_scheduler.FilesystemWatcherJob, scheduledPruneJob *pkg_scheduler.ScheduledPruneJob, vulnerabilityScanJob *pkg_scheduler.VulnerabilityScanJob, autoHealJob *pkg_scheduler.AutoHealJob) {
160+
func setupSettingsCallbacks(lifecycleCtx context.Context, appServices *Services, appConfig *config.Config, newScheduler *scheduler.JobScheduler, imagePollingJob *scheduler.ImagePollingJob, autoUpdateJob *scheduler.AutoUpdateJob, environmentHealthJob *scheduler.EnvironmentHealthJob, fsWatcherJob *scheduler.FilesystemWatcherJob, scheduledPruneJob *scheduler.ScheduledPruneJob, vulnerabilityScanJob *scheduler.VulnerabilityScanJob, autoHealJob *scheduler.AutoHealJob) {
161161
appServices.Settings.OnImagePollingSettingsChanged = func(_ context.Context) {
162162
if err := newScheduler.RescheduleJob(lifecycleCtx, imagePollingJob); err != nil {
163163
slog.WarnContext(lifecycleCtx, "Failed to reschedule image-polling job", "error", err)

backend/internal/bootstrap/router_bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func setupRouter(ctx context.Context, cfg *config.Config, appServices *Services)
119119
handlers.RegisterWebhookTrigger(apiGroup, appServices.Webhook) //nolint:contextcheck
120120

121121
apiGroup.Use(middleware.NewEnvProxyMiddlewareWithParam(
122-
types.LOCAL_DOCKER_ENVIRONMENT_ID,
122+
types.LocalDockerEnvironmentId,
123123
"id",
124124
envResolver,
125125
createAuthValidator(appServices),

backend/internal/common/errors.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,24 @@ func (e *ApiKeyNotFoundError) Error() string {
12051205
return "API key not found"
12061206
}
12071207

1208+
type ApiKeyExpiredError struct{}
1209+
1210+
func (e *ApiKeyExpiredError) Error() string {
1211+
return "API key has expired"
1212+
}
1213+
1214+
type ApiKeyInvalidError struct{}
1215+
1216+
func (e *ApiKeyInvalidError) Error() string {
1217+
return "invalid API key"
1218+
}
1219+
1220+
type ApiKeyProtectedError struct{}
1221+
1222+
func (e *ApiKeyProtectedError) Error() string {
1223+
return "API key is protected"
1224+
}
1225+
12081226
type ApiKeyUpdateError struct {
12091227
Err error
12101228
}

backend/internal/huma/handlers/apikeys.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ func (h *ApiKeyHandler) UpdateApiKey(ctx context.Context, input *UpdateApiKeyInp
256256

257257
apiKey, err := h.apiKeyService.UpdateApiKey(ctx, input.ID, input.Body)
258258
if err != nil {
259-
if errors.Is(err, services.ErrApiKeyNotFound) {
259+
if _, ok := errors.AsType[*common.ApiKeyNotFoundError](err); ok {
260260
return nil, huma.Error404NotFound((&common.ApiKeyNotFoundError{}).Error())
261261
}
262-
if errors.Is(err, services.ErrApiKeyProtected) {
262+
if _, ok := errors.AsType[*common.ApiKeyProtectedError](err); ok {
263263
return nil, huma.Error403Forbidden("static API keys cannot be updated")
264264
}
265265
return nil, huma.Error500InternalServerError((&common.ApiKeyUpdateError{Err: err}).Error())
@@ -285,10 +285,10 @@ func (h *ApiKeyHandler) DeleteApiKey(ctx context.Context, input *DeleteApiKeyInp
285285
}
286286

287287
if err := h.apiKeyService.DeleteApiKey(ctx, input.ID); err != nil {
288-
if errors.Is(err, services.ErrApiKeyNotFound) {
288+
if _, ok := errors.AsType[*common.ApiKeyNotFoundError](err); ok {
289289
return nil, huma.Error404NotFound((&common.ApiKeyNotFoundError{}).Error())
290290
}
291-
if errors.Is(err, services.ErrApiKeyProtected) {
291+
if _, ok := errors.AsType[*common.ApiKeyProtectedError](err); ok {
292292
return nil, huma.Error403Forbidden("static API keys cannot be deleted")
293293
}
294294
return nil, huma.Error500InternalServerError((&common.ApiKeyDeletionError{Err: err}).Error())

backend/internal/huma/handlers/containers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ContainerHandler struct {
2525
settingsService *services.SettingsService
2626
}
2727

28-
// Paginated response
28+
// ContainerPaginatedResponse response
2929
type ContainerPaginatedResponse struct {
3030
Success bool `json:"success"`
3131
Data []containertypes.Summary `json:"data"`
@@ -121,7 +121,7 @@ type DeleteContainerOutput struct {
121121
Body ContainerActionResponse
122122
}
123123

124-
// RegisterContainers registers container endpoints.
124+
// SetAutoUpdateInput sets the auto update value for a container.
125125
type SetAutoUpdateInput struct {
126126
EnvironmentID string `path:"id" doc:"Environment ID"`
127127
ContainerID string `path:"containerId" doc:"Container ID"`

backend/internal/huma/handlers/environments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func (h *EnvironmentHandler) createEnvironmentWithApiKey(ctx context.Context, en
464464
func (h *EnvironmentHandler) createEnvironmentLegacy(ctx context.Context, env *models.Environment, user *models.User, body environment.Create) (*CreateEnvironmentOutput, error) {
465465
// Legacy pairing flows
466466
if (body.AccessToken == nil || *body.AccessToken == "") && body.BootstrapToken != nil && *body.BootstrapToken != "" {
467-
token, err := h.environmentService.PairAgentWithBootstrap(ctx, body.ApiUrl, *body.BootstrapToken)
467+
token, err := h.environmentService.PairAgentWithBootstrap(ctx, body.ApiUrl, *body.BootstrapToken) //nolint:staticcheck
468468
if err != nil {
469469
slog.ErrorContext(ctx, "Failed to pair with agent", "apiUrl", body.ApiUrl, "error", err.Error())
470470
return nil, huma.Error502BadGateway((&common.AgentPairingError{Err: err}).Error())

0 commit comments

Comments
 (0)