public void InvalidBucketNames(string bucket)
        {
            var exception = Assert.ThrowsAny <ArgumentException>(() => StorageClientImpl.ValidateBucket(bucket));

            Assert.Equal("bucket", exception.ParamName);
            Assert.Contains(bucket, exception.Message);
        }
Esempio n. 2
0
        public void GetEffectiveEncryptionKey_Invalid(EncryptionKey clientkey, EncryptionKey operationKey, string kmsKey, string expectedMessageSubstring)
        {
            var service   = new StorageService();
            var client    = new StorageClientImpl(service, clientkey);
            var exception = Assert.Throws <ArgumentException>(() => client.GetEffectiveEncryptionKey(operationKey, kmsKey));

            Assert.Contains(expectedMessageSubstring, exception.Message);
        }
Esempio n. 3
0
        public void GetEffectiveEncryptionKey_Valid(EncryptionKey clientkey, EncryptionKey operationKey, string kmsKey, EncryptionKey expected)
        {
            var service = new StorageService();
            var client  = new StorageClientImpl(service, clientkey);
            var actual  = client.GetEffectiveEncryptionKey(operationKey, kmsKey);

            Assert.Same(expected, actual);
        }
Esempio n. 4
0
        private async Task Run()
        {
// 1. no basic auth, with usercredentials
// need to set export http_proxy=http://localhost:3128 for Pubsub
// need to set ProxySupportedHttpClientFactory for GCS and oauth2

//  auth Y
//  gcs Y
//  pubsub Y


// 1638323879.659    693 192.168.9.1 TCP_TUNNEL/200 45147 CONNECT storage.googleapis.com:443 - HIER_DIRECT/172.253.63.128 -
// 1638323879.659    884 192.168.9.1 TCP_TUNNEL/200 7349 CONNECT oauth2.googleapis.com:443 - HIER_DIRECT/142.251.45.10 -
// 1638323879.659    372 192.168.9.1 TCP_TUNNEL/200 7878 CONNECT pubsub.googleapis.com:443 - HIER_DIRECT/172.217.13.234 -


// 2. no basic auth, with service account credentials
// export GOOGLE_APPLICATION_CREDENTIALS=/path/to/svc_account.json
//  auth N
//  gcs N
//  pubsub Y

// 3. no basicauth, with ServiceAccountCredential
            //var stream = new FileStream("/path/to/svc_account.json", FileMode.Open, FileAccess.Read);
            //ServiceAccountCredential sacredential = ServiceAccountCredential.FromServiceAccountData(stream);
            GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();

            credential = credential.CreateWithHttpClientFactory(new ProxySupportedHttpClientFactory());

            StorageService service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = StorageClientImpl.ApplicationName,
                HttpClientFactory     = new ProxySupportedHttpClientFactory(),
            });
            var client = new StorageClientImpl(service, null);

            foreach (var b in client.ListBuckets(projectID))
            {
                Console.WriteLine(b.Name);
            }

            PublisherServiceApiClient publisher = PublisherServiceApiClient.Create();
            ProjectName projectName             = ProjectName.FromProject(projectID);

            foreach (Topic t in publisher.ListTopics(projectName))
            {
                Console.WriteLine(t.Name);
            }
        }
        public void DownloadGzippedFile_NoClientDecompression()
        {
            var service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = _fixture.Client.Service.HttpClientInitializer,
                GZipEnabled           = false
            });
            var client = new StorageClientImpl(service);
            var stream = new MemoryStream();

            client.DownloadObject(StorageFixture.CrossLanguageTestBucket, "gzipped-text.txt", stream);
            var expected = Encoding.UTF8.GetBytes("hello world");
            var actual   = stream.ToArray();

            Assert.Equal(expected, actual);
        }
        public void DownloadGzippedFile_NoClientDecompression_IgnoreHash()
        {
            TestEnvironment.SkipIfVpcSc();

            var service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = _fixture.Client.Service.HttpClientInitializer,
                GZipEnabled           = false
            });
            var client = new StorageClientImpl(service);
            var stream = new MemoryStream();

            client.DownloadObject(StorageFixture.CrossLanguageTestBucket, "gzipped-text.txt", stream,
                                  new DownloadObjectOptions {
                DownloadValidationMode = DownloadValidationMode.Never
            });
            var expected = Encoding.UTF8.GetBytes("hello world");
            var actual   = stream.ToArray();

            Assert.Equal(expected, actual);
        }
Esempio n. 7
0
        private async Task Run()
        {
            string CREDENTIAL_FILE_PKCS12       = "/path/to/your/cert/file.p12";
            string serviceAccountEmail          = "*****@*****.**";
            var    certificate                  = new X509Certificate2(CREDENTIAL_FILE_PKCS12, "notasecret", X509KeyStorageFlags.Exportable);
            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                //Scopes = new[] { StorageService.Scope.DevstorageReadOnly, PublisherClient.DefaultScopes },
                Scopes            = PublisherClient.DefaultScopes.Append(StorageService.Scope.DevstorageReadOnly),
                HttpClientFactory = new ProxySupportedHttpClientFactory()
            }.FromCertificate(certificate));


            //GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();
            //StorageService service = StorageClient.Create(credential);

            StorageService service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = StorageClientImpl.ApplicationName,
                HttpClientFactory     = new ProxySupportedHttpClientFactory(),
            });
            var client = new StorageClientImpl(service, null);

            foreach (var b in client.ListBuckets(projectID))
            {
                Console.WriteLine(b.Name);
            }

            ChannelCredentials channelCredentials = credential.ToChannelCredentials();
            Channel            channel            = new Channel(PublisherClient.DefaultEndpoint.ToString(), channelCredentials);
            PublisherSettings  ps        = new PublisherSettings();
            PublisherClient    publisher = PublisherClient.Create(channel, ps);

            foreach (Topic t in publisher.ListTopics(new ProjectName(projectID)))
            {
                Console.WriteLine(t.Name);
            }
        }
 public void ValidBucketNames(string bucket)
 {
     StorageClientImpl.ValidateBucket(bucket);
 }