public void Initialize() { try { storageClient = StorageClient.Create(); storageClient.GetBucket(bucketName); } catch (Exception ex) { throw new ConfigurationException($"Cannot connect to google cloud bucket '${bucketName}'.", ex); } }
public void ClearBucketLabels() { var bucketName = _fixture.BucketName; // Snippet: ClearBucketLabels(string, *) StorageClient client = StorageClient.Create(); IDictionary <string, string> oldLabels = client.ClearBucketLabels(bucketName); Console.WriteLine($"Number of labels before clearing: {oldLabels.Count}"); // End snippet Assert.Null(client.GetBucket(bucketName).Labels); }
//Storage implementation public void UploadObject(string aBucketName, string aName, string aType, Stream aStream) { try { var bucket = storage.GetBucket(aBucketName, null); storage.UploadObject(aBucketName, aName, aType, aStream); } catch (Google.GoogleApiException e) when(e.Error.Code == 409) { // The bucket already exists. That's fine. Console.WriteLine(e.Error.Message); } }
public void UseAfterDelete() { try { var app = FirebaseApp.Create(new AppOptions() { Credential = MockCredential }); StorageClient storageClient = StorageClientHelper.GetStorageClient(app); app.Delete(); Assert.Throws <ObjectDisposedException>( () => storageClient.GetBucket("test")); } catch (Exception ex) { Assert.NotEmpty(ex.Message); } }
public void RemoveBucketLabel() { var bucketName = _fixture.BucketName; // Snippet: RemoveBucketLabel(string, string, *) StorageClient client = StorageClient.Create(); string oldValue = client.RemoveBucketLabel(bucketName, "label"); Console.WriteLine($"Old value: {oldValue}"); // Verify the label is now gone... Bucket bucket = client.GetBucket(bucketName); string fetchedValue = null; bucket.Labels?.TryGetValue("label", out fetchedValue); Console.WriteLine($"Fetched value: {fetchedValue}"); // End snippet Assert.Null(fetchedValue); }
public void SetBucketLabel() { var bucketName = _fixture.BucketName; // Snippet: SetBucketLabel(string, string, string, *) StorageClient client = StorageClient.Create(); string now = DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture); string newValue = "new_value_" + now; string oldValue = client.SetBucketLabel(bucketName, "label", newValue); Console.WriteLine($"Old value: {oldValue}"); // Verify the label is now correct... Bucket bucket = client.GetBucket(bucketName); string fetchedValue = bucket.Labels?["label"]; Console.WriteLine($"Fetched value: {fetchedValue}"); // End snippet Assert.Equal(newValue, fetchedValue); }
private static void RemoveHolds(StorageClient client, string bucketName) { var bucket = client.GetBucket(bucketName); if (bucket.DefaultEventBasedHold == true) { Console.WriteLine($"Removing default event based hold from bucket {bucket.Name}"); bucket.DefaultEventBasedHold = false; client.UpdateBucket(bucket); } foreach (var obj in client.ListObjects(bucketName)) { if (obj.EventBasedHold == true) { Console.WriteLine($"Removing event based hold from object {obj.Name}"); } obj.EventBasedHold = false; client.UpdateObject(obj); } }
private void MaybeCreateBucket() { try { _client.GetBucket(_bucket); return; } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { // Need to create the bucket... // (But let's do so outside the catch.) } Console.WriteLine($"Creating bucket '{_bucket}'"); var serviceAccount = GoogleCredential.GetApplicationDefault().UnderlyingCredential as ServiceAccountCredential; if (serviceAccount is null) { throw new InvalidOperationException("Default credentials are not for a service account, so we can't determine the project ID"); } _client.CreateBucket(serviceAccount.ProjectId, _bucket); }
public void GetImages() { var imgs = storageClient.GetBucket(bucketName); }
public void InitializeBucket() { _bucket = _storageClient.GetBucket(STORAGE_BUCKET); }
public GoogleClodStorageXmlRepository(GoogleCredential credential, string projectId, string bucketName) { _bucketName = bucketName; _client = StorageClient.Create(credential); _bucket = _client.GetBucket(_bucketName) ?? _client.CreateBucket(_bucketName, projectId); }