Skip to content

Commit

Permalink
Merge pull request #172 from rundeck/issue/169
Browse files Browse the repository at this point in the history
Fix #169 project create does not require config input
  • Loading branch information
gschueler authored Apr 27, 2018
2 parents 8350063 + 2a89f46 commit 57e409c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/rundeck/client/tool/commands/Projects.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.rundeck.client.tool.commands;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lexicalscope.jewel.cli.CommandLineInterface;
import com.lexicalscope.jewel.cli.Option;
import org.rundeck.toolbelt.Command;
Expand All @@ -31,7 +30,6 @@
import org.rundeck.client.util.Format;

import java.io.Console;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -151,7 +149,7 @@ interface Create extends ProjectCreateOptions, ConfigInputOptions {
@Command(description = "Create a project.")
public void create(Create options, CommandOutput output) throws IOException, InputError {

Map<String, String> config = Configure.loadConfig(options);
Map<String, String> config = Configure.loadConfig(options, false);

ProjectItem project = new ProjectItem();
project.setName(projectOrEnv(options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public static enum InputFileFormat {
"removed.")
public void set(ConfigureSetOpts opts, CommandOutput output) throws IOException, InputError {

Map<String, String> config = loadConfig(opts);
Map<String, String> config = loadConfig(opts, true);
ProjectConfig projectConfig = apiCall(api -> api.setProjectConfiguration(
opts.getProject(),
new ProjectConfig(config)
));

}

public static Map<String, String> loadConfig(final ConfigInputOptions opts) throws InputError, IOException {
public static Map<String, String> loadConfig(final ConfigInputOptions opts, final boolean requireInput) throws InputError, IOException {
HashMap<String, String> inputConfig = new HashMap<>();
if (opts.isFile()) {
File input = opts.getFile();
Expand Down Expand Up @@ -163,7 +163,7 @@ public static Map<String, String> loadConfig(final ConfigInputOptions opts) thro
inputConfig.putAll(config);
}

if (inputConfig.size() < 1) {
if (inputConfig.size() < 1 && requireInput) {
throw new InputError("no configuration was specified");
}
return inputConfig;
Expand All @@ -181,7 +181,7 @@ public static Map<String, String> loadConfig(final ConfigInputOptions opts) thro
"Can provide input via a file (json, properties or yaml), or commandline. If both are " +
"provided, the commandline values will override the loaded file values.")
public void update(ConfigureUpdateOpts opts, CommandOutput output) throws IOException, InputError {
Map<String, String> config = loadConfig(opts);
Map<String, String> config = loadConfig(opts, true);
output.info(String.format("Updating %d configuration properties...", config.size()));
for (String s : config.keySet()) {
ProjectConfig body = new ProjectConfig(Collections.singletonMap("value", config.get(s)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ import spock.lang.Specification
*/
class ProjectsSpec extends Specification {

def "create does not require config"() {
given:

def api = Mock(RundeckApi)
def opts = Mock(Projects.Create) {
getProject() >> 'testProject'
}

def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build()
def client = new Client(api, retrofit, null, null, 18, true, null)
def hasclient = Mock(RdApp) {
getClient() >> client
}
Projects projects = new Projects(hasclient)
def out = Mock(CommandOutput)

when:
projects.create(opts, out)

then:
1 * api.createProject(_) >>
Calls.response(new ProjectItem(name: 'testProject', description: '123', config: [:]))

}
def "projects list outformat"() {
given:

Expand Down

0 comments on commit 57e409c

Please sign in to comment.