Skip to content

Commit

Permalink
fix: [#418] Add more examples regex usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Dec 31, 2023
1 parent a86e9a1 commit 9583d5e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- uses: schubergphilis/mcvs-docker-action@v0.2.1
- uses: 030/mcvs-docker-action@18-trivyignore-validation
with:
dockle-accept-key: libcrypto3,libssl3
token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Accept the risk until 2023-01-01
CVE-2019-14697 exp:2024-01-30
CVE-2019-14697
CVE-2019-14697 exp:2024-01-01
CVE-2019-14697 exp:2023-01-01
1 change: 1 addition & 0 deletions cmd/n3dr/repositoriesV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Examples:
FQDN: n3drURL,
HTTPS: &https,
Pass: n3drPass,
Regex: regex,
RepoName: n3drRepo,
SkipErrors: skipErrors,
User: n3drUser,
Expand Down
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Examples

regex

## repositoriesV2

Use the [basePathPrefix](./repositoriesV2/BASE_PATH_PREFIX.md) subcommand if
Expand Down
28 changes: 24 additions & 4 deletions internal/app/n3dr/artifactsv2/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"sync"
"time"

Expand Down Expand Up @@ -86,7 +87,7 @@ func (n *Nexus3) download(checksum, downloadedFileChecksum string, asset *models
return nil
}

func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) {
func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) error {
shaType, checksum := artifacts.Checksum(asset)

log.WithFields(log.Fields{
Expand All @@ -101,6 +102,19 @@ func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) {
}
if !filesToBeSkipped {
file := filepath.Join(n.DownloadDirName, repo, assetPath)

//
//
//
r, err := regexp.Compile(n.Regex)
if err != nil {
return err
}
if !r.MatchString(file) {
log.Debugf("file: '%s' skipped as it does not match regex: '%s'", file, n.Regex)
return nil
}

downloadedFileChecksum, err := artifacts.ChecksumLocalFile(file, shaType)
if err != nil {
panic(err)
Expand All @@ -110,6 +124,8 @@ func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) {
panic(err)
}
}

return nil
}

func (n *Nexus3) downloadIfChecksumMismatchLocalFile(continuationToken, repo string) error {
Expand All @@ -129,13 +145,17 @@ func (n *Nexus3) downloadIfChecksumMismatchLocalFile(continuationToken, repo str
for _, item := range resp.GetPayload().Items {
for _, asset := range item.Assets {
if n.WithoutWaitGroups || n.WithoutWaitGroupArtifacts {
n.downloadSingleArtifact(asset, repo)
if err := n.downloadSingleArtifact(asset, repo); err != nil {
return err
}
} else {
wg.Add(1)
go func(asset *models.AssetXO) {
defer wg.Done()

n.downloadSingleArtifact(asset, repo)
if err := n.downloadSingleArtifact(asset, repo); err != nil {
panic(err)
}
}(asset)
}
}
Expand Down Expand Up @@ -199,7 +219,7 @@ func (n *Nexus3) repository(repo *models.AbstractAPIRepository) {
func (n *Nexus3) Backup() error {
var wg sync.WaitGroup

cn := connection.Nexus3{BasePathPrefix: n.BasePathPrefix, FQDN: n.FQDN, DownloadDirName: n.DownloadDirName, Pass: n.Pass, User: n.User, HTTPS: n.HTTPS, DockerHost: n.DockerHost, DockerPort: n.DockerPort, DockerPortSecure: n.DockerPortSecure}
cn := connection.Nexus3{BasePathPrefix: n.BasePathPrefix, FQDN: n.FQDN, DownloadDirName: n.DownloadDirName, Pass: n.Pass, User: n.User, HTTPS: n.HTTPS, DockerHost: n.DockerHost, DockerPort: n.DockerPort, DockerPortSecure: n.DockerPortSecure, Regex: n.Regex}
a := artifacts.Nexus3{Nexus3: &cn}
repos, err := a.Repos()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/n3dr/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Nexus3 struct {
AwsBucket, AwsID, AwsRegion, AwsSecret, BasePathPrefix, DockerHost, DownloadDirName, DownloadDirNameZip, Pass, RepoName, User string
AwsBucket, AwsID, AwsRegion, AwsSecret, BasePathPrefix, DockerHost, DownloadDirName, DownloadDirNameZip, Pass, Regex, RepoName, User string
DockerPort int32
DockerPortSecure, SkipErrors, StrictContentTypeValidation, WithoutWaitGroups, WithoutWaitGroupArtifacts, WithoutWaitGroupRepositories, ZIP bool
HTTPS *bool `validate:"required"`
Expand Down

0 comments on commit 9583d5e

Please sign in to comment.