use of org.rundeck.client.tool.InputError in project rundeck-cli by rundeck.
the class ACLs method performACLModify.
/**
* Upload a file to create/modify an ACLPolicy
*
* @param options file options
* @param func create the request
* @param rdTool rdTool
* @param output output
*
* @return result policy
*/
public static ACLPolicy performACLModify(final ACLFileOptions options, BiFunction<RequestBody, RundeckApi, Call<ACLPolicy>> func, final RdTool rdTool, final CommandOutput output) throws IOException, InputError {
File input = options.getFile();
if (!input.canRead() || !input.isFile()) {
throw new InputError(String.format("File is not readable or does not exist: %s", input));
}
RequestBody requestBody = RequestBody.create(Client.MEDIA_TYPE_YAML, input);
ServiceClient.WithErrorResponse<ACLPolicy> execute = rdTool.apiWithErrorResponseDowngradable(api -> func.apply(requestBody, api));
checkValidationError(output, rdTool.getClient(), execute, input.getAbsolutePath(), rdTool.getAppConfig().isAnsiEnabled());
return rdTool.getClient().checkError(execute);
}
use of org.rundeck.client.tool.InputError in project rundeck-cli by rundeck.
the class Archives method export.
@Command(description = "Export a project archive")
public boolean export(ArchiveExportOpts opts, CommandOutput output) throws IOException, InputError {
if (opts.isIncludeFlags() && opts.isExecutionIds()) {
throw new InputError("Cannot use --execids/-e with --include/-i");
}
boolean apiv19 = getClient().getApiVersion() >= 19;
Set<Flags> includeFlags = opts.isIncludeFlags() ? opts.getIncludeFlags() : new HashSet<>();
if (!opts.isIncludeFlags()) {
includeFlags.add(Flags.all);
}
String project = projectOrEnv(opts);
if (!apiv19) {
if (opts.isIncludeFlags() && includeFlags.size() > 1) {
throw new InputError("Cannot use --include: " + includeFlags + " with API < 19");
}
if (opts.isIncludeFlags() && !includeFlags.contains(Flags.all)) {
throw new InputError("Cannot use --include: " + includeFlags + " with API < 19");
}
output.info(String.format("Export Archive for project: %s", project));
if (opts.isExecutionIds()) {
output.info(String.format("Contents: only execution IDs: %s", opts.getExecutionIds()));
} else {
output.info("Contents: all");
}
output.info("Begin synchronous request...");
// sync
receiveArchiveFile(output, apiCall(api -> api.exportProject(project, opts.getExecutionIds())), opts.getFile());
return true;
}
output.info(String.format("Export Archive for project: %s", project));
if (opts.isExecutionIds()) {
output.info(String.format("Contents: only execution IDs: %s", opts.getExecutionIds()));
} else {
output.info(String.format("Contents: %s", opts.getIncludeFlags()));
}
output.info("Begin asynchronous request...");
ProjectExportStatus status;
if (opts.isExecutionIds()) {
status = apiCall(api -> api.exportProjectAsync(project, opts.getExecutionIds()));
} else {
status = apiCall(api -> api.exportProjectAsync(project, includeFlags.contains(Flags.all), includeFlags.contains(Flags.jobs), includeFlags.contains(Flags.executions), includeFlags.contains(Flags.configs), includeFlags.contains(Flags.readmes), includeFlags.contains(Flags.acls), includeFlags.contains(Flags.scm)));
}
return loopStatus(getClient(), status, project, opts.getFile(), output, () -> {
try {
Thread.sleep(2000);
return true;
} catch (InterruptedException e) {
return false;
}
});
}
use of org.rundeck.client.tool.InputError in project rundeck-cli by rundeck.
the class Readme method put.
@Command(description = "set project readme/motd file")
public void put(SetOptions options, CommandOutput output) throws IOException, InputError {
if (!options.isText() && !options.isFile()) {
throw new InputError("-f/--file or -t/--text is required");
}
RequestBody requestBody;
if (options.isFile()) {
requestBody = RequestBody.create(MediaType.parse("text/plain"), options.getFile());
} else {
requestBody = RequestBody.create(MediaType.parse("text/plain"), options.getText());
}
String project = projectOrEnv(options);
ProjectReadme readme = apiCall(api -> api.putReadme(project, getReadmeFile(options), requestBody));
output.output(readme.getContents());
}
use of org.rundeck.client.tool.InputError in project rundeck-cli by rundeck.
the class AppCommand method projectOrEnv.
/**
* @param options project options
* @return project name from options or ENV
* @throws InputError if project is not set via options or ENV
*/
public String projectOrEnv(final ProjectInput options) throws InputError {
if (null != options.getProject()) {
return options.getProject();
}
try {
String rd_project = getAppConfig().require("RD_PROJECT", "or specify as `-p/--project value` : Project name.");
Pattern pat = Pattern.compile(PROJECT_NAME_PATTERN);
if (!pat.matcher(rd_project).matches()) {
throw new InputError(String.format("Cannot match (%s) to pattern: /%s/ : RD_PROJECT", rd_project, PROJECT_NAME_PATTERN));
}
return rd_project;
} catch (ConfigSource.ConfigSourceError configSourceError) {
throw new InputError(configSourceError.getMessage());
}
}
use of org.rundeck.client.tool.InputError in project rundeck-cli by rundeck.
the class Jobs method getJobList.
/* Bulk toggle execution */
private List<String> getJobList(BulkJobActionOptions options) throws InputError, IOException {
// if id,idlist specified, use directly
// otherwise query for the list and assemble the ids
List<String> ids = new ArrayList<>();
if (options.isIdlist()) {
ids = Arrays.asList(options.getIdlist().split("\\s*,\\s*"));
} else {
if (!options.isJob() && !options.isGroup() && !options.isGroupExact() && !options.isJobExact()) {
throw new InputError("must specify -i, or -j/-g/-J/-G to specify jobs to enable.");
}
String project = projectOrEnv(options);
List<JobItem> body = apiCall(api -> api.listJobs(project, options.getJob(), options.getGroup(), options.getJobExact(), options.getGroupExact()));
for (JobItem jobItem : body) {
ids.add(jobItem.getId());
}
}
return ids;
}
Aggregations