View Javadoc
1   /*
2    * Copyright (c) 2016 ingenieux Labs
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package br.com.ingenieux.mojo.beanstalk.config;
18  
19  import com.amazonaws.services.elasticbeanstalk.model.DescribeConfigurationSettingsRequest;
20  import com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription;
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  
27  import java.util.Collection;
28  
29  import br.com.ingenieux.mojo.aws.util.GlobUtil;
30  import br.com.ingenieux.mojo.beanstalk.AbstractNeedsEnvironmentMojo;
31  
32  import static org.apache.commons.lang.StringUtils.isNotBlank;
33  
34  /**
35   * Returns the Configuration Settings
36   *
37   * See the <a href= "http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/API_DescribeConfigurationSettings.html"
38   * >DescribeConfigurationSettings API</a> call.
39   *
40   * @since 0.2.0
41   */
42  @Mojo(name = "describe-configuration-settings")
43  public class DescribeConfigurationSettingsMojo extends AbstractNeedsEnvironmentMojo {
44  
45    /**
46     * Template Name
47     */
48    @Parameter(property = "beanstalk.templateName")
49    String templateName;
50  
51    @Override
52    protected EnvironmentDescription handleResults(Collection<EnvironmentDescription> environments) throws MojoExecutionException {
53      try {
54        return super.handleResults(environments);
55      } catch (Exception exc) {
56        // Don't care - We're an exception to the rule, you know.
57  
58        return null;
59      }
60    }
61  
62    protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
63      boolean bTemplateNameDefined = isNotBlank(templateName) && !GlobUtil.hasWildcards(templateName);
64  
65      DescribeConfigurationSettingsRequest req = new DescribeConfigurationSettingsRequest().withApplicationName(applicationName);
66  
67      if (bTemplateNameDefined) {
68        req.withTemplateName(templateName);
69      } else if (null != curEnv) {
70        req.withEnvironmentName(curEnv.getEnvironmentName());
71      } else {
72        getLog().warn("You must supply a templateName or environmentName. Ignoring");
73  
74        return null;
75      }
76  
77      getLog().info("Request: " + req);
78  
79      return getService().describeConfigurationSettings(req);
80    }
81  }