Java Code Examples for hudson.util.FormValidation#okWithMarkup()

The following examples show how to use hudson.util.FormValidation#okWithMarkup() . 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: AWSEBDeploymentBuilder.java    From awseb-deployment-plugin with Apache License 2.0 6 votes vote down vote up
public FormValidation doValidateUpload(@QueryParameter("applicationName") String applicationName,
                                       @QueryParameter("bucketName") String bucketName,
                                       @QueryParameter("keyPrefix") String keyPrefix,
                                       @QueryParameter("versionLabelFormat") String versionLabelFormat) {

    String objectKey = Utils.formatPath("%s/%s-%s.zip",
            defaultIfBlank(keyPrefix, "<ERROR: MISSING KEY PREFIX>"),
            defaultIfBlank(applicationName, "<ERROR: MISSING APPLICATION NAME>"),
            defaultIfBlank(versionLabelFormat, "<ERROR: MISSING VERSION LABEL FORMAT>"));

    String targetPath = Util.escape(String.format("s3://%s/%s",
            defaultIfBlank(bucketName, "[default account bucket for region]"),
            objectKey));

    final String resultingMessage = format("Your object will be uploaded to S3 as: <code>%s</code> (<i>note replacements will apply</i>)", targetPath);

    return FormValidation.okWithMarkup(resultingMessage);
}
 
Example 2
Source File: ConfigurationAsCode.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@POST
@Restricted(NoExternalUse.class)
public FormValidation doCheckNewSource(@QueryParameter String newSource) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    String normalizedSource = Util.fixEmptyAndTrim(newSource);
    File file = new File(Util.fixNull(normalizedSource));
    if (normalizedSource == null) {
        return FormValidation.ok(); // empty, do nothing
    }
    if (!file.exists() && !ConfigurationAsCode.isSupportedURI(normalizedSource)) {
        return FormValidation.error("Configuration cannot be applied. File or URL cannot be parsed or do not exist.");
    }

    List<YamlSource> yamlSources = Collections.emptyList();
    try {
        List<String> sources = Collections.singletonList(normalizedSource);
        yamlSources = getConfigFromSources(sources);
        final Map<Source, String> issues = checkWith(yamlSources);
        final JSONArray errors = collectProblems(issues, "error");
        if (!errors.isEmpty()) {
            return FormValidation.error(errors.toString());
        }
        final JSONArray warnings = collectProblems(issues, "warning");
        if (!warnings.isEmpty()) {
            return FormValidation.warning(warnings.toString());
        }
        return FormValidation.okWithMarkup("The configuration can be applied");
    } catch (ConfiguratorException | IllegalArgumentException e) {
        return FormValidation.error(e, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    }
}
 
Example 3
Source File: AWSEBDeploymentBuilder.java    From awseb-deployment-plugin with Apache License 2.0 4 votes vote down vote up
public FormValidation doValidateCredentials(
        @QueryParameter("credentialId") final String credentialId,
        @QueryParameter final String awsRegion) {
    for (String value : Arrays.asList(credentialId, awsRegion)) {
        if (value.contains("$")) {
            return FormValidation.warning("Validation skipped due to parameter usage ('$')");
        }
    }

    StringWriter stringWriter = new StringWriter();
    PrintWriter w = new PrintWriter(stringWriter, true);

    try {
        w.printf("<ul>%n");

        w.printf("<li>Building Client (credentialId: '%s', region: '%s')</li>%n", Util.escape(credentialId),
                Util.escape(awsRegion));

        AWSClientFactory factory = AWSClientFactory.getClientFactory(credentialId, awsRegion);

        AmazonS3Client amazonS3 = factory.getService(AmazonS3Client.class);

        String s3Endpoint = factory.getEndpointFor(amazonS3);

        w.printf("<li>Testing Amazon S3 Service (endpoint: %s)</li>%n", Util.escape(s3Endpoint));

        w.printf("<li>Buckets Found: %d</li>%n", amazonS3.listBuckets().size());

        AWSElasticBeanstalkClient
                awsElasticBeanstalk =
                factory.getService(AWSElasticBeanstalkClient.class);

        String
                awsEBEndpoint =
                factory.getEndpointFor(awsElasticBeanstalk);

        w.printf("<li>Testing AWS Elastic Beanstalk Service (endpoint: %s)</li>%n",
                Util.escape(awsEBEndpoint));

        List<String>
                applicationList =
                Lists.transform(awsElasticBeanstalk.describeApplications().getApplications(),
                        new Function<ApplicationDescription, String>() {
                            @Override
                            public String apply(ApplicationDescription input) {
                                return input.getApplicationName();
                            }
                        });

        w.printf("<li>Applications Found: %d (%s)</li>%n", applicationList.size(),
                Util.escape(StringUtils.join(applicationList, ", ")));

        w.printf("</ul>%n");

        return FormValidation.okWithMarkup(stringWriter.toString());
    } catch (Exception exc) {
        return FormValidation.error(exc, "Failure");
    }
}