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.
- Loading branch information
Showing
8 changed files
with
264 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
56 changes: 56 additions & 0 deletions
56
src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRCreateRepositoryTask.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,56 @@ | ||
/* | ||
* 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.ecr; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import org.gradle.api.internal.ConventionTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import com.amazonaws.services.ecr.AmazonECR; | ||
import com.amazonaws.services.ecr.model.CreateRepositoryRequest; | ||
import com.amazonaws.services.ecr.model.CreateRepositoryResult; | ||
import com.amazonaws.services.ecr.model.Repository; | ||
import com.google.common.base.MoreObjects; | ||
|
||
public class AmazonECRCreateRepositoryTask extends ConventionTask { | ||
|
||
@Getter | ||
@Setter | ||
private String repositoryName; | ||
|
||
@Getter | ||
private Repository repository; | ||
|
||
|
||
public AmazonECRCreateRepositoryTask() { | ||
setDescription("Create ECR repository"); | ||
setGroup("AWS"); | ||
} | ||
|
||
@TaskAction | ||
public void createRepository() { | ||
AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class); | ||
AmazonECR ecr = ext.getClient(); | ||
|
||
String repositoryName = MoreObjects.firstNonNull(getRepositoryName(), ext.getRepositoryName()); | ||
|
||
CreateRepositoryResult result = ecr.createRepository(new CreateRepositoryRequest() | ||
.withRepositoryName(repositoryName)); | ||
repository = result.getRepository(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRDeleteRepositoryTask.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,56 @@ | ||
/* | ||
* 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.ecr; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import org.gradle.api.internal.ConventionTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import com.amazonaws.services.ecr.AmazonECR; | ||
import com.amazonaws.services.ecr.model.DeleteRepositoryRequest; | ||
import com.amazonaws.services.ecr.model.DeleteRepositoryResult; | ||
import com.amazonaws.services.ecr.model.Repository; | ||
import com.google.common.base.MoreObjects; | ||
|
||
public class AmazonECRDeleteRepositoryTask extends ConventionTask { | ||
|
||
@Getter | ||
@Setter | ||
private String repositoryName; | ||
|
||
@Getter | ||
private Repository repository; | ||
|
||
|
||
public AmazonECRDeleteRepositoryTask() { | ||
setDescription("Delete ECR repository"); | ||
setGroup("AWS"); | ||
} | ||
|
||
@TaskAction | ||
public void createRepository() { | ||
AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class); | ||
AmazonECR ecr = ext.getClient(); | ||
|
||
String repositoryName = MoreObjects.firstNonNull(getRepositoryName(), ext.getRepositoryName()); | ||
|
||
DeleteRepositoryResult result = ecr.deleteRepository(new DeleteRepositoryRequest() | ||
.withRepositoryName(repositoryName)); | ||
repository = result.getRepository(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRGetAuthorizationTokenTask.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,62 @@ | ||
/* | ||
* 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.ecr; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.internal.ConventionTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import com.amazonaws.services.ecr.AmazonECR; | ||
import com.amazonaws.services.ecr.model.AuthorizationData; | ||
import com.amazonaws.services.ecr.model.GetAuthorizationTokenRequest; | ||
import com.amazonaws.services.ecr.model.GetAuthorizationTokenResult; | ||
|
||
public class AmazonECRGetAuthorizationTokenTask extends ConventionTask { | ||
|
||
@Getter | ||
@Setter | ||
private List<String> repositoryIds; | ||
|
||
@Getter | ||
private List<AuthorizationData> authorizationData; | ||
|
||
|
||
public AmazonECRGetAuthorizationTokenTask() { | ||
setDescription("Get authorization token for ECR repository"); | ||
setGroup("AWS"); | ||
} | ||
|
||
@TaskAction | ||
public void createRepository() { | ||
List<String> repositoryIds = getRepositoryIds(); | ||
|
||
if (repositoryIds == null || repositoryIds.isEmpty()) { | ||
throw new GradleException("Must specify ECR repositoryIds"); | ||
} | ||
|
||
AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class); | ||
AmazonECR ecr = ext.getClient(); | ||
|
||
GetAuthorizationTokenResult result = ecr.getAuthorizationToken(new GetAuthorizationTokenRequest() | ||
.withRegistryIds(repositoryIds)); | ||
authorizationData = result.getAuthorizationData(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRPlugin.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.ecr; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
import jp.classmethod.aws.gradle.AwsPlugin; | ||
|
||
public class AmazonECRPlugin implements Plugin<Project> { | ||
|
||
public void apply(Project project) { | ||
project.getPluginManager().apply(AwsPlugin.class); | ||
project.getExtensions().create(AmazonECRPluginExtension.NAME, AmazonECRPluginExtension.class, project); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/jp/classmethod/aws/gradle/ecr/AmazonECRPluginExtension.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,39 @@ | ||
/* | ||
* 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.ecr; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import org.gradle.api.Project; | ||
|
||
import com.amazonaws.services.ecr.AmazonECRClient; | ||
|
||
import jp.classmethod.aws.gradle.common.BaseRegionAwarePluginExtension; | ||
|
||
public class AmazonECRPluginExtension extends BaseRegionAwarePluginExtension<AmazonECRClient> { | ||
|
||
public static final String NAME = "ecr"; | ||
|
||
@Getter | ||
@Setter | ||
private String repositoryName; | ||
|
||
|
||
public AmazonECRPluginExtension(Project project) { | ||
super(project, AmazonECRClient.class); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/META-INF/gradle-plugins/jp.classmethod.aws.ecr.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.ecr.AmazonECRPlugin |