ignite-1000: reading key from json

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bbbcf0b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bbbcf0b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bbbcf0b8

Branch: refs/heads/ignite-1000
Commit: bbbcf0b8836fd04d1789bbe040dacb32f606aa87
Parents: 2e58e52
Author: Denis Magda <[email protected]>
Authored: Mon Jun 8 16:54:59 2015 +0300
Committer: Denis Magda <[email protected]>
Committed: Mon Jun 8 16:54:59 2015 +0300

----------------------------------------------------------------------
 .../cloud/TcpDiscoveryCloudIpFinder.java        | 21 +++++++++++++++-----
 .../TcpDiscoveryCloudIpFinderSelfTest.java      | 15 +++++++-------
 2 files changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bbbcf0b8/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
 
b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
index 2637742..ff210e5 100644
--- 
a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
+++ 
b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java
@@ -19,6 +19,7 @@ package org.apache.ignite.spi.discovery.tcp.ipfinder.cloud;
 
 import com.google.common.base.*;
 import com.google.common.io.*;
+import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
@@ -30,6 +31,7 @@ import org.jclouds.*;
 import org.jclouds.compute.*;
 import org.jclouds.compute.domain.*;
 import org.jclouds.domain.*;
+import org.jclouds.googlecloud.*;
 import org.jclouds.location.reference.*;
 
 import java.io.*;
@@ -322,7 +324,7 @@ public class TcpDiscoveryCloudIpFinder extends 
TcpDiscoveryIpFinderAdapter {
                     throw new IgniteSpiException("Both credential and 
credentialPath are set. Use only one method.");
 
                 if (credentialPath != null)
-                    credential = getPrivateKeyFromFile();
+                    credential = getCredentialFromFile();
 
                 try {
                     ContextBuilder ctxBuilder = 
ContextBuilder.newBuilder(provider);
@@ -398,13 +400,22 @@ public class TcpDiscoveryCloudIpFinder extends 
TcpDiscoveryIpFinderAdapter {
     }
 
     /**
-     * Retrieves a private key from the secrets file.
+     * Reads credential info from {@link #credentialPath} and returns in a 
string format.
      *
-     * @return Private key
+     * @return Credential in {@code String} representation.
+     * @throws IgniteSpiException In case of error.
      */
-    private String getPrivateKeyFromFile() throws IgniteSpiException {
+    private String getCredentialFromFile() throws IgniteSpiException {
         try {
-            return Files.toString(new File(credentialPath), Charsets.UTF_8);
+            if (!provider.equals("google-compute-engine"))
+                throw new IgniteSpiException("Failed to read credentials from 
file, unsupported provider [" +
+                "provider=" + provider + ", credentialPath=" + credentialPath 
+ ']');
+
+            String fileContents = Files.toString(new File(credentialPath), 
Charsets.UTF_8);
+
+            Supplier<Credentials> credentialSupplier = new 
GoogleCredentialsFromJson(fileContents);
+
+            return credentialSupplier.get().credential;
         }
         catch (IOException e) {
             throw new IgniteSpiException("Failed to retrieve the private key 
from the file: " + credentialPath, e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bbbcf0b8/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
 
b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
index aba0760..618189d 100644
--- 
a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
+++ 
b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java
@@ -59,9 +59,9 @@ public class TcpDiscoveryCloudIpFinderSelfTest extends
      *
      * @throws Exception If any error occurs.
      */
-    public void testAmazonWebServices() throws Exception {
-        testCloudProvider("aws-ec2");
-    }
+    //public void testAmazonWebServices() throws Exception {
+    //    testCloudProvider("aws-ec2");
+    //}
 
     /**
      * Tests GCE.
@@ -77,9 +77,9 @@ public class TcpDiscoveryCloudIpFinderSelfTest extends
      *
      * @throws Exception If any error occurs.
      */
-    public void testRackspace() throws Exception {
-        testCloudProvider("rackspace-cloudservers-us");
-    }
+    //public void testRackspace() throws Exception {
+    //    testCloudProvider("rackspace-cloudservers-us");
+    //}
 
     /**
      * Tests a given provider.
@@ -101,9 +101,8 @@ public class TcpDiscoveryCloudIpFinderSelfTest extends
 
         if (provider.equals("google-compute-engine"))
             
ipFinder.setCredentialPath(IgniteCloudTestSuite.getSecretKey(provider));
-        else {
+        else
             
ipFinder.setCredential(IgniteCloudTestSuite.getSecretKey(provider));
-        }
 
         Collection<InetSocketAddress> addresses = 
ipFinder.getRegisteredAddresses();
 

Reply via email to