Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh/archives import include #561

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ String validate(ProjectInput opts) throws InputError {
}

@Getter @Setter
static class ArchiveImportOpts extends BaseOptions{
public static class ArchiveImportOpts extends BaseOptions{
@CommandLine.Option(names = {"-r"}, description = "Remove Job UUIDs in imported jobs. Default: preserve job UUIDs.")
boolean remove;

Expand Down Expand Up @@ -122,6 +122,54 @@ static class ArchiveImportOpts extends BaseOptions{
description = "Set options for enabled components, in the form name.key=value")
Map<String, String> componentOptions;

@CommandLine.Option(
names = {"--include"/*, "-i"*/}, //note: -i would conflict with async import
description =
"List of archive contents to import. [executions,config,acl,scm,webhooks,nodeSources]. Default: " +
"executions. (webhooks: requires API v34. nodeSources: requires API v38).")
Set<ImportFlags> includeFlags;

boolean isIncludeFlags() {
return includeFlags != null && !includeFlags.isEmpty();
}

Set<ImportFlags> calculateFlags(){
if(isIncludeFlags()){
return includeFlags;
}
Set<ImportFlags> importFlags = new HashSet<>();
//determine via boolean options
if(!isNoExecutions()){
importFlags.add(ImportFlags.executions);
}
if(isIncludeConfig()){
importFlags.add(ImportFlags.config);
}
if(isIncludeAcl()){
importFlags.add(ImportFlags.acl);
}
if(isIncludeScm()){
importFlags.add(ImportFlags.scm);
}
if(isIncludeWebhooks()){
importFlags.add(ImportFlags.webhooks);
}
if(isIncludeNodeSources()){
importFlags.add(ImportFlags.nodeSources);
}

return importFlags;
}

}

enum ImportFlags {
executions,
config,
acl,
scm,
webhooks,
nodeSources,
}

@CommandLine.Command(description = "Get the status of an ongoing asynchronous import process.", name = "async-import-status")
Expand All @@ -142,24 +190,25 @@ public int importArchive(@CommandLine.Mixin ArchiveImportOpts opts) throws Input
if (!input.canRead() || !input.isFile()) {
throw new InputError(String.format("File is not readable or does not exist: %s", input));
}
if ((opts.isIncludeWebhooks() || opts.isWhkRegenAuthTokens()) && getRdTool().getClient().getApiVersion() < 34) {
Set<ImportFlags> importFlags = opts.calculateFlags();
if ((importFlags.contains(ImportFlags.webhooks) || opts.isWhkRegenAuthTokens()) && getRdTool().getClient().getApiVersion() < 34) {
throw new InputError(String.format("Cannot use --include-webhooks or --regenerate-tokens with API < 34 (currently: %s)", getRdTool().getClient().getApiVersion()));
}
if ((opts.isIncludeWebhooks() || opts.isWhkRegenUuid()) && getRdTool().getClient().getApiVersion() < 47) {
throw new InputError(String.format("Cannot use --include-webhooks or --remove-webhooks-uuids with API < 47 (currently: %s)", getRdTool().getClient().getApiVersion()));
if ((importFlags.contains(ImportFlags.webhooks) && opts.isWhkRegenUuid()) && getRdTool().getClient().getApiVersion() < 47) {
throw new InputError(String.format("Cannot use --include-webhooks with --remove-webhooks-uuids with API < 47 (currently: %s)", getRdTool().getClient().getApiVersion()));
}
if ((opts.isIncludeNodeSources()) && getRdTool().getClient().getApiVersion() < 38) {
if ((importFlags.contains(ImportFlags.nodeSources)) && getRdTool().getClient().getApiVersion() < 38) {
throw new InputError(String.format("Cannot use --include-node-sources with API < 38 (currently: %s)", getRdTool().getClient().getApiVersion()));
}
RequestBody body = RequestBody.create(input, Client.MEDIA_TYPE_ZIP);

Map<String, String> extraCompOpts = new HashMap<>();
if (opts.components != null && opts.components.size() > 0) {
if (opts.components != null && !opts.components.isEmpty()) {
for (String component : opts.components) {
extraCompOpts.put("importComponents." + component, "true");
}
}
if (opts.componentOptions != null && opts.componentOptions.size() > 0) {
if (opts.componentOptions != null && !opts.componentOptions.isEmpty()) {
for (Map.Entry<String, String> stringStringEntry : opts.componentOptions.entrySet()) {
extraCompOpts.put("importOpts." + stringStringEntry.getKey(), stringStringEntry.getValue());
}
Expand All @@ -168,14 +217,14 @@ public int importArchive(@CommandLine.Mixin ArchiveImportOpts opts) throws Input
ProjectImportStatus status = apiCall(api -> api.importProjectArchive(
project,
opts.isRemove() ? "remove" : "preserve",
!opts.isNoExecutions(),
opts.isIncludeConfig(),
opts.isIncludeAcl(),
opts.isIncludeScm(),
opts.isIncludeWebhooks(),
importFlags.contains(ImportFlags.executions),
importFlags.contains(ImportFlags.config),
importFlags.contains(ImportFlags.acl),
importFlags.contains(ImportFlags.scm),
importFlags.contains(ImportFlags.webhooks),
opts.isWhkRegenAuthTokens(),
opts.isWhkRegenUuid(),
opts.isIncludeNodeSources(),
importFlags.contains(ImportFlags.nodeSources),
opts.isAsyncImportEnabled(),
extraCompOpts,
body
Expand Down Expand Up @@ -216,7 +265,7 @@ public int importArchive(@CommandLine.Mixin ArchiveImportOpts opts) throws Input


@Getter @Setter
static class ArchiveExportOpts extends BaseOptions {
public static class ArchiveExportOpts extends BaseOptions {

@CommandLine.Option(
names = {"--execids", "-e"},
Expand Down
Loading
Loading