createGCSClient static method

Future<AutoRefreshingAuthClient> createGCSClient(
  1. Object credential
)

Implementation

static Future<auth.AutoRefreshingAuthClient> createGCSClient(
    Object credential) async {
  if (credential is String) {
    var credentialLC = credential.toLowerCase();
    if (credentialLC == 'metadata' || credentialLC == 'metadata.server') {
      return auth.clientViaMetadataServer();
    }
  }

  final accountCredentials =
      auth.ServiceAccountCredentials.fromJson(credential);

  try {
    var client = await auth.clientViaServiceAccount(
        accountCredentials, gcs.Storage.SCOPES);
    return client;
  } catch (e) {
    throw StateError("Error creating GCP client: $e");
  }
}