Ejemplo n.º 1
0
        private bool CreateServiceAccountAndKey(UserCredential userCredential, string projectID, string accountID, string displayName)
        {
            try
            {
                var service = new IamService(new IamService.Initializer
                {
                    HttpClientInitializer = userCredential,
                    ApplicationName       = AppName,
                });

                var request2 = new CreateServiceAccountRequest
                {
                    AccountId      = accountID,
                    ServiceAccount = new ServiceAccount
                    {
                        DisplayName = displayName
                    }
                };

                var serviceAccount = service.Projects.ServiceAccounts.Create(
                    request2, "projects/" + projectID).Execute();

                var email = serviceAccount.Email;

                var key = service.Projects.ServiceAccounts.Keys.Create(
                    new CreateServiceAccountKeyRequest(),
                    "projects/-/serviceAccounts/" + email)
                          .Execute();
            }
            catch (Exception)
            {
            }

            return(true);
        }
        public QuickStartTest()
        {
            // Check for _projectId and throw exception if empty
            _projectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");
            if (_projectId == null)
            {
                throw new ArgumentNullException("GOOGLE_PROJECT_ID", "Environment variable not set");
            }

            // Create service account for test
            var credential = GoogleCredential.GetApplicationDefault()
                             .CreateScoped(IamService.Scope.CloudPlatform);

            _iamService = new IamService(
                new IamService.Initializer
            {
                HttpClientInitializer = credential
            });

            var request = new CreateServiceAccountRequest
            {
                AccountId      = "iam-test-account" + DateTime.UtcNow.Millisecond,
                ServiceAccount = new ServiceAccount
                {
                    DisplayName = "iamTestAccount"
                }
            };

            _serviceAccount = _iamService.Projects.ServiceAccounts.Create(
                request, "projects/" + _projectId).Execute();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="callSettings">
 /// If not null, applies overrides to this RPC call.
 /// </param>
 /// <returns>
 /// A Task containing the RPC response.
 /// </returns>
 public override stt::Task <ServiceAccount> CreateServiceAccountAsync(
     CreateServiceAccountRequest request,
     gaxgrpc::CallSettings callSettings = null)
 {
     Modify_CreateServiceAccountRequest(ref request, ref callSettings);
     return(_callCreateServiceAccount.Async(request, callSettings));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="callSettings">
 /// If not null, applies overrides to this RPC call.
 /// </param>
 /// <returns>
 /// The RPC response.
 /// </returns>
 public override ServiceAccount CreateServiceAccount(
     CreateServiceAccountRequest request,
     gaxgrpc::CallSettings callSettings = null)
 {
     Modify_CreateServiceAccountRequest(ref request, ref callSettings);
     return(_callCreateServiceAccount.Sync(request, callSettings));
 }
        public async Task <string> Create(string folderId, string name, string description)
        {
            var channel = new Channel("iam.api.cloud.yandex.net", 443, new SslCredentials());
            var client  = new ServiceAccountService.ServiceAccountServiceClient(channel);
            var request = new CreateServiceAccountRequest
            {
                Description = description,
                FolderId    = folderId,
                Name        = name
            };
            var response = await client.CreateAsync(request);

            return(response.Id);
        }
        // [START iam_create_service_account]
        public static ServiceAccount CreateServiceAccount(string projectId,
                                                          string name, string displayName)
        {
            var request = new CreateServiceAccountRequest
            {
                AccountId      = name,
                ServiceAccount = new ServiceAccount
                {
                    DisplayName = displayName
                }
            };

            ServiceAccount serviceAccount = s_iam.Projects.ServiceAccounts
                                            .Create(request, "projects/" + projectId).Execute();

            Console.WriteLine("Created service account: " + serviceAccount.Email);
            return(serviceAccount);
        }
        private string CreateServiceAccount()
        {
            var service = TestIamService();

            var request = new CreateServiceAccountRequest
            {
                AccountId      = RandomId(),
                ServiceAccount = new ServiceAccount
                {
                    DisplayName = "Test service account"
                }
            };

            var serviceAccount = service.Projects.ServiceAccounts.Create(
                request, $"projects/{s_projectId}").Execute();

            return(serviceAccount.Email);
        }
Ejemplo n.º 8
0
    public void GenerateServiceAccount(int numberOfAccount = 1)
    {
        var scopes    = new string[] { DriveService.Scope.Drive, IamService.Scope.CloudPlatform };
        var driveAuth = _googleCloudConfig.CredentialsPath;

        using var stream = new FileStream(driveAuth, FileMode.Open, FileAccess.Read);
        var credential = GoogleCredential.FromStream(stream)
                         .CreateScoped(scopes);

        var service = new IamService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential
        });

        for (var i = 0; i < numberOfAccount; i++)
        {
            var uniqueId = StringUtil.GenerateUniqueId();
            var request  = new CreateServiceAccountRequest()
            {
                AccountId      = $"fulan-{uniqueId}",
                ServiceAccount = new ServiceAccount()
                {
                    DisplayName = $"fulan {uniqueId}"
                }
            };

            var serviceAccount = service.Projects.ServiceAccounts.Create(request, "projects/zizibot-295007").Execute();

            var name       = serviceAccount.Name;
            var accountKey = service.Projects.ServiceAccounts.Keys.Create(new CreateServiceAccountKeyRequest()
            {
                PrivateKeyType = "TYPE_GOOGLE_CREDENTIALS_FILE",
                KeyAlgorithm   = "KEY_ALG_RSA_2048"
            }, serviceAccount.Name).Execute();

            Log.Information("created: {0}", serviceAccount.Name);
        }
    }
        public IHttpActionResult CreateServiceAccount(string projectID, string accountID, string displayName)
        {
            try
            {
                var service = new IamService(new IamService.Initializer
                {
                    HttpClientInitializer = AppFlowMetadata.UserCredential,
                    ApplicationName       = AppFlowMetadata.AppName,
                });

                var request2 = new CreateServiceAccountRequest
                {
                    AccountId      = accountID,
                    ServiceAccount = new ServiceAccount
                    {
                        DisplayName = displayName
                    }
                };

                var serviceAccount = service.Projects.ServiceAccounts.Create(
                    request2, "projects/" + projectID).Execute();

                var email = serviceAccount.Email;

                var key = service.Projects.ServiceAccounts.Keys.Create(
                    new CreateServiceAccountKeyRequest(),
                    "projects/-/serviceAccounts/" + email)
                          .Execute();

                return(Ok(serviceAccount.UniqueId));
            }
            catch (Exception)
            {
            }

            return(Ok());
        }
Ejemplo n.º 10
0
    public static ServiceAccount CreateServiceAccount(string projectId,
                                                      string name, string displayName)
    {
        var credential = GoogleCredential.GetApplicationDefault()
                         .CreateScoped(IamService.Scope.CloudPlatform);
        var service = new IamService(new IamService.Initializer
        {
            HttpClientInitializer = credential
        });

        var request = new CreateServiceAccountRequest
        {
            AccountId      = name,
            ServiceAccount = new ServiceAccount
            {
                DisplayName = displayName
            }
        };
        var serviceAccount = service.Projects.ServiceAccounts.Create(
            request, "projects/" + projectId).Execute();

        Console.WriteLine("Created service account: " + serviceAccount.Email);
        return(serviceAccount);
    }
 partial void Modify_CreateServiceAccountRequest(ref CreateServiceAccountRequest request, ref gaxgrpc::CallSettings settings);
 /// <summary>
 ///
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="callSettings">
 /// If not null, applies overrides to this RPC call.
 /// </param>
 /// <returns>
 /// The RPC response.
 /// </returns>
 public virtual ServiceAccount CreateServiceAccount(
     CreateServiceAccountRequest request,
     gaxgrpc::CallSettings callSettings = null)
 {
     throw new sys::NotImplementedException();
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="request">
 /// The request object containing all of the parameters for the API call.
 /// </param>
 /// <param name="cancellationToken">
 /// A <see cref="st::CancellationToken"/> to use for this RPC.
 /// </param>
 /// <returns>
 /// A Task containing the RPC response.
 /// </returns>
 public virtual stt::Task <ServiceAccount> CreateServiceAccountAsync(
     CreateServiceAccountRequest request,
     st::CancellationToken cancellationToken) => CreateServiceAccountAsync(
     request,
     gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));