From b7714790d1775a80e4d9b23f67d5272c4f99dbb1 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Sat, 22 Jun 2024 16:22:54 -0700 Subject: [PATCH] Filter node versions by status. --- drip/api.gen.go | 6 +++--- mapper/node_version.go | 7 +++++-- openapi.yml | 2 ++ server/implementation/registry.go | 3 ++- services/registry/registry_svc.go | 3 ++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drip/api.gen.go b/drip/api.gen.go index ec40537..a6b44b1 100644 --- a/drip/api.gen.go +++ b/drip/api.gen.go @@ -4141,9 +4141,9 @@ var swaggerSpec = []string{ "siwWSNPXIJpl+Vh/X0WUKuc30GRQwdz62Ctr5zHf9RZSeFYlg4d+9zBk/SBRxCEGcgMmZsSJu+r76x1P", "+/PybdQNcjTpERSdC/TEZ76naMrZwiRIs2LlDZG/5BNk0l1ZeS263ml7A1IncH7EYzGbqbyx2O/+ue5l", "9GY6hNfrHyK/ARl4PFBLM5ym7nmbobd4vgnb88G714w/xLIe3r3b9XfvKqcMueg+YOj1iK9NgrbiHd/a", - "VeXiYH/HHu79LnMuPuwJ42aJdYrh98wVVPoNioVBriYR6PnR0XDTBD6ea2KLiXyKdPTigR6E7qFO7OwT", - "0bv7VnOVQAysCrYAm6tUDFtCEbQGoJo3GJnzNDqO5lJmygLBGRlqS33I+Cy6u777bwAAAP//3lbeB96a", - "AAA=", + "VeXiYL/TmQF/ZqkOVTTuiq2/46vExFKnCVfsF32fGRkf9vxxs7Q7xfB7ZhIqvQrFwiBXkwj0/OhouGl6", + "H89xscU0P0WyevFAz0X3UDZ29gHp3X3JuUogBnQFW4DNZCqGLYEKWj9QzRsEzXkaHUdzKTNln+CMDLUd", + "P2R8Ft1d3/03AAD//zWISy78mgAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/mapper/node_version.go b/mapper/node_version.go index dbec489..a7f822f 100644 --- a/mapper/node_version.go +++ b/mapper/node_version.go @@ -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 } @@ -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 @@ -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 = "" } diff --git a/openapi.yml b/openapi.yml index 79529be..d882f52 100644 --- a/openapi.yml +++ b/openapi.yml @@ -1445,6 +1445,8 @@ paths: - in: query name: statuses required: false + style: form + explode: true schema: type: array items: diff --git a/server/implementation/registry.go b/server/implementation/registry.go index 4c4521a..fa5aaa9 100644 --- a/server/implementation/registry.go +++ b/server/implementation/registry.go @@ -945,6 +945,7 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions( Page: page, PageSize: pageSize, } + if request.Params.Statuses != nil { f.Status = mapper.ApiNodeVersionStatusesToDbNodeVersionStatuses(request.Params.Statuses) } @@ -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, diff --git a/services/registry/registry_svc.go b/services/registry/registry_svc.go index ad28494..efaeec2 100644 --- a/services/registry/registry_svc.go +++ b/services/registry/registry_svc.go @@ -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...)) } @@ -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") }