// Path: provider/src/main/java/com/cloudera/director/google/internal/GoogleCredentials.java
// public class GoogleCredentials {
// 
//   private final Config applicationProperties;
//   private final String projectId;
//   private final String jsonKey;
//   private final Compute compute;
//   private final SQLAdmin sqlAdmin;
// 
//   public GoogleCredentials(Config applicationProperties, String projectId, String jsonKey) {
//     this.applicationProperties = applicationProperties;
//     this.projectId = projectId;
//     this.jsonKey = jsonKey;
//     this.compute = buildCompute();
//     this.sqlAdmin = buildSQLAdmin();
//   }
// 
//   private Compute buildCompute() {
//     try {
//       JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
//       HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
//       GoogleCredential credential;
// 
//       if (jsonKey != null) {
//         credential = GoogleCredential.fromStream(
//             new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY)
//             .createScoped(Collections.singleton(ComputeScopes.COMPUTE));
//       } else {
//         Collection COMPUTE_SCOPES = Collections.singletonList(ComputeScopes.COMPUTE);
// 
//         credential = GoogleCredential
//             .getApplicationDefault(httpTransport, JSON_FACTORY)
//             .createScoped(COMPUTE_SCOPES);
//       }
// 
//       return new Compute.Builder(httpTransport,
//           JSON_FACTORY,
//           null)
//           .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties))
//           .setHttpRequestInitializer(credential)
//           .build();
// 
//     } catch (Exception e) {
//       throw new RuntimeException(e);
//     }
//   }
// 
//   private SQLAdmin buildSQLAdmin() {
//     try {
//       JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
//       HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
//       GoogleCredential credential;
// 
//       if (jsonKey != null) {
//         credential = GoogleCredential.fromStream(
//             new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY)
//             .createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN));
//       } else {
//         Collection SQLSERVICE_ADMIN_SCOPES = Collections.singletonList(SQLAdminScopes.SQLSERVICE_ADMIN);
// 
//         credential = GoogleCredential
//             .getApplicationDefault(httpTransport, JSON_FACTORY)
//             .createScoped(SQLSERVICE_ADMIN_SCOPES);
//       }
// 
//       return new SQLAdmin.Builder(httpTransport,
//           JSON_FACTORY,
//           null)
//           .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties))
//           .setHttpRequestInitializer(credential)
//           .build();
// 
//     } catch (Exception e) {
//       throw new RuntimeException(e);
//     }
//   }
// 
//   public String getProjectId() {
//     return projectId;
//   }
// 
//   public String getJsonKey() {
//     return jsonKey;
//   }
// 
//   public Compute getCompute() {
//     return compute;
//   }
// 
//   public SQLAdmin getSQLAdmin() {
//     return sqlAdmin;
//   }
// 
//   public boolean match(String projectId, String jsonKey) {
//     return projectId.equals(this.projectId) &&
//         jsonKey.equals(this.jsonKey);
//   }
// }


import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
import com.cloudera.director.google.internal.GoogleCredentials;
import com.cloudera.director.spi.v1.common.http.HttpProxyParameters;
import com.cloudera.director.spi.v1.model.Configured;
import com.cloudera.director.spi.v1.model.LocalizationContext;
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException;
import com.cloudera.director.spi.v1.provider.CloudProvider;
import com.cloudera.director.spi.v1.provider.CredentialsProvider;
import com.cloudera.director.spi.v1.provider.util.AbstractLauncher;
import com.google.api.services.compute.Compute;
import com.google.common.annotations.VisibleForTesting;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigSyntax;
    return ConfigFactory.parseResourcesAnySyntax(GoogleLauncher.class, configPath, options);
  }

  /**
   * Parses the specified configuration file.
   *
   * @param configFile the configuration file
   * @return the parsed configuration
   */
  private static Config parseConfigFromFile(File configFile) {
    ConfigParseOptions options = ConfigParseOptions.defaults()
        .setSyntax(ConfigSyntax.CONF)
        .setAllowMissing(false);

    return ConfigFactory.parseFileAnySyntax(configFile, options);
  }

  @Override
  public CloudProvider createCloudProvider(String cloudProviderId, Configured configuration,
      Locale locale) {

    if (!GoogleCloudProvider.ID.equals(cloudProviderId)) {
      throw new IllegalArgumentException("Cloud provider not found: " + cloudProviderId);
    }

    LocalizationContext localizationContext = getLocalizationContext(locale);

    // At this point the configuration object will already contain
    // the required data for authentication.

// Path: provider/src/main/java/com/cloudera/director/google/internal/GoogleCredentials.java
// public class GoogleCredentials {
// 
//   private final Config applicationProperties;
//   private final String projectId;
//   private final String jsonKey;
//   private final Compute compute;
//   private final SQLAdmin sqlAdmin;
// 
//   public GoogleCredentials(Config applicationProperties, String projectId, String jsonKey) {
//     this.applicationProperties = applicationProperties;
//     this.projectId = projectId;
//     this.jsonKey = jsonKey;
//     this.compute = buildCompute();
//     this.sqlAdmin = buildSQLAdmin();
//   }
// 
//   private Compute buildCompute() {
//     try {
//       JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
//       HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
//       GoogleCredential credential;
// 
//       if (jsonKey != null) {
//         credential = GoogleCredential.fromStream(
//             new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY)
//             .createScoped(Collections.singleton(ComputeScopes.COMPUTE));
//       } else {
//         Collection COMPUTE_SCOPES = Collections.singletonList(ComputeScopes.COMPUTE);
// 
//         credential = GoogleCredential
//             .getApplicationDefault(httpTransport, JSON_FACTORY)
//             .createScoped(COMPUTE_SCOPES);
//       }
// 
//       return new Compute.Builder(httpTransport,
//           JSON_FACTORY,
//           null)
//           .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties))
//           .setHttpRequestInitializer(credential)
//           .build();
// 
//     } catch (Exception e) {
//       throw new RuntimeException(e);
//     }
//   }
// 
//   private SQLAdmin buildSQLAdmin() {
//     try {
//       JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
//       HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
//       GoogleCredential credential;
// 
//       if (jsonKey != null) {
//         credential = GoogleCredential.fromStream(
//             new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY)
//             .createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN));
//       } else {
//         Collection SQLSERVICE_ADMIN_SCOPES = Collections.singletonList(SQLAdminScopes.SQLSERVICE_ADMIN);
// 
//         credential = GoogleCredential
//             .getApplicationDefault(httpTransport, JSON_FACTORY)
//             .createScoped(SQLSERVICE_ADMIN_SCOPES);
//       }
// 
//       return new SQLAdmin.Builder(httpTransport,
//           JSON_FACTORY,
//           null)
//           .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties))
//           .setHttpRequestInitializer(credential)
//           .build();
// 
//     } catch (Exception e) {
//       throw new RuntimeException(e);
//     }
//   }
// 
//   public String getProjectId() {
//     return projectId;
//   }
// 
//   public String getJsonKey() {
//     return jsonKey;
//   }
// 
//   public Compute getCompute() {
//     return compute;
//   }
// 
//   public SQLAdmin getSQLAdmin() {
//     return sqlAdmin;
//   }
// 
//   public boolean match(String projectId, String jsonKey) {
//     return projectId.equals(this.projectId) &&
//         jsonKey.equals(this.jsonKey);
//   }
// }


// Path: provider/src/main/java/com/cloudera/director/google/GoogleLauncher.java
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
import com.cloudera.director.google.internal.GoogleCredentials;
import com.cloudera.director.spi.v1.common.http.HttpProxyParameters;
import com.cloudera.director.spi.v1.model.Configured;
import com.cloudera.director.spi.v1.model.LocalizationContext;
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException;
import com.cloudera.director.spi.v1.provider.CloudProvider;
import com.cloudera.director.spi.v1.provider.CredentialsProvider;
import com.cloudera.director.spi.v1.provider.util.AbstractLauncher;
import com.google.api.services.compute.Compute;
import com.google.common.annotations.VisibleForTesting;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigSyntax;

    return ConfigFactory.parseResourcesAnySyntax(GoogleLauncher.class, configPath, options);
  }

  /**
   * Parses the specified configuration file.
   *
   * @param configFile the configuration file
   * @return the parsed configuration
   */
  private static Config parseConfigFromFile(File configFile) {
    ConfigParseOptions options = ConfigParseOptions.defaults()
        .setSyntax(ConfigSyntax.CONF)
        .setAllowMissing(false);

    return ConfigFactory.parseFileAnySyntax(configFile, options);
  }

  @Override
  public CloudProvider createCloudProvider(String cloudProviderId, Configured configuration,
      Locale locale) {

    if (!GoogleCloudProvider.ID.equals(cloudProviderId)) {
      throw new IllegalArgumentException("Cloud provider not found: " + cloudProviderId);
    }

    LocalizationContext localizationContext = getLocalizationContext(locale);

    // At this point the configuration object will already contain
    // the required data for authentication.

    CredentialsProvider<GoogleCredentials> provider = new GoogleCredentialsProvider(applicationProperties);