本文整理汇总了Java中com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse类的典型用法代码示例。如果您正苦于以下问题:Java DefaultGoPluginApiResponse类的具体用法?Java DefaultGoPluginApiResponse怎么用?Java DefaultGoPluginApiResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultGoPluginApiResponse类属于com.thoughtworks.go.plugin.api.response包,在下文中一共展示了DefaultGoPluginApiResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
public GoPluginApiResponse execute() throws ServerRequestFailedException {
LOG.debug("Validating plugin settings.");
ArrayList<Map<String, String>> result = new ArrayList<>();
for (Map.Entry<String, Field> entry : GetPluginConfigurationExecutor.FIELDS.entrySet()) {
Field field = entry.getValue();
Map<String, String> validationError = field.validate(settings.get(entry.getKey()));
if (!validationError.isEmpty()) {
result.add(validationError);
}
}
if(StringUtils.isBlank(settings.get("go_server_url"))) {
ServerInfo severInfo = pluginRequest.getSeverInfo();
if(StringUtils.isBlank(severInfo.getSecureSiteUrl())) {
HashMap<String, String> error = new HashMap<>();
error.put("key", "go_server_url");
error.put("message", "Secure site url is not configured. Please specify Go Server Url.");
result.add(error);
}
}
return DefaultGoPluginApiResponse.success(GSON.toJson(result));
}
示例2: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
if (request.authConfigs().isEmpty()) {
throw new NoAuthorizationConfigurationException("[Authenticate] No authorization configuration found.");
}
final GoogleConfiguration configuration = request.authConfigs().get(0).getConfiguration();
final GoogleApiClient googleApiClient = configuration.googleApiClient();
final GoogleUser googleUser = googleApiClient.userProfile(request.tokenInfo());
if (configuration.allowedDomains().isEmpty() || configuration.allowedDomains().contains(googleUser.getHd())) {
Map<String, Object> userMap = new HashMap<>();
userMap.put("user", new User(googleUser));
userMap.put("roles", Collections.emptyList());
return DefaultGoPluginApiResponse.success(GSON.toJson(userMap));
}
LOG.warn(format("[Authenticate] User `{0}` is not belongs to allowed domain list.", googleUser.getEmail()));
return DefaultGoPluginApiResponse.error(format("[Authenticate] User `{0}` is not belongs to allowed domain list.", googleUser.getEmail()));
}
开发者ID:gocd-contrib,项目名称:google-oauth-authorization-plugin,代码行数:23,代码来源:UserAuthenticationRequestExecutor.java
示例3: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() {
MarathonInstance instance = agentInstances.find(request.agent().elasticAgentId());
if (instance == null) {
return DefaultGoPluginApiResponse.success("false");
}
boolean environmentMatches = stripToEmpty(request.environment()).equalsIgnoreCase(stripToEmpty(instance.environment()));
Map<String, String> containerProperties = instance.properties() == null ? new HashMap<>() : instance.properties();
Map<String, String> requestProperties = request.properties() == null ? new HashMap<>() : request.properties();
boolean propertiesMatch = propertiesMatch(requestProperties, containerProperties);
LOG.debug("ShouldAssignWorkRequestExecutor: propertiesMatch: " + String.valueOf(propertiesMatch) + ", environmentMatches: " + String.valueOf(environmentMatches));
return DefaultGoPluginApiResponse.success(String.valueOf(environmentMatches && propertiesMatch));
}
开发者ID:pikselpalette,项目名称:gocd-elastic-agent-marathon,代码行数:19,代码来源:ShouldAssignWorkRequestExecutor.java
示例4: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
PluginSettings pluginSettings = pluginRequest.getPluginSettings();
Agents allAgents = pluginRequest.listAgents();
Agents missingAgents = new Agents();
for (Agent agent : allAgents.agents()) {
if (agentInstances.find(agent.elasticAgentId()) == null) {
MarathonPlugin.LOG.warn("Was expecting a container with name " + agent.elasticAgentId() + ", but it was missing!");
missingAgents.add(agent);
}
}
Agents agentsToDisable = agentInstances.instancesCreatedAfterTimeout(pluginSettings, allAgents);
agentsToDisable.addAll(missingAgents);
disableIdleAgents(agentsToDisable);
allAgents = pluginRequest.listAgents();
terminateDisabledAgents(allAgents, pluginSettings);
agentInstances.terminateUnregisteredInstances(pluginSettings, allAgents);
return DefaultGoPluginApiResponse.success("");
}
示例5: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
Credentials credentials = Credentials.fromJSON(request.requestBody());
final List<AuthConfig> authConfigs = AuthConfig.fromJSONList(request.requestBody());
Map<String, Object> userMap = new HashMap<>();
try {
final User user = authenticator.authenticate(credentials, authConfigs);
userMap.put("user", user);
userMap.put("roles", Collections.emptyList());
return new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, GSON.toJson(userMap));
} catch (AuthenticationException e) {
LOG.error(String.format("[Authenticate] Failed to authenticate user: `%s`", credentials.getUsername()), e);
return new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, GSON.toJson(userMap));
}
}
示例6: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
if (request.authConfigs() == null || request.authConfigs().isEmpty()) {
throw new NoAuthorizationConfigurationException("[Authenticate] No authorization configuration found.");
}
final AuthConfig authConfig = request.authConfigs().get(0);
final LoggedInUserInfo loggedInUserInfo = gitHubAuthenticator.authenticate(request.tokenInfo(), authConfig);
Map<String, Object> userMap = new HashMap<>();
if (loggedInUserInfo != null) {
userMap.put("user", loggedInUserInfo.getUser());
userMap.put("roles", gitHubAuthorizer.authorize(loggedInUserInfo, authConfig, request.roles()));
}
DefaultGoPluginApiResponse response = new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, GSON.toJson(userMap));
return response;
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:19,代码来源:UserAuthenticationRequestExecutor.java
示例7: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
public GoPluginApiResponse execute() throws Exception {
if (request.authConfigs() == null || request.authConfigs().isEmpty()) {
throw new NoAuthorizationConfigurationException("[Authorization Server Url] No authorization configuration found.");
}
LOG.debug("[Get Authorization Server URL] Getting authorization server url from auth config.");
final AuthConfig authConfig = request.authConfigs().get(0);
final GitHubConfiguration gitHubConfiguration = authConfig.gitHubConfiguration();
String authorizationServerUrl = HttpUrl.parse(gitHubConfiguration.apiUrl())
.newBuilder()
.addPathSegment("login")
.addPathSegment("oauth")
.addPathSegment("authorize")
.addQueryParameter("client_id", gitHubConfiguration.clientId())
.addQueryParameter("redirect_uri", request.callbackUrl())
.addQueryParameter("scope", gitHubConfiguration.scope())
.build().toString();
return DefaultGoPluginApiResponse.success(GSON.toJson(Collections.singletonMap("authorization_server_url", authorizationServerUrl)));
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:24,代码来源:GetAuthorizationServerUrlRequestExecutor.java
示例8: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
public GoPluginApiResponse execute() throws Exception {
if (request.authConfigs() == null || request.authConfigs().isEmpty()) {
throw new NoAuthorizationConfigurationException("[Get Access Token] No authorization configuration found.");
}
if (!request.requestParameters().containsKey("code")) {
throw new IllegalArgumentException("Get Access Token] Expecting `code` in request params, but not received.");
}
final AuthConfig authConfig = request.authConfigs().get(0);
final GitHubConfiguration gitHubConfiguration = authConfig.gitHubConfiguration();
String fetchAccessTokenUrl = fetchAccessTokenUrl(gitHubConfiguration);
final Request fetchAccessTokenRequest = fetchAccessTokenRequest(fetchAccessTokenUrl);
final Response response = httpClient.newCall(fetchAccessTokenRequest).execute();
if (response.isSuccessful()) {
LOG.info("[Get Access Token] Access token fetched successfully.");
final TokenInfo tokenInfo = TokenInfo.fromJSON(response.body().string());
return DefaultGoPluginApiResponse.success(tokenInfo.toJSON());
}
throw new AuthenticationException(format("[Get Access Token] {0}", response.message()));
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:25,代码来源:FetchAccessTokenRequestExecutor.java
示例9: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
final ValidationResult validationResult = new MetadataValidator().validate(request.gitHubRoleConfiguration());
if (!request.gitHubRoleConfiguration().hasConfiguration()) {
validationResult.addError("Organizations", "At least one of the fields(organizations,teams or users) should be specified.");
validationResult.addError("Teams", "At least one of the fields(organizations,teams or users) should be specified.");
validationResult.addError("Users", "At least one of the fields(organizations,teams or users) should be specified.");
}
try {
request.gitHubRoleConfiguration().teams();
} catch (RuntimeException e) {
validationResult.addError("Teams", e.getMessage());
}
return DefaultGoPluginApiResponse.success(validationResult.toJSON());
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:19,代码来源:RoleConfigValidateRequestExecutor.java
示例10: shouldContainFilePatternInResponseToGetConfigurationRequest
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldContainFilePatternInResponseToGetConfigurationRequest() throws UnhandledRequestTypeException {
DefaultGoPluginApiRequest getConfigRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "go.plugin-settings.get-configuration");
GoPluginApiResponse response = plugin.handle(getConfigRequest);
assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE));
JsonObject responseJsonObject = getJsonObjectFromResponse(response);
JsonElement pattern = responseJsonObject.get("file_pattern");
assertNotNull(pattern);
JsonObject patternAsJsonObject = pattern.getAsJsonObject();
assertThat(patternAsJsonObject.get("display-name").getAsString(), is("Go YAML files pattern"));
assertThat(patternAsJsonObject.get("default-value").getAsString(), is("**/*.gocd.yaml,**/*.gocd.yml"));
assertThat(patternAsJsonObject.get("required").getAsBoolean(), is(false));
assertThat(patternAsJsonObject.get("secure").getAsBoolean(), is(false));
assertThat(patternAsJsonObject.get("display-order").getAsInt(), is(0));
}
示例11: shouldContainValidFieldsInResponseMessage
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Test
public void shouldContainValidFieldsInResponseMessage() throws UnhandledRequestTypeException {
GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}");
when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse);
GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot());
assertThat(response.responseCode(), is(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE));
final JsonParser parser = new JsonParser();
JsonElement responseObj = parser.parse(response.responseBody());
assertTrue(responseObj.isJsonObject());
JsonObject obj = responseObj.getAsJsonObject();
assertTrue(obj.has("errors"));
assertTrue(obj.has("pipelines"));
assertTrue(obj.has("environments"));
assertTrue(obj.has("target_version"));
}
示例12: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() {
DockerContainer instance = agentInstances.find(request.agent().elasticAgentId());
if (instance == null) {
return DefaultGoPluginApiResponse.success("false");
}
boolean environmentMatches = stripToEmpty(request.environment()).equalsIgnoreCase(stripToEmpty(instance.environment()));
Map<String, String> containerProperties = instance.properties() == null ? new HashMap<String, String>() : instance.properties();
Map<String, String> requestProperties = request.properties() == null ? new HashMap<String, String>() : request.properties();
boolean propertiesMatch = requestProperties.equals(containerProperties);
if (environmentMatches && propertiesMatch) {
return DefaultGoPluginApiResponse.success("true");
}
return DefaultGoPluginApiResponse.success("false");
}
示例13: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
PluginSettings pluginSettings = pluginRequest.getPluginSettings();
Agents allAgents = pluginRequest.listAgents();
Agents missingAgents = new Agents();
for (Agent agent : allAgents.agents()) {
if (agentInstances.find(agent.elasticAgentId()) == null) {
LOG.warn("Was expecting a container with name " + agent.elasticAgentId() + ", but it was missing!");
missingAgents.add(agent);
}
}
Agents agentsToDisable = agentInstances.instancesCreatedAfterTimeout(pluginSettings, allAgents);
agentsToDisable.addAll(missingAgents);
disableIdleAgents(agentsToDisable);
allAgents = pluginRequest.listAgents();
terminateDisabledAgents(allAgents, pluginSettings);
agentInstances.terminateUnregisteredInstances(pluginSettings, allAgents);
return DefaultGoPluginApiResponse.success("");
}
示例14: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() {
DockerService instance = agentInstances.find(request.agent().elasticAgentId());
if (instance == null) {
LOG.info(format(format("[should-assign-work] Agent with id `{0}` not exists.", request.agent().elasticAgentId())));
return DefaultGoPluginApiResponse.success("false");
}
if (request.jobIdentifier().getJobId().equals(instance.jobId())) {
LOG.info(format("[should-assign-work] Job with profile {0} can be assigned to an agent {1} with job id {2}", request.properties(), instance.name(), instance.jobId()));
return DefaultGoPluginApiResponse.success("true");
}
LOG.info(format("[should-assign-work] Job with profile {0} can be assigned to an agent {1}", request.properties(), instance.name()));
return DefaultGoPluginApiResponse.success("false");
}
开发者ID:gocd-contrib,项目名称:docker-swarm-elastic-agents,代码行数:18,代码来源:ShouldAssignWorkRequestExecutor.java
示例15: execute
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; //导入依赖的package包/类
@Override
public GoPluginApiResponse execute() throws Exception {
final List<String> knownFields = new ArrayList<>();
final ValidationResult validationResult = new ValidationResult();
for (Metadata field : GetProfileMetadataExecutor.FIELDS) {
knownFields.add(field.getKey());
validationResult.addError(field.validate(request.getProperties().get(field.getKey())));
}
final Set<String> set = new HashSet<>(request.getProperties().keySet());
set.removeAll(knownFields);
if (!set.isEmpty()) {
for (String key : set) {
validationResult.addError(key, "Is an unknown property.");
}
}
for (Validatable validatable : validators) {
validationResult.merge(validatable.validate(request.getProperties()));
}
return DefaultGoPluginApiResponse.success(validationResult.toJSON());
}
开发者ID:gocd-contrib,项目名称:docker-swarm-elastic-agents,代码行数:26,代码来源:ProfileValidateRequestExecutor.java