Skip to content

Commit

Permalink
Filter node versions by status.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang committed Jun 22, 2024
1 parent 91c8121 commit b771479
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions drip/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions mapper/node_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func DbNodeVersionToApiNodeVersion(dbNodeVersion *ent.NodeVersion) *drip.NodeVer
id := dbNodeVersion.ID.String()
var downloadUrl string
status := DbNodeVersionStatusToApiNodeVersionStatus(dbNodeVersion.Status)
if dbNodeVersion.Edges.StorageFile != nil && dbNodeVersion.Status == schema.NodeVersionStatusActive {
if dbNodeVersion.Edges.StorageFile != nil {
downloadUrl = dbNodeVersion.Edges.StorageFile.FileURL
}

Expand Down Expand Up @@ -107,7 +107,8 @@ func ApiNodeVersionStatusesToDbNodeVersionStatuses(status *[]drip.NodeVersionSta
}

for _, s := range *status {
nodeVersionStatus = append(nodeVersionStatus, ApiNodeVersionStatusToDbNodeVersionStatus(s))
dbNodeVersion := ApiNodeVersionStatusToDbNodeVersionStatus(s)
nodeVersionStatus = append(nodeVersionStatus, dbNodeVersion)
}

return nodeVersionStatus
Expand All @@ -125,6 +126,8 @@ func ApiNodeVersionStatusToDbNodeVersionStatus(status drip.NodeVersionStatus) sc
nodeVersionStatus = schema.NodeVersionStatusDeleted
case drip.NodeVersionStatusPending:
nodeVersionStatus = schema.NodeVersionStatusPending
case drip.NodeVersionStatusFlagged:
nodeVersionStatus = schema.NodeVersionStatusFlagged
default:
nodeVersionStatus = ""
}
Expand Down
2 changes: 2 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,8 @@ paths:
- in: query
name: statuses
required: false
style: form
explode: true
schema:
type: array
items:
Expand Down
3 changes: 2 additions & 1 deletion server/implementation/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions(
Page: page,
PageSize: pageSize,
}

if request.Params.Statuses != nil {
f.Status = mapper.ApiNodeVersionStatusesToDbNodeVersionStatuses(request.Params.Statuses)
}
Expand Down Expand Up @@ -972,7 +973,7 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions(
apiNodeVersions = append(apiNodeVersions, *mapper.DbNodeVersionToApiNodeVersion(dbNodeVersion))
}

log.Ctx(ctx).Info().Msgf("Found %d node versions", len(apiNodeVersions))
log.Ctx(ctx).Info().Msgf("Found %d node versions", nodeVersionResults.Total)
return drip.ListAllNodeVersions200JSONResponse{
Versions: &apiNodeVersions,
Total: &nodeVersionResults.Total,
Expand Down
3 changes: 2 additions & 1 deletion services/registry/registry_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func (s *RegistryService) ListNodeVersions(ctx context.Context, client *ent.Clie
}

if filter.Status != nil && len(filter.Status) > 0 {
log.Ctx(ctx).Info().Msgf("listing node versions with status: %v", filter.Status)
query.Where(nodeversion.StatusIn(filter.Status...))
}

Expand Down Expand Up @@ -744,7 +745,7 @@ func (s *RegistryService) PerformSecurityCheck(ctx context.Context, client *ent.

if issues != "" {
log.Ctx(ctx).Info().Msgf("No security issues found in node %s@%s. Updating to active.", nodeVersion.NodeID, nodeVersion.Version)
err := nodeVersion.Update().SetStatus(schema.NodeVersionStatusActive).Exec(ctx)
err := nodeVersion.Update().SetStatus(schema.NodeVersionStatusActive).SetStatusReason("Passed automated checks").Exec(ctx)
if err != nil {
log.Ctx(ctx).Error().Err(err).Msgf("failed to update node version status to active")
}
Expand Down

0 comments on commit b771479

Please sign in to comment.