Esempio n. 1
0
        private async Task <ServiceAccount> CreateOrGetServiceAccountAsync()
        {
            var service = TestProject.CreateIamService();
            var email   = $"{this.name}@{TestProject.ProjectId}.iam.gserviceaccount.com";

            try
            {
                return(await service.Projects.ServiceAccounts
                       .Get($"projects/{TestProject.ProjectId}/serviceAccounts/{email}")
                       .ExecuteAsync());
            }
            catch (Exception)
            {
                return(await service.Projects.ServiceAccounts.Create(
                           new CreateServiceAccountRequest()
                {
                    AccountId = name,
                    ServiceAccount = new ServiceAccount()
                    {
                        DisplayName = "Test account for integration testing"
                    }
                },
                           $"projects/{TestProject.ProjectId}")
                       .ExecuteAsync()
                       .ConfigureAwait(false));
            }
        }
Esempio n. 2
0
        private static async Task <string> GetComputeEngineDefaultServiceAccount()
        {
            var iamService         = TestProject.CreateIamService();
            var allServiceAccounts = await iamService.Projects.ServiceAccounts
                                     .List($"projects/{TestProject.ProjectId}")
                                     .ExecuteAsync();

            return(allServiceAccounts
                   .Accounts
                   .First(sa => sa.Email.EndsWith("*****@*****.**"))
                   .Email);
        }