-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(s3): Refactor S3 config to support separate plugin binaries bucket (
#715)
- Loading branch information
1 parent
5fc94d5
commit 5749544
Showing
12 changed files
with
152 additions
and
72 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
72 changes: 72 additions & 0 deletions
72
front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3ClientFactory.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,72 @@ | ||
/* | ||
* Copyright 2020 Netflix, 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. | ||
*/ | ||
package com.netflix.spinnaker.front50.config; | ||
|
||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.Protocol; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.regions.Region; | ||
import com.amazonaws.regions.Regions; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.S3ClientOptions; | ||
import java.util.Optional; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* Creates an S3 client. | ||
* | ||
* <p>Since there are multiple implementations of {@link S3Properties} and we create different | ||
* clients based on those properties, the actual factory code needed to be split out. | ||
*/ | ||
public class S3ClientFactory { | ||
|
||
public static AmazonS3 create( | ||
AWSCredentialsProvider awsCredentialsProvider, S3Properties s3Properties) { | ||
ClientConfiguration clientConfiguration = new ClientConfiguration(); | ||
if (s3Properties.getProxyProtocol() != null) { | ||
if (s3Properties.getProxyProtocol().equalsIgnoreCase("HTTPS")) { | ||
clientConfiguration.setProtocol(Protocol.HTTPS); | ||
} else { | ||
clientConfiguration.setProtocol(Protocol.HTTP); | ||
} | ||
Optional.ofNullable(s3Properties.getProxyHost()).ifPresent(clientConfiguration::setProxyHost); | ||
Optional.ofNullable(s3Properties.getProxyPort()) | ||
.map(Integer::parseInt) | ||
.ifPresent(clientConfiguration::setProxyPort); | ||
} | ||
|
||
AmazonS3Client client = new AmazonS3Client(awsCredentialsProvider, clientConfiguration); | ||
|
||
if (!StringUtils.isEmpty(s3Properties.getEndpoint())) { | ||
client.setEndpoint(s3Properties.getEndpoint()); | ||
|
||
if (!StringUtils.isEmpty(s3Properties.getRegionOverride())) { | ||
client.setSignerRegionOverride(s3Properties.getRegionOverride()); | ||
} | ||
|
||
client.setS3ClientOptions( | ||
S3ClientOptions.builder().setPathStyleAccess(s3Properties.getPathStyleAccess()).build()); | ||
} else { | ||
Optional.ofNullable(s3Properties.getRegion()) | ||
.map(Regions::fromName) | ||
.map(Region::getRegion) | ||
.ifPresent(client::setRegion); | ||
} | ||
|
||
return client; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3MetadataStorageProperties.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,21 @@ | ||
/* | ||
* Copyright 2020 Netflix, 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. | ||
*/ | ||
package com.netflix.spinnaker.front50.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("spinnaker.s3") | ||
public class S3MetadataStorageProperties extends S3Properties {} |
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
21 changes: 21 additions & 0 deletions
21
front50-s3/src/main/java/com/netflix/spinnaker/front50/config/S3PluginStorageProperties.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,21 @@ | ||
/* | ||
* Copyright 2020 Netflix, 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. | ||
*/ | ||
package com.netflix.spinnaker.front50.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("spinnaker.s3.plugin-storage") | ||
public class S3PluginStorageProperties extends S3Properties {} |
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
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