Java Code Examples for com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse#success()

The following examples show how to use com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse#success() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterProfileValidateRequestExecutor.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
public GoPluginApiResponse execute() {
    final List<String> knownFields = new ArrayList<>();
    final ValidationResult validationResult = new ValidationResult();

    for (Metadata field : GetClusterProfileMetadataExecutor.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.");
        }
    }
    List<Map<String, String>> validateErrors = new PrivateDockerRegistrySettingsValidator().validate(request);
    validateErrors.forEach(error -> validationResult.addError(new ValidationError(error.get("key"), error.get("message"))));
    return DefaultGoPluginApiResponse.success(validationResult.toJSON());
}
 
Example 2
Source File: GetAuthorizationServerUrlRequestExecutor.java    From github-oauth-authorization-plugin with Apache License 2.0 6 votes vote down vote up
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)));
}
 
Example 3
Source File: RoleConfigValidateRequestExecutor.java    From github-oauth-authorization-plugin with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: Plugin2.java    From go-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException {

    if ("configuration".equals(goPluginApiRequest.requestName())) {
        HashMap<String, Object> config = new HashMap<>();

        HashMap<String, Object> url = new HashMap<>();
        url.put("display-order", "0");
        url.put("display-name", "Url");
        url.put("required", true);
        config.put("Url", url);
        return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(config));
    } else if ("view".equals(goPluginApiRequest.requestName())) {
        return getViewRequest();
    }
    throw new UnhandledRequestTypeException(goPluginApiRequest.requestName());
}
 
Example 5
Source File: ShouldAssignWorkRequestExecutor.java    From kubernetes-elastic-agents with Apache License 2.0 6 votes vote down vote up
@Override
public GoPluginApiResponse execute() {
    KubernetesInstance pod = agentInstances.find(request.agent().elasticAgentId());

    if (pod == null) {
        return DefaultGoPluginApiResponse.success("false");
    }

    if (request.jobIdentifier().getJobId().equals(pod.jobId())) {
        LOG.debug(format("[should-assign-work] Job with identifier {0} can be assigned to an agent {1}.", request.jobIdentifier(), pod.name()));
        return DefaultGoPluginApiResponse.success("true");
    }

    LOG.debug(format("[should-assign-work] Job with identifier {0} can not be assigned to an agent {1}.", request.jobIdentifier(), pod.name()));
    return DefaultGoPluginApiResponse.success("false");
}
 
Example 6
Source File: ServerPingRequestExecutor.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
@Override
public GoPluginApiResponse execute() throws Exception {
    List<ClusterProfileProperties> allClusterProfileProperties = serverPingRequest.allClusterProfileProperties();

    for (ClusterProfileProperties clusterProfileProperties : allClusterProfileProperties) {
        performCleanupForACluster(clusterProfileProperties, clusterSpecificAgentInstances.get(clusterProfileProperties.uuid()));
    }

    CheckForPossiblyMissingAgents();
    return DefaultGoPluginApiResponse.success("");
}
 
Example 7
Source File: AuthConfigValidateRequestExecutor.java    From github-oauth-authorization-plugin with Apache License 2.0 5 votes vote down vote up
public GoPluginApiResponse execute() {
    final GitHubConfiguration gitHubConfiguration = request.githubConfiguration();
    final ValidationResult validationResult = new MetadataValidator().validate(gitHubConfiguration);

    if (gitHubConfiguration.authenticateWith() == AuthenticateWith.GITHUB_ENTERPRISE && Util.isBlank(gitHubConfiguration.gitHubEnterpriseUrl())) {
        validationResult.addError("GitHubEnterpriseUrl", "GitHubEnterpriseUrl must not be blank.");
    }

    if (Util.isBlank(gitHubConfiguration.personalAccessToken())) {
        validationResult.addError("PersonalAccessToken", "PersonalAccessToken must not be blank.");
    }

    return DefaultGoPluginApiResponse.success(validationResult.toJSON());
}
 
Example 8
Source File: JobCompletionRequestExecutor.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public GoPluginApiResponse execute() throws Exception {
    ClusterProfileProperties clusterProfileProperties = jobCompletionRequest.getClusterProfileProperties();
    String elasticAgentId = jobCompletionRequest.getElasticAgentId();
    Agent agent = new Agent(elasticAgentId);
    LOG.info("[Job Completion] Terminating elastic agent with id {} on job completion {} in cluster {}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier(), clusterProfileProperties);
    List<Agent> agents = Arrays.asList(agent);
    pluginRequest.disableAgents(agents);
    agentInstances.terminate(agent.elasticAgentId(), clusterProfileProperties);
    pluginRequest.deleteAgents(agents);
    return DefaultGoPluginApiResponse.success("");
}
 
Example 9
Source File: ValidStaticClassPlugin.java    From go-plugins with Apache License 2.0 5 votes vote down vote up
private GoPluginApiResponse getViewRequest(){
    HashMap<String, String> view = new HashMap<>();
    view.put("displayValue", "TestTask");
    view.put("template", "<html><body>this is a static class plugin</body></html>");

    return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(view));
}
 
Example 10
Source File: Plugin1.java    From go-plugins with Apache License 2.0 5 votes vote down vote up
private GoPluginApiResponse getViewRequest(){
    HashMap<String, String> view = new HashMap<>();
    view.put("displayValue", "TestTask");
    view.put("template", "<html><body>this is a do nothing plugin</body></html>");

    return DefaultGoPluginApiResponse.success(new GsonBuilder().create().toJson(view));
}
 
Example 11
Source File: DumbPluginThatRespondsWithClassloaderName.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException {
    switch(goPluginApiRequest.requestName()){
        case "Thread.currentThread.getContextClassLoader":
            return DefaultGoPluginApiResponse.success(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName());
        case "this.getClass.getClassLoader":
            return DefaultGoPluginApiResponse.success(this.getClass().getClassLoader().getClass().getCanonicalName());
        default:
            throw new UnhandledRequestTypeException(goPluginApiRequest.requestName());
    }
}
 
Example 12
Source File: ClusterStatusReportExecutor.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public GoPluginApiResponse execute() throws Exception {
    LOG.info("[status-report] Generating status report");

    StatusReport statusReport = dockerContainers.getStatusReport(clusterStatusReportRequest.getClusterProfile());

    final Template template = viewBuilder.getTemplate("status-report.template.ftlh");
    final String statusReportView = viewBuilder.build(template, statusReport);

    JsonObject responseJSON = new JsonObject();
    responseJSON.addProperty("view", statusReportView);

    return DefaultGoPluginApiResponse.success(responseJSON.toString());
}
 
Example 13
Source File: GetPluginIconExecutor.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public GoPluginApiResponse execute() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", getContentType());
    jsonObject.addProperty("data", Base64.getEncoder().encodeToString(Util.readResourceBytes(getIcon())));
    return DefaultGoPluginApiResponse.success(GSON.toJson(jsonObject));
}
 
Example 14
Source File: GetRoleConfigMetadataRequestExecutor.java    From github-oauth-authorization-plugin with Apache License 2.0 4 votes vote down vote up
public GoPluginApiResponse execute() throws Exception {
    final List<ProfileMetadata> authConfigMetadata = MetadataHelper.getMetadata(GitHubRoleConfiguration.class);
    return DefaultGoPluginApiResponse.success(GSON.toJson(authConfigMetadata));
}
 
Example 15
Source File: ValidateArtifactStoreConfigExecutor.java    From docker-registry-artifact-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public GoPluginApiResponse execute() {
    final ValidationResult validationResult = artifactStoreConfig.validate();
    return DefaultGoPluginApiResponse.success(validationResult.toJSON());
}
 
Example 16
Source File: GetClusterProfileMetadataExecutor.java    From kubernetes-elastic-agents with Apache License 2.0 4 votes vote down vote up
@Override
public GoPluginApiResponse execute() throws Exception {
    return DefaultGoPluginApiResponse.success(GSON.toJson(FIELDS));
}
 
Example 17
Source File: GetAuthConfigViewRequestExecutor.java    From github-oauth-authorization-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public GoPluginApiResponse execute() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/auth-config.template.html"));
    return DefaultGoPluginApiResponse.success(GSON.toJson(jsonObject));
}
 
Example 18
Source File: DescriptorValidatorPlugin.java    From gocd with Apache License 2.0 4 votes vote down vote up
@Override
public GoPluginApiResponse handle(GoPluginApiRequest goPluginApiRequest) throws UnhandledRequestTypeException {
    return DefaultGoPluginApiResponse.success(goPluginApiRequest.requestBody());
}
 
Example 19
Source File: GetArtifactStoreConfigMetadataExecutor.java    From docker-registry-artifact-plugin with Apache License 2.0 4 votes vote down vote up
public GoPluginApiResponse execute() {
    final List<ConfigMetadata> storeConfigMetadata = MetadataHelper.getMetadata(ArtifactStoreConfig.class);
    return DefaultGoPluginApiResponse.success( Util.GSON.toJson(storeConfigMetadata));
}
 
Example 20
Source File: GetPublishArtifactViewExecutor.java    From docker-registry-artifact-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public GoPluginApiResponse execute() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/publish-artifact.template.html"));
    return DefaultGoPluginApiResponse.success( GSON.toJson(jsonObject));
}