Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate ebextensions before deployment, for YAML validity #2

Closed
yegor256 opened this issue Sep 25, 2013 · 31 comments
Closed

validate ebextensions before deployment, for YAML validity #2

yegor256 opened this issue Sep 25, 2013 · 31 comments

Comments

@yegor256
Copy link
Member

yegor256 commented Sep 25, 2013

Moved from jcabi/jcabi#109

Would be nice to validate .ebextensions directory in WAR package before deployment, for validity


- ~~`2-677fde75`/#16~~ - `2-c30faef8`/#15 (by ) - `16-a618f555`/#21 (by )
@dmarkov
Copy link

dmarkov commented Dec 26, 2014

@darkled can you please help? Keep in mind this. If you have any technical questions, don't hesitate to ask right here

The budget here is 30 mins, which is exactly how much time will be paid for, when the task is completed

@dmarkov
Copy link

dmarkov commented Jan 8, 2015

@darkled just a reminder that you're working with this task for 13 days already

added -30 to your rating, now it is equal to +45

@asaen
Copy link

asaen commented Jan 9, 2015

@dmarkov please, assign this task to someone else.

@dmarkov
Copy link

dmarkov commented Jan 12, 2015

@dmarkov please, assign this task to someone else.

@darkled OK, I will try to assign someone else

@dmarkov
Copy link

dmarkov commented Jan 16, 2015

@dpisarenko the issue is yours, please help

@mentiflectax
Copy link
Contributor

@yegor256 Is it correct that in scope of this task I need to implement something like

final File extdir = new File(".ebextensions");

for (final file : extdir.listFiles(new ConfigFileFilter())) {
    if (!(validYaml(file) || validJson(file))) {
        throw new Exception("File " + file.getAbsolutePath() 
        + " is neither valid YAML, nor valid JSON");
    }
}

where ConfigFileFilter is defined as shown below?

public class ConfigFileFilter : FilenameFilter {
    public boolean accept(File dir, String name) {
        return name.endsWith(".config");
    }
}

@yegor256
Copy link
Member Author

@dpisarenko I think they expect only YAML files there with .config extensions. We should validate that they are all in readable YAML format and they all end with .config

@yegor256
Copy link
Member Author

@dpisarenko I may be wrong, please make sure you check the official documentation of AWS

@mentiflectax
Copy link
Contributor

@yegor256 According to http:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html

Configuration files should conform to YAML or JSON formatting standards

@yegor256
Copy link
Member Author

@dpisarenko than you're right

@mentiflectax
Copy link
Contributor

@yegor256 Is it correct that .ebextensions directory is supposed to be in the com.jcabi.beanstalk.maven.plugin.AbstractBeanstalkMojo#war archive?

@mentiflectax
Copy link
Contributor

@yegor256 Is it OK, if

  1. I make sure that the method com.jcabi.beanstalk.maven.plugin.AbstractBeanstalkMojo#checkEbextensionsValidity runs inside a unit test and
  2. add TODOs for JSON and YAML validation?
private void checkEbextensionsValidity() throws MojoFailureException {
    try {
        final ZipFile warfile = createZipFile();
        final ZipEntry ebextdir = warfile.getEntry(".ebextensions");
        if (ebextdir == null)
            throw new MojoFailureException(
                ".ebextensions directory does not exist in the WAR file");
        final Enumeration<? extends ZipEntry> entries = warfile.entries();
        int files = 0;
        while (entries.hasMoreElements()) {
            final ZipEntry entry = entries.nextElement();
            if (entry.getName().startsWith(".ebextensions/")
                && !entry.isDirectory()) {
                files++;
                final String text = readFile(warfile, entry);
                if (!(validJson(text) || validYaml(text))) {
                    throw new MojoFailureException(Joiner.on("").join(
                        "File '",
                        entry.getName(),
                        "' in .ebextensions is neither valid JSON,",
                        " nor valid YAML"));
                }
            }
        }
    } catch (final IOException e) {
        Logger.error(this, e.getMessage());
        throw new MojoFailureException(".ebextensions validation failed");
    }
}

/**
 * Validates a YAML string.
 * @param text Text to validate
 * @return True, if text is a valid YAML string.
 * @todo #2:30min Implement validation of YAML inside the method
 * AbstractBeanstalkMojo.validYaml. Remember to unit test your solution.
 */
protected boolean validYaml(final String text) {
    throw new NotImplementedException(
        "com.jcabi.beanstalk.maven.plugin.AbstractBeanstalkMojo.validJson");
}

/**
 * Validates a JSON string.
 * @param text Text to validate
 * @return True, if text is a valid JSON string.
 * @todo #2:30min Implement validation of JSON inside the method
 * AbstractBeanstalkMojo.validJson(). Remember to unit test your solution.
 */
protected boolean validJson(final String text) {
    throw new NotImplementedException(
        "com.jcabi.beanstalk.maven.plugin.AbstractBeanstalkMojo.validJson");
}

@yegor256
Copy link
Member Author

@dpisarenko looks good to me

@mentiflectax
Copy link
Contributor

@yegor256 I created a test, which is supposed to verify that execute calls checkEbextensionsValidity.

    @Test
    @Ignore
    public void executeCallscheckEbextensionsValidity()
        throws MojoFailureException {
        final AbstractBeanstalkMojo mojo = Mockito.spy(
            new AbstractBeanstalkMojoTest.BeanstalkMojoForTesting()
        );
        mojo.setSkip(false);
        Mockito.doNothing().when(mojo).checkEbextensionsValidity();
        mojo.execute();
        Mockito.verify(mojo).checkEbextensionsValidity();
    }

In order for it to run, I need to set the war member variable. How can I do it (set the mojo.war member variable inside the test), except using PowerMockito to set a private variable (which is considered a bad practice) ?

@mentiflectax
Copy link
Contributor

@yegor256 How can I disable the AbstractClassNameCheck and MultipleStringLiteralsCheck checks for the AbstractBeanstalkMojoTest class?

I tried this:

/**
 * Tests for the AbstractBeanstalkMojo class.
 * @author Dmitri Pisarenko ([email protected])
 * @version $Id$
 * @since 1.0
 * @checkstyle AbstractClassNameCheck (1 lines)
 * @checkstyle MultipleStringLiteralsCheck (3 lines)
 */
public final class AbstractBeanstalkMojoTest {

but still get Checkstyle errors.

@yegor256
Copy link
Member Author

@dpisarenko create a setter, like it's done with setSkip()

@yegor256
Copy link
Member Author

@dpisarenko checkstyle is right in this case, don't test abstract classes. Instead, test concrete classes that extend them.

@mentiflectax
Copy link
Contributor

@yegor256 Both UpdateMojo and DeployMojo (subclasses of AbstractBeanstalkMojo) are final, which means I cannot mock/spy on them with Mockito. What is the right way to do in this case?

@mentiflectax
Copy link
Contributor

@yegor256 How can I disable Checkstyle's MultipleStringLiteralsCheck? I tried putting @checkstyle MultipleStringLiteralsCheck (10 lines) into the class Javadoc and // @checkstyle MultipleStringLiteralsCheck (10 lines) before the line, where the violation occurs, but none of that helped.

@yegor256
Copy link
Member Author

put this one into the Javadoc of the class:

@checkstyle MultipleStringLiteralsCheck (500 lines)

should work

@mentiflectax
Copy link
Contributor

@yegor256 The PR has been merged. Please close the issue. Thanks.

@yegor256
Copy link
Member Author

@dpisarenko thanks!

@yegor256
Copy link
Member Author

@rultor release, tag is 0.11

@rultor
Copy link
Contributor

rultor commented Jan 23, 2015

@rultor release, tag is 0.11

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Jan 23, 2015

@rultor release, tag is 0.11

@yegor256 Oops, I failed. You can see the full log here (spent 10min)

yegor256 pushed a commit that referenced this issue Jan 26, 2015
@yegor256
Copy link
Member Author

@rultor release, tag is 0.11

@rultor
Copy link
Contributor

rultor commented Jan 26, 2015

@rultor release, tag is 0.11

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Jan 26, 2015

@rultor release, tag is 0.11

@yegor256 Done! FYI, the full log is here (took me 9min)

@dmarkov
Copy link

dmarkov commented Jan 27, 2015

these 2 puzzles were created in this ticket: 2-c30faef8, 2-677fde75

@dmarkov
Copy link

dmarkov commented Jan 27, 2015

@dpisarenko thank you, added 30 mins to your acc, payment num is 50842019. +30 added to your rating, at the moment it is: +551

@dmarkov
Copy link

dmarkov commented Aug 10, 2016

@yegor256 last 2 puzzles 2-c30faef8/#15, 16-a618f555/#21 originated from here were solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants