Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud storage function #72

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
delete encryption key.
  • Loading branch information
takuya1981 committed Jun 11, 2019
commit 4fc783685a06f35bce0702ecf059aae8952efc89
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FirebaseAdmin.Cloud;
using Google.Cloud.Storage.V1;
using Xunit;
Expand All @@ -38,23 34,6 @@ public void UseBucket()
this.TestBucket(FirebaseApp.DefaultInstance.GetProjectId(), storageClient);
}

[Fact]
public void UseBucketWithCustomEncryptionKey()
{
var app = FirebaseApp.Create(FirebaseApp.DefaultInstance.Options, "CustomEncryptionApp");
try
{
EncryptionKey encryptionKey = EncryptionKey.Generate();
var storageClient = StorageClientHelper.GetStorageClient(app, encryptionKey);
Assert.Equal(encryptionKey, storageClient.EncryptionKey);
this.TestBucket(app.GetProjectId(), storageClient);
}
finally
{
app.Delete();
}
}

private void TestBucket(string projectId, StorageClient storageClient)
{
var bucketName = IntegrationTestUtils.GetDefaultBucketName(projectId);
Expand Down
17 changes: 0 additions & 17 deletions FirebaseAdmin/FirebaseAdmin.Tests/Cloud/StorageClientHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 13,6 @@
// limitations under the License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FirebaseAdmin.Cloud;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Storage.V1;
using Xunit;
Expand Down Expand Up @@ -56,17 50,6 @@ public void GetStorageClient()
Assert.Throws<InvalidOperationException>(() => StorageClientHelper.GetStorageClient(app));
}

[Fact]
public void GetStorageClientWithEncryptionKey()
{
var app = FirebaseApp.Create(new AppOptions() { Credential = MockCredential });
EncryptionKey encryptionKey = EncryptionKey.Generate();
StorageClient storageClient = StorageClientHelper.GetStorageClient(app, encryptionKey);
Assert.Same(storageClient, StorageClientHelper.GetStorageClient(app, encryptionKey));
app.Delete();
Assert.Throws<InvalidOperationException>(() => StorageClientHelper.GetStorageClient(app, encryptionKey));
}

[Fact]
public void UseAfterDelete()
{
Expand Down
16 changes: 6 additions & 10 deletions FirebaseAdmin/FirebaseAdmin/Cloud/StorageClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 13,6 @@
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Text;
using Google.Cloud.Storage.V1;

namespace FirebaseAdmin.Cloud
Expand All @@ -27,27 25,26 @@ public sealed class StorageClientHelper : IFirebaseService
{
private StorageClient storageClient;

private StorageClientHelper(FirebaseApp app, EncryptionKey encryptionKey = null)
private StorageClientHelper(FirebaseApp app)
{
this.storageClient = StorageClient.Create(app.Options.Credential, encryptionKey);
this.storageClient = StorageClient.Create(app.Options.Credential);
}

/// <summary>
/// Gets the StorageClient instance associated with the default Firebase app. Return value is
/// <c>null</c> if the default app doesn't yet exist.
/// </summary>
/// <param name="encryptionKey">Optional EncryptionKey to use for all relevant object-based operations by default. May be null.</param>
/// <returns>The <see cref="StorageClient"/> instance associated with the specified
/// app.</returns>
public static StorageClient GetStorageClient(EncryptionKey encryptionKey = null)
public static StorageClient GetStorageClient()
{
var app = FirebaseApp.DefaultInstance;
if (app == null)
{
return null;
}

return GetStorageClient(app, encryptionKey);
return GetStorageClient(app);
}

/// <summary>
Expand All @@ -57,8 54,7 @@ public static StorageClient GetStorageClient(EncryptionKey encryptionKey = null)
/// app.</returns>
/// <exception cref="System.ArgumentNullException">If the app argument is null.</exception>
/// <param name="app">An app instance.</param>
/// <param name="encryptionKey">Optional EncryptionKey to use for all relevant object-based operations by default. May be null.</param>
public static StorageClient GetStorageClient(FirebaseApp app, EncryptionKey encryptionKey = null)
public static StorageClient GetStorageClient(FirebaseApp app)
{
if (app == null)
{
Expand All @@ -67,7 63,7 @@ public static StorageClient GetStorageClient(FirebaseApp app, EncryptionKey encr

return app.GetOrInit<StorageClientHelper>(typeof(StorageClientHelper).Name, () =>
{
return new StorageClientHelper(app, encryptionKey);
return new StorageClientHelper(app);
}).storageClient;
}

Expand Down