Use SitePaths to acquire GCP Credentials

Credential path will be expected in the gerritsite/etc/ directory.

Change-Id: I1775e05cdc0f68e5458b4de43b42ca6ed9fe71cc
diff --git a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Module.java b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Module.java
index 88fff7c..826d4db 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Module.java
@@ -26,6 +26,8 @@
 import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.lifecycle.LifecycleModule;
 import com.google.gerrit.server.config.PluginConfigFactory;
+import com.google.gerrit.server.config.SitePaths;
+import com.google.inject.Inject;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
 import com.google.inject.Singleton;
@@ -46,6 +48,8 @@
   public static final String SECTION = "ref-database";
   public static final String SUBSECTION = "spanner";
 
+  private SitePaths sitePaths;
+
   @Override
   protected void configure() {
     logger.atInfo().log("Configuring Cloud Spanner for global refdb.");
@@ -61,6 +65,11 @@
     listener().to(HeartbeatExecutorProvider.class);
   }
 
+  @Inject
+  Module(SitePaths sitePaths) {
+    this.sitePaths = sitePaths;
+  }
+
   @Provides
   @Singleton
   private Config Configuration(PluginConfigFactory configFactory, @PluginName String pluginName) {
@@ -79,7 +88,8 @@
     } else {
       String credentialsPath = getString(cfg, SECTION, SUBSECTION, CREDENTIALS_KEY, null);
       GoogleCredentials credentials =
-          GoogleCredentials.fromStream(new FileInputStream(credentialsPath));
+          GoogleCredentials.fromStream(
+              new FileInputStream(sitePaths.etc_dir.resolve(credentialsPath).toString()));
       options = SpannerOptions.newBuilder().setCredentials(credentials).build();
     }
     return options;
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index f715531..7d1159b 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -9,7 +9,7 @@
         instance = spanner-instance
         database = global-refdb
         useEmulator = false
-        credentialsPath = /path/to/credentials.json
+        credentialsPath = credentials.json
 ```
 
 `ref-database.spanner.instance`
@@ -25,5 +25,5 @@
 `Default: false.`
 
 `ref-database.spanner.credentialsPath`
-:   Required when not using the emulator. The path to Google cloud credentials.
+:   Required when not using the emulator. The name of the google cloud credentials file in the site/etc directory.
 `Default: null.`