Skip to content

Commit

Permalink
Merge pull request classmethod#114 from mochizuki-masao/feature/add_s…
Browse files Browse the repository at this point in the history
…sm_parameter

Implement SSMPutParameter Task
  • Loading branch information
dai0304 authored Jun 20, 2017
2 parents b375ca6 + 596e135 commit 8b020d9
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Current Features / Supported AWS Products
* Read messages
* SNS
* Publish message
* SSM
* Put parameters

Requirements
------------
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ dependencies {
compile "com.amazonaws:aws-java-sdk-sqs:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-sns:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-ecr:$awsJavaSdkVersion"
compile "com.amazonaws:aws-java-sdk-ssm:$awsJavaSdkVersion"

// tests
testCompile "junit:junit:$junitVersion"
Expand Down
4 changes: 4 additions & 0 deletions deploy/jp.classmethod.aws.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ pluginBundle {
id = 'jp.classmethod.aws.s3'
displayName = 'Gradle Amazon S3 plugin'
}
awsSSMPlugin {
id = 'jp.classmethod.aws.ssm'
displayName = 'Gradle Amazon SSM plugin'
}
}
mavenCoordinates {
groupId = project.group
Expand Down
30 changes: 30 additions & 0 deletions samples/11-ssm/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// -*- coding: utf-8; mode: groovy -*-

import com.amazonaws.services.simplesystemsmanagement.model.Parameter;

import jp.classmethod.aws.gradle.ssm.AmazonSSMPutParameterTask;


buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }

}
dependencies {
classpath "jp.classmethod.aws:gradle-aws-plugin:0.+"
}
}

apply plugin: "jp.classmethod.aws.ssm"

task putParameter(type: AmazonSSMPutParameterTask) {
prefix = "some.prefix."
overwrite = true
parameters = [
new Parameter().withName("foo").withValue("bar").withType("String"),
new Parameter().withName("foo2").withValue("bar2").withType("SecureString"),
new Parameter().withName("foo3").withValue("bar3,bar4").withType("StringList")
]
}
29 changes: 29 additions & 0 deletions src/main/java/jp/classmethod/aws/gradle/ssm/AmazonSSMPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jp.classmethod.aws.gradle.ssm;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

import jp.classmethod.aws.gradle.AwsPlugin;

public class AmazonSSMPlugin implements Plugin<Project> {

public void apply(Project project) {
project.getPluginManager().apply(AwsPlugin.class);
project.getExtensions().create(AmazonSSMPluginExtention.NAME, AmazonSSMPluginExtention.class, project);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jp.classmethod.aws.gradle.ssm;

import org.gradle.api.Project;

import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;

import jp.classmethod.aws.gradle.common.BaseRegionAwarePluginExtension;

public class AmazonSSMPluginExtention extends BaseRegionAwarePluginExtension<AWSSimpleSystemsManagementClient> {

public static final String NAME = "ssm";


public AmazonSSMPluginExtention(Project project) {
super(project, AWSSimpleSystemsManagementClient.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jp.classmethod.aws.gradle.ssm;

import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.TaskAction;

import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import com.amazonaws.services.simplesystemsmanagement.model.ParameterAlreadyExistsException;
import com.amazonaws.services.simplesystemsmanagement.model.PutParameterRequest;
import com.amazonaws.services.simplesystemsmanagement.model.PutParameterResult;

public class AmazonSSMPutParameterTask extends ConventionTask {

@Getter
@Setter
private List<Parameter> parameters = new ArrayList<>();

/**
* If overwrite is set true, the parameter which has the same
* name will be overwritten with the task execution.
* The default value is false.
*/
@Getter
@Setter
private boolean overwrite;

/**
* used to group parameters with specific prefix.
* when prefix = "foo." and parameter name = "bar",
* actual parameter name will be "foo.bar".
*/
@Getter
@Setter
private String prefix;

@Getter
private PutParameterResult putParameterResult;


public AmazonSSMPutParameterTask() {
setDescription("Put SSM Parameters.");
setGroup("AWS");
}

@TaskAction
public void putParameter() {
// to enable conventionMappings feature
List<Parameter> parameters = getParameters();

if (parameters.isEmpty()) {
return;
}

if (getPrefix() == null) {
setPrefix("");
}

AmazonSSMPluginExtention ext = getProject().getExtensions().getByType(AmazonSSMPluginExtention.class);
AWSSimpleSystemsManagementClient ssm = ext.getClient();

parameters.stream()
.map(param -> new PutParameterRequest()
.withName(getPrefix() + param.getName())
.withType(param.getType())
.withValue(param.getValue())
.withOverwrite(isOverwrite()))
.forEach(request -> {
try {
ssm.putParameter(request);
} catch (ParameterAlreadyExistsException e) {
getLogger().warn("parameter {} already exists", request.getName());
}
});

getLogger().info("Successfully Put SSM Parameters.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2013-2016 Classmethod, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

implementation-class=jp.classmethod.aws.gradle.ssm.AmazonSSMPlugin

0 comments on commit 8b020d9

Please sign in to comment.