goharbor / goharbor/harbor-cli

[feature]: Central Cron Expression Validation

Open
#863 5 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Problem

The Harbor CLI currently validates cron expressions in multiple places, for example in:

`pkg/views/scan-all/update/view.go`

and

`cmd/harbor/root/scan_all/update_schedule.go`

This creates duplicated validation logic and makes future changes harder to maintain. If the validation behavior needs to be updated, it may need to be changed in several files, which increases the risk of inconsistent behavior or missed updates.

## Proposed Solution

Centralize cron expression validation in the `utils` package.

The duplicated validation logic should be moved into a reusable utility function, for example something like:

```go
utils.ValidateCronExpression(...)
```

Both the view layer and the command implementation should then use this shared function instead of maintaining their own validation logic.

This would make the behavior consistent across the CLI and reduce duplication.

## Alternatives Considered

An alternative would be to keep the current validation logic in each location, but that leaves the code duplicated and makes it easier for validation behavior to diverge over time.

Another option would be to only refactor one of the existing implementations, but that would not fully solve the maintainability issue.

## Additional Context

Relevant files currently containing cron validation logic include:

```text
pkg/views/scan-all/update/view.go
cmd/harbor/root/scan_all/update_schedule.go
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.