Unverified Commit eb72d135 authored by Greg Messner's avatar Greg Messner Committed by GitHub
Browse files

Update application settings (#471)

parent 870cf651
...@@ -107,7 +107,7 @@ public class ApplicationSettingsApi extends AbstractApi { ...@@ -107,7 +107,7 @@ public class ApplicationSettingsApi extends AbstractApi {
* @return the populated ApplicationSettings instance * @return the populated ApplicationSettings instance
* @throws GitLabApiException if any error occurs * @throws GitLabApiException if any error occurs
*/ */
private final ApplicationSettings parseApplicationSettings(JsonNode root) throws GitLabApiException { public static final ApplicationSettings parseApplicationSettings(JsonNode root) throws GitLabApiException {
ApplicationSettings appSettings = new ApplicationSettings(); ApplicationSettings appSettings = new ApplicationSettings();
...@@ -122,7 +122,8 @@ public class ApplicationSettingsApi extends AbstractApi { ...@@ -122,7 +122,8 @@ public class ApplicationSettingsApi extends AbstractApi {
case "created_at": case "created_at":
try { try {
appSettings.setCreatedAt(ISO8601.toDate(root.path(fieldName).asText())); String value = root.path(fieldName).asText();
appSettings.setCreatedAt(ISO8601.toDate(value));
} catch (ParseException pe) { } catch (ParseException pe) {
throw new GitLabApiException(pe); throw new GitLabApiException(pe);
} }
...@@ -130,7 +131,8 @@ public class ApplicationSettingsApi extends AbstractApi { ...@@ -130,7 +131,8 @@ public class ApplicationSettingsApi extends AbstractApi {
case "updated_at": case "updated_at":
try { try {
appSettings.setUpdatedAt(ISO8601.toDate(root.path(fieldName).asText())); String value = root.path(fieldName).asText();
appSettings.setUpdatedAt(ISO8601.toDate(value));
} catch (ParseException pe) { } catch (ParseException pe) {
throw new GitLabApiException(pe); throw new GitLabApiException(pe);
} }
......
...@@ -6,6 +6,7 @@ import org.gitlab4j.api.utils.JacksonJsonEnumHelper; ...@@ -6,6 +6,7 @@ import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
/** /**
* This enum provides constants and value validation for the available GitLab application settings. * This enum provides constants and value validation for the available GitLab application settings.
* See <a href="https://docs.gitlab.com/ce/api/settings.html#list-of-settings-that-can-be-accessed-via-api-calls"> * See <a href="https://docs.gitlab.com/ce/api/settings.html#list-of-settings-that-can-be-accessed-via-api-calls">
...@@ -87,7 +88,7 @@ public enum Setting { ...@@ -87,7 +88,7 @@ public enum Setting {
* is required to apply changes. * is required to apply changes.
*/ */
//TODO according to documentation : string or array of strings => How to do this? //TODO according to documentation : string or array of strings => How to do this?
ASSET_PROXY_WHITELIST(String.class), ASSET_PROXY_WHITELIST(new Class<?>[]{String.class, String[].class}),
/** /**
* By default, we write to the authorized_keys file to support Git over SSH * By default, we write to the authorized_keys file to support Git over SSH
...@@ -166,7 +167,7 @@ public enum Setting { ...@@ -166,7 +167,7 @@ public enum Setting {
* Default project creation protection. Can take: 0 (No one), 1 (Maintainers) * Default project creation protection. Can take: 0 (No one), 1 (Maintainers)
* or 2 (Developers + Maintainers) * or 2 (Developers + Maintainers)
*/ */
DEFAULT_PROJECT_CREATION(String.class), DEFAULT_PROJECT_CREATION(Integer.class),
/** /**
* What visibility level new projects receive. Can take private, internal and * What visibility level new projects receive. Can take private, internal and
...@@ -666,11 +667,11 @@ public enum Setting { ...@@ -666,11 +667,11 @@ public enum Setting {
PASSWORD_AUTHENTICATION_ENABLED_FOR_WEB(Boolean.class), PASSWORD_AUTHENTICATION_ENABLED_FOR_WEB(Boolean.class),
/** /**
* Path of the group that is allowed to toggle the performance bar. * ID of the group that is allowed to toggle the performance bar.
* @deprecated Use {@link #PERFORMANCE_BAR_ALLOWED_GROUP_PATH} instead. * @deprecated Use {@link #PERFORMANCE_BAR_ALLOWED_GROUP_PATH} instead.
*/ */
@Deprecated @Deprecated
PERFORMANCE_BAR_ALLOWED_GROUP_ID(String.class), PERFORMANCE_BAR_ALLOWED_GROUP_ID(Integer.class),
/** /**
* Path of the group that is allowed to toggle the performance bar. * Path of the group that is allowed to toggle the performance bar.
...@@ -697,7 +698,7 @@ public enum Setting { ...@@ -697,7 +698,7 @@ public enum Setting {
/** /**
* Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling. * Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.
* The documentation liusts this as a decimal, but it is a String in the JSON. * The documentation lists this as a decimal, but it is a String in the JSON.
*/ */
POLLING_INTERVAL_MULTIPLIER(String.class), POLLING_INTERVAL_MULTIPLIER(String.class),
...@@ -1038,12 +1039,13 @@ public enum Setting { ...@@ -1038,12 +1039,13 @@ public enum Setting {
private static JacksonJsonEnumHelper<Setting> enumHelper = new JacksonJsonEnumHelper<>(Setting.class); private static JacksonJsonEnumHelper<Setting> enumHelper = new JacksonJsonEnumHelper<>(Setting.class);
private Class<?> type; private Class<?> type;
private Class<?>[] types;
private Setting(Class<?> type) { private Setting(Class<?> type) {
this.type = type; this.type = type;
} }
public final Class<?> getType() { private Setting(Class<?>[] types) {
return (type); this.types = types;
} }
@JsonCreator @JsonCreator
...@@ -1068,8 +1070,24 @@ public enum Setting { ...@@ -1068,8 +1070,24 @@ public enum Setting {
* @param value the value to validate * @param value the value to validate
* @return true if the value is of the correct type or null * @return true if the value is of the correct type or null
*/ */
public boolean isValid(Object value) { public final boolean isValid(Object value) {
return (value == null || value.getClass() == type);
if (value == null) {
return (true);
}
Class<?> valueType = value.getClass();
if (type != null) {
return (valueType == type);
}
for (Class<?> type : types) {
if (valueType == type) {
return (true);
}
}
return (false);
} }
/** /**
...@@ -1085,8 +1103,13 @@ public enum Setting { ...@@ -1085,8 +1103,13 @@ public enum Setting {
return; return;
} }
StringBuilder shouldBe = new StringBuilder(types[0].getSimpleName());
for (int i = 1; i < types.length; i++) {
shouldBe.append(" | ").append(types[i].getSimpleName());
}
String errorMsg = String.format("'%s' value is of incorrect type, is %s, should be %s", String errorMsg = String.format("'%s' value is of incorrect type, is %s, should be %s",
toValue(), value.getClass().getSimpleName(), getType().getSimpleName()); toValue(), value.getClass().getSimpleName(), shouldBe.toString());
throw new GitLabApiException(errorMsg); throw new GitLabApiException(errorMsg);
} }
} }
...@@ -25,6 +25,11 @@ public class JsonUtils { ...@@ -25,6 +25,11 @@ public class JsonUtils {
jacksonJson.getObjectMapper().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); jacksonJson.getObjectMapper().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
} }
static JsonNode readTreeFromMap(Map<String, Object> map) throws JsonParseException, JsonMappingException, IOException {
String jsonString = jacksonJson.getObjectMapper().writeValueAsString(map);
return (jacksonJson.readTree(jsonString));
}
static JsonNode readTreeFromString(String jsonString) throws JsonParseException, JsonMappingException, IOException { static JsonNode readTreeFromString(String jsonString) throws JsonParseException, JsonMappingException, IOException {
return (jacksonJson.readTree(jsonString)); return (jacksonJson.readTree(jsonString));
} }
...@@ -116,11 +121,15 @@ public class JsonUtils { ...@@ -116,11 +121,15 @@ public class JsonUtils {
} }
static void sortedDump(final JsonNode node) throws JsonProcessingException { static void sortedDump(final JsonNode node) throws JsonProcessingException {
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class); System.err.println(sortedJsonString(node));
System.err.println(jacksonJson.getObjectMapper().writeValueAsString(obj));
System.err.flush(); System.err.flush();
} }
static String sortedJsonString(final JsonNode node) throws JsonProcessingException {
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class);
return (jacksonJson.getObjectMapper().writeValueAsString(obj));
}
static String readResource(String filename) throws IOException { static String readResource(String filename) throws IOException {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename)); InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename));
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.gitlab4j.api.JsonUtils.compareJson; import static org.gitlab4j.api.JsonUtils.compareJson;
import static org.gitlab4j.api.JsonUtils.readTreeFromResource;
import static org.gitlab4j.api.JsonUtils.unmarshalResource; import static org.gitlab4j.api.JsonUtils.unmarshalResource;
import static org.gitlab4j.api.JsonUtils.unmarshalResourceList; import static org.gitlab4j.api.JsonUtils.unmarshalResourceList;
import static org.gitlab4j.api.JsonUtils.unmarshalResourceMap; import static org.gitlab4j.api.JsonUtils.unmarshalResourceMap;
...@@ -34,6 +35,7 @@ import java.util.Map; ...@@ -34,6 +35,7 @@ import java.util.Map;
import org.gitlab4j.api.models.AccessRequest; import org.gitlab4j.api.models.AccessRequest;
import org.gitlab4j.api.models.Application; import org.gitlab4j.api.models.Application;
import org.gitlab4j.api.models.ApplicationSettings;
import org.gitlab4j.api.models.ArtifactsFile; import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.AwardEmoji; import org.gitlab4j.api.models.AwardEmoji;
import org.gitlab4j.api.models.Badge; import org.gitlab4j.api.models.Badge;
...@@ -53,7 +55,6 @@ import org.gitlab4j.api.models.Epic; ...@@ -53,7 +55,6 @@ import org.gitlab4j.api.models.Epic;
import org.gitlab4j.api.models.EpicIssue; import org.gitlab4j.api.models.EpicIssue;
import org.gitlab4j.api.models.Event; import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.ExportStatus; import org.gitlab4j.api.models.ExportStatus;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.FileUpload; import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Group; import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.HealthCheckInfo; import org.gitlab4j.api.models.HealthCheckInfo;
...@@ -76,6 +77,7 @@ import org.gitlab4j.api.models.PackageFile; ...@@ -76,6 +77,7 @@ import org.gitlab4j.api.models.PackageFile;
import org.gitlab4j.api.models.Pipeline; import org.gitlab4j.api.models.Pipeline;
import org.gitlab4j.api.models.PipelineSchedule; import org.gitlab4j.api.models.PipelineSchedule;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectHook; import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser; import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.ProtectedBranch; import org.gitlab4j.api.models.ProtectedBranch;
...@@ -100,6 +102,8 @@ import org.gitlab4j.api.services.JiraService; ...@@ -100,6 +102,8 @@ import org.gitlab4j.api.services.JiraService;
import org.gitlab4j.api.services.SlackService; import org.gitlab4j.api.services.SlackService;
import org.junit.Test; import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
public class TestGitLabApiBeans { public class TestGitLabApiBeans {
@Test @Test
...@@ -418,6 +422,13 @@ public class TestGitLabApiBeans { ...@@ -418,6 +422,13 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(runnerDetail, "runner-detail.json")); assertTrue(compareJson(runnerDetail, "runner-detail.json"));
} }
@Test
public void testSettings() throws Exception {
JsonNode json = readTreeFromResource("application-settings.json");
ApplicationSettings applicationSettings = ApplicationSettingsApi.parseApplicationSettings(json);
assertTrue(compareJson(applicationSettings.getSettings(), "application-settings.json"));
}
@Test @Test
public void testAllRunners() throws Exception { public void testAllRunners() throws Exception {
List<Runner> allRunners = unmarshalResourceList(Runner.class, "all-runners.json"); List<Runner> allRunners = unmarshalResourceList(Runner.class, "all-runners.json");
......
{
"default_projects_limit": 100000,
"signup_enabled": false,
"password_authentication_enabled_for_web": true,
"gravatar_enabled": true,
"sign_in_text": "",
"home_page_url": "",
"default_branch_protection": 2,
"restricted_visibility_levels": [],
"max_attachment_size": 10,
"session_expire_delay": 10080,
"default_project_visibility": "internal",
"default_snippet_visibility": "private",
"default_group_visibility": "private",
"outbound_local_requests_whitelist": [],
"domain_whitelist": [],
"domain_blacklist_enabled" : false,
"domain_blacklist" : [],
"external_authorization_service_enabled": true,
"external_authorization_service_url": "https://authorize.me",
"external_authorization_service_default_label": "default",
"external_authorization_service_timeout": 0.5,
"user_oauth_applications": true,
"after_sign_out_path": "",
"container_registry_token_expire_delay": 5,
"repository_storages": ["default"],
"plantuml_enabled": false,
"terminal_max_session_time": 0,
"polling_interval_multiplier": "1.0",
"rsa_key_restriction": 0,
"dsa_key_restriction": 0,
"ecdsa_key_restriction": 0,
"ed25519_key_restriction": 0,
"first_day_of_week": 0,
"enforce_terms": true,
"terms": "Hello world!",
"performance_bar_allowed_group_id": 42,
"instance_statistics_visibility_private": false,
"user_show_add_ssh_key_message": true,
"file_template_project_id": 1,
"local_markdown_version": 0,
"asset_proxy_enabled": true,
"asset_proxy_url": "https://assets.example.com",
"asset_proxy_whitelist": ["example.com", "*.example.com", "your-instance.com"],
"geo_node_allowed_ips": "0.0.0.0/0, ::/0",
"allow_local_requests_from_hooks_and_services": true,
"allow_local_requests_from_web_hooks_and_services": true,
"allow_local_requests_from_system_hooks": false
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment