Skip to content
Permalink
Browse files
Merge remote-tracking branch 'jclouds-labs-google-local/promote-googl…
…e-cloud-storage-moved' into promoted-google-cloud-storage
  • Loading branch information
gaul committed May 7, 2017
2 parents 1c6c36b + b671d2c commit 6efc894e3fe9d6cc4958360ba0811aec6c279b30
Show file tree
Hide file tree
Showing 130 changed files with 11,348 additions and 0 deletions.
@@ -0,0 +1,51 @@
jclouds Google Cloud Storage Provider
======
Make sure both Google Cloud Storage and Google Cloud Storage JSON API are enabled for the project
(check from Developers Console -> Api&auth -> APIs)

FAQ:
--------

* Q. What is the identity for Google Cloud Storage?

A. the identity is the developer email which can be obtained from the admin GUI. Its usually something in the form: [PROJECT_ID](https://cloud.google.com/compute/docs/overview#projectids)@developer.gserviceaccount.com

* Q. What is the credential for Google Cloud Storage

A. the credential is a private key, in pem format. It can be extracted from the p12 keystore that is obtained when creating a "Service Account" (in the GUI: Google apis console > Api Access > Create another client ID > "Service Account"

* Q. How to convert a p12 keystore into a pem format jclouds Google Cloud Storage can handle:

A.

1. Convert the p12 file into pem format (it will ask for the keystore password, which is usually "notasecret"):
openssl pkcs12 -in <my_keystore>.p12 -out <my_keystore>.pem -nodes

2. Extract only the pk and remove passphrase
openssl rsa -in <my_keystore>.pem -out <my_key>.pem

The last file (<my_key>.pem) should contain the pk that needs to be passed to `ContextBuilder.credential()` for the provider `google-cloud-storage`.


Running the live tests:
--------

1. Place the following in your ~/.m2/settings.xml in a profile enabled when live:
```
<test.google-cloud-storage.identity>PROJECT_ID@developer.gserviceaccount.com</test.google-cloud-storage.identity>
<test.google-cloud-storage.credential>-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQRRbRqVDtJLN1MO/xJoKqZuphDeBh5jIKueW3aNIiWs1XFcct+h
-- this text is literally from your <my_key>.pem
aH7xmpHSTbbXmQkuuv+z8EKijigprd/FoJpTX1f5/R+4wQ==
-----END RSA PRIVATE KEY-----</test.google-cloud-storage.credential>
</properties>
```
Or, if using an existing OAuth Bearer Token for authentication.
```
<test.google-cloud-storage.identity>PROJECT_ID@developer.gserviceaccount.com</test.google-cloud-storage.identity>
<test.google-cloud-storage.credential>EXISTING_BEARER_TOKEN</test.google-cloud-storage.credential>
<test.jclouds.oauth.credential-type>bearerTokenCredentials</test.jclouds.oauth.credential-type>
</properties>
```

2. mvn clean install -Plive
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>jclouds-labs-google</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<!-- TODO: when out of labs, switch to org.jclouds.provider -->
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>google-cloud-storage</artifactId>
<name>jclouds Google Cloud Storage provider</name>
<description>jclouds components to access Google Cloud Storage</description>
<packaging>bundle</packaging>

<properties>
<test.google-cloud-storage.identity>client_email which usually looks like project_id@developer.gserviceaccount.com</test.google-cloud-storage.identity>
<test.google-cloud-storage.credential>Private key (PEM encoded PKCS12 file or literal) associated with the client_email</test.google-cloud-storage.credential>
<!-- Add this property to use a different project, or avoid looking up the project for each test. -->
<test.jclouds.googlecloud.project-name></test.jclouds.googlecloud.project-name>
<test.jclouds.oauth.credential-type>p12PrivateKeyCredentials</test.jclouds.oauth.credential-type>
<test.google-cloud-storage.api-version>v1</test.google-cloud-storage.api-version>
<test.google-cloud-storage.build-version/>
<jclouds.osgi.export>org.jclouds.googlecloudstorage*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.common</groupId>
<artifactId>googlecloud</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.jclouds.common</groupId>
<artifactId>googlecloud</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>oauth</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${jclouds.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${jclouds.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${jclouds.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-okhttp</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>
<!-- Already provided by jclouds-sshj -->
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skipTests>true</skipTests>
</configuration>
</execution>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<threadCount>1</threadCount>
<systemPropertyVariables>
<test.google-cloud-storage.identity>${test.google-cloud-storage.identity}</test.google-cloud-storage.identity>
<test.google-cloud-storage.credential>${test.google-cloud-storage.credential}</test.google-cloud-storage.credential>
<test.jclouds.googlecloud.project-name>${test.jclouds.googlecloud.project-name}</test.jclouds.googlecloud.project-name>
<test.jclouds.oauth.credential-type>${test.jclouds.oauth.credential-type}</test.jclouds.oauth.credential-type>
<test.google-cloud-storage.api-version>${test.google-cloud-storage.api-version}</test.google-cloud-storage.api-version>
<test.google-cloud-storage.build-version>${test.google-cloud-storage.build-version}</test.google-cloud-storage.build-version>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.jclouds.googlecloudstorage;

import java.io.Closeable;

import javax.ws.rs.Path;

import org.jclouds.googlecloudstorage.features.BucketAccessControlsApi;
import org.jclouds.googlecloudstorage.features.BucketApi;
import org.jclouds.googlecloudstorage.features.DefaultObjectAccessControlsApi;
import org.jclouds.googlecloudstorage.features.ObjectAccessControlsApi;
import org.jclouds.googlecloudstorage.features.ObjectApi;
import org.jclouds.googlecloudstorage.features.ResumableUploadApi;
import org.jclouds.rest.annotations.Delegate;

/**
* Provide access to GoogleCloudStorage
*
* @see <a href="https://developers.google.com/storage/docs/json_api/v1/">api doc /a>
*/
public interface GoogleCloudStorageApi extends Closeable {

/**
* Provides access to Default Object Access Control features on bucket
*/
@Delegate
@Path("/storage/v1")
DefaultObjectAccessControlsApi getDefaultObjectAccessControlsApi();

/**
* Provides access to Bucket Access Control features
*/
@Delegate
@Path("/storage/v1")
BucketAccessControlsApi getBucketAccessControlsApi();

/**
* Provides access to Bucket features
*/
@Delegate
@Path("/storage/v1")
BucketApi getBucketApi();

/**
* Provides access to Object Access Control features
*/
@Delegate
@Path("/storage/v1")
ObjectAccessControlsApi getObjectAccessControlsApi();

/**
* Provides access to Google Cloud Storage Object features
*/
@Delegate
ObjectApi getObjectApi();

/**
* Provides access to Google Cloud Storage ResumableUpload features
*/
@Delegate
ResumableUploadApi getResumableUploadApi();
}
@@ -0,0 +1,96 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.jclouds.googlecloudstorage;

import static org.jclouds.Constants.PROPERTY_IDEMPOTENT_METHODS;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.OPERATION_COMPLETE_INTERVAL;
import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.OPERATION_COMPLETE_TIMEOUT;
import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
import static org.jclouds.reflect.Reflection2.typeToken;

import java.net.URI;
import java.util.Properties;

import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.googlecloud.config.CurrentProject;
import org.jclouds.googlecloudstorage.blobstore.config.GoogleCloudStorageBlobStoreContextModule;
import org.jclouds.googlecloudstorage.config.GoogleCloudStorageHttpApiModule;
import org.jclouds.googlecloudstorage.config.GoogleCloudStorageParserModule;
import org.jclouds.oauth.v2.config.OAuthModule;
import org.jclouds.rest.internal.BaseHttpApiMetadata;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;

public class GoogleCloudStorageApiMetadata extends BaseHttpApiMetadata<GoogleCloudStorageApi> {

@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}

public GoogleCloudStorageApiMetadata() {
this(new Builder());
}

protected GoogleCloudStorageApiMetadata(Builder builder) {
super(builder);
}

public static Properties defaultProperties() {
Properties properties = BaseHttpApiMetadata.defaultProperties();
properties.put("oauth.endpoint", "https://accounts.google.com/o/oauth2/token");
properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
properties.put(JWS_ALG, "RS256");
properties.put(PROPERTY_SESSION_INTERVAL, 3600);
properties.put(OPERATION_COMPLETE_INTERVAL, 2000);
properties.put(OPERATION_COMPLETE_TIMEOUT, 600000);
properties.setProperty(PROPERTY_IDEMPOTENT_METHODS, "DELETE,GET,HEAD,OPTIONS,POST,PUT");
return properties;
}

public static class Builder extends BaseHttpApiMetadata.Builder<GoogleCloudStorageApi, Builder> {
protected Builder() {
id("google-cloud-storage")
.name("Google Cloud Storage Api")
.identityName(CurrentProject.ClientEmail.DESCRIPTION)
.credentialName("PEM encoded P12 private key associated with client_email")
.documentation(URI.create("https://developers.google.com/storage/docs/json_api"))
.version("v1")
.defaultEndpoint("https://www.googleapis.com")
.defaultProperties(GoogleCloudStorageApiMetadata.defaultProperties())
.view(typeToken(BlobStoreContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>> builder()
.add(GoogleCloudStorageParserModule.class)
.add(OAuthModule.class)
.add(GoogleCloudStorageHttpApiModule.class)
.add(GoogleCloudStorageBlobStoreContextModule.class).build());
}

@Override
public GoogleCloudStorageApiMetadata build() {
return new GoogleCloudStorageApiMetadata(this);
}

@Override
protected Builder self() {
return this;
}
}
}

0 comments on commit 6efc894

Please sign in to comment.