forked from classmethod/gradle-aws-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request classmethod#114 from mochizuki-masao/feature/add_s…
…sm_parameter Implement SSMPutParameter Task
- Loading branch information
Showing
8 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
src/main/java/jp/classmethod/aws/gradle/ssm/AmazonSSMPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/jp/classmethod/aws/gradle/ssm/AmazonSSMPluginExtention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/jp/classmethod/aws/gradle/ssm/AmazonSSMPutParameterTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/META-INF/gradle-plugins/jp.classmethod.aws.ssm.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |