forked from jfrog/jfrog-cli-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transfer config - Precheck for Docker repo names (jfrog#1018)
- Loading branch information
Showing
15 changed files
with
177 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
artifactory/commands/utils/checkrunner.go → ...mands/utils/precheckrunner/checkrunner.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package precheckrunner | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...actory/commands/utils/checkrunner_test.go → .../utils/precheckrunner/checkrunner_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package precheckrunner | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...y/commands/utils/remoteurlchecker_test.go → ...s/precheckrunner/remoteurlchecker_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package utils | ||
package precheckrunner | ||
|
||
import ( | ||
"encoding/json" | ||
|
74 changes: 74 additions & 0 deletions
74
artifactory/commands/utils/precheckrunner/repositorynamingchecker.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package precheckrunner | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" | ||
|
||
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" | ||
"github.com/jfrog/jfrog-client-go/artifactory/services" | ||
"github.com/jfrog/jfrog-client-go/utils/log" | ||
) | ||
|
||
const ( | ||
repositoryNamingCheckName = "Repositories naming" | ||
illegalDockerRepositoryKeyReason = "Docker repository keys in JFrog Cloud are not allowed to include '.' or '_' characters." | ||
) | ||
|
||
type illegalRepositoryKeys struct { | ||
RepoKey string `json:"repo_key,omitempty"` | ||
Reason string `json:"reason,omitempty"` | ||
} | ||
|
||
// Run repository naming check before transferring configuration from one Artifactory to another | ||
type RepositoryNamingCheck struct { | ||
selectedRepos map[utils.RepoType][]services.RepositoryDetails | ||
} | ||
|
||
func NewRepositoryNamingCheck(selectedRepos map[utils.RepoType][]services.RepositoryDetails) *RepositoryNamingCheck { | ||
return &RepositoryNamingCheck{selectedRepos} | ||
} | ||
|
||
func (drc *RepositoryNamingCheck) Name() string { | ||
return repositoryNamingCheckName | ||
} | ||
|
||
func (drc *RepositoryNamingCheck) ExecuteCheck(args RunArguments) (passed bool, err error) { | ||
results := drc.getIllegalRepositoryKeys() | ||
if len(results) == 0 { | ||
return true, nil | ||
} | ||
|
||
return false, handleFailuresInRepositoryKeysRun(results) | ||
} | ||
|
||
func (drc *RepositoryNamingCheck) getIllegalRepositoryKeys() []illegalRepositoryKeys { | ||
var results []illegalRepositoryKeys | ||
for _, repositoriesOfType := range drc.selectedRepos { | ||
for _, repository := range repositoriesOfType { | ||
if strings.ToLower(repository.PackageType) == "docker" && strings.ContainsAny(repository.Key, "_.") { | ||
log.Debug("Found Docker repository with illegal characters:", repository.Key) | ||
results = append(results, illegalRepositoryKeys{ | ||
RepoKey: repository.Key, | ||
Reason: illegalDockerRepositoryKeyReason, | ||
}) | ||
} | ||
} | ||
} | ||
return results | ||
} | ||
|
||
// Create CSV summary of all the files with illegal repository keys and log the result | ||
func handleFailuresInRepositoryKeysRun(illegalDockerRepositoryKeys []illegalRepositoryKeys) (err error) { | ||
// Create summary | ||
csvPath, err := commandUtils.CreateCSVFile("illegal-repository-keys", illegalDockerRepositoryKeys, time.Now()) | ||
if err != nil { | ||
log.Error("Couldn't create the illegal repository keys CSV file", err) | ||
return | ||
} | ||
// Log result | ||
log.Info(fmt.Sprintf("Found %d illegal repository keys. Check the summary CSV file in: %s", len(illegalDockerRepositoryKeys), csvPath)) | ||
return | ||
} |
Oops, something went wrong.