|
| 1 | +/* |
| 2 | + * Copyright 2014-2021 Andrew Gaul <andrew@gaul.org> |
| 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 | + * https://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 org.gaul.s3proxy.azureblob; |
| 18 | + |
| 19 | +import java.net.URI; |
| 20 | +import java.util.Properties; |
| 21 | + |
| 22 | +import com.google.auto.service.AutoService; |
| 23 | + |
| 24 | +import org.jclouds.azure.storage.config.AzureStorageProperties; |
| 25 | +import org.jclouds.oauth.v2.config.CredentialType; |
| 26 | +import org.jclouds.oauth.v2.config.OAuthProperties; |
| 27 | +import org.jclouds.providers.ProviderMetadata; |
| 28 | +import org.jclouds.providers.internal.BaseProviderMetadata; |
| 29 | + |
| 30 | +/** |
| 31 | + * Implementation of org.jclouds.types.ProviderMetadata for Microsoft Azure |
| 32 | + * Blob Service. |
| 33 | + */ |
| 34 | +@AutoService(ProviderMetadata.class) |
| 35 | +public final class AzureBlobProviderMetadata extends BaseProviderMetadata { |
| 36 | + public AzureBlobProviderMetadata() { |
| 37 | + super(builder()); |
| 38 | + } |
| 39 | + |
| 40 | + public AzureBlobProviderMetadata(Builder builder) { |
| 41 | + super(builder); |
| 42 | + } |
| 43 | + |
| 44 | + public static Builder builder() { |
| 45 | + return new Builder(); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public Builder toBuilder() { |
| 50 | + return builder().fromProviderMetadata(this); |
| 51 | + } |
| 52 | + |
| 53 | + public static Properties defaultProperties() { |
| 54 | + Properties properties = new Properties(); |
| 55 | + properties.put("oauth.endpoint", "https://#.microsoft.com/${" + |
| 56 | + AzureStorageProperties.TENANT_ID + "}/oauth2/token"); |
| 57 | + properties.put(OAuthProperties.RESOURCE, "https://storage.azure.com"); |
| 58 | + properties.put(OAuthProperties.CREDENTIAL_TYPE, |
| 59 | + CredentialType.CLIENT_CREDENTIALS_SECRET.toString()); |
| 60 | + properties.put(AzureStorageProperties.ACCOUNT, "${jclouds.identity}"); |
| 61 | + return properties; |
| 62 | + } |
| 63 | + public static final class Builder extends BaseProviderMetadata.Builder { |
| 64 | + protected Builder() { |
| 65 | + id("azureblob-sdk") |
| 66 | + .name("Microsoft Azure Blob Service") |
| 67 | + .apiMetadata(new AzureBlobApiMetadata()) |
| 68 | + .endpoint("https://${" + AzureStorageProperties.ACCOUNT + |
| 69 | + "}.blob.core.windows.net") |
| 70 | + .homepage(URI.create( |
| 71 | + "http://www.microsoft.com/windowsazure/storage/")) |
| 72 | + .console(URI.create("https://windows.azure.com/default.aspx")) |
| 73 | + .linkedServices("azureblob", "azurequeue", "azuretable") |
| 74 | + .iso3166Codes("US-TX", "US-IL", "IE-D", "SG", "NL-NH", "HK") |
| 75 | + .defaultProperties( |
| 76 | + AzureBlobProviderMetadata.defaultProperties()); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public AzureBlobProviderMetadata build() { |
| 81 | + return new AzureBlobProviderMetadata(this); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public Builder fromProviderMetadata( |
| 86 | + ProviderMetadata in) { |
| 87 | + super.fromProviderMetadata(in); |
| 88 | + return this; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments