Beispiel #1
0
        public static ServiceAccountKey CreateKeyOfServiceAccount(string userEmail)
        {
            var newKeyDetails = s_service.Projects.ServiceAccounts.Keys.Create(
                new CreateServiceAccountKeyRequest(), "projects/-/serviceAccounts/" + userEmail);

            ServiceAccountKey key = newKeyDetails.Execute();

            return(key);
        }
Beispiel #2
0
        // [START iam_create_key]
        public static ServiceAccountKey CreateKey(string serviceAccountEmail)
        {
            ServiceAccountKey key = s_service.Projects.ServiceAccounts.Keys.Create(
                new CreateServiceAccountKeyRequest(),
                "projects/-/serviceAccounts/" + serviceAccountEmail)
                                    .Execute();

            Console.WriteLine("Created key: " + key.Name);
            return(key);
        }
Beispiel #3
0
        private static void ServiceAccounts(string credentialsJson, string userEmail)
        {
            LoginAsServiceAccountWithJson(credentialsJson);

            IList <ServiceAccountKey> serviceAccountKeys = ListKeysOfServiceAccount(userEmail);

            ServiceAccountKey newKey = CreateKeyOfServiceAccount(userEmail);

            // Call the translate API with the new key.
            byte[] jsonKey       = Convert.FromBase64String(newKey.PrivateKeyData);
            Stream jsonKeyStream = new MemoryStream(jsonKey);
            ServiceAccountCredential credential = ServiceAccountCredential
                                                  .FromServiceAccountData(jsonKeyStream);
            GoogleCredential googleCredential = GoogleCredential
                                                .FromServiceAccountCredential(credential);
            var client   = TranslationClient.Create(googleCredential);
            var response = client.TranslateText("Hello World", "ru");

            Console.WriteLine(response.TranslatedText);

            //DeleteKeyOfServiceAccount(newKey);

            // LoginWithServiceAccountKey(newKey, credentialsJson);
        }
        /// <summary>
        /// Generates new credentials for the service account associated with this enterprise. The calling service account must have been retrieved by calling Enterprises.GetServiceAccount and must have been set as the enterprise service account by calling Enterprises.SetAccount.Only the type of the key should be populated in the resource to be inserted.
        /// Documentation https://developers.google.com/androidenterprise/v1/reference/serviceaccountkeys/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Androidenterprise service.</param>
        /// <param name="enterpriseId">The ID of the enterprise.</param>
        /// <param name="body">A valid Androidenterprise v1 body.</param>
        /// <returns>ServiceAccountKeyResponse</returns>
        public static ServiceAccountKey Insert(AndroidenterpriseService service, string enterpriseId, ServiceAccountKey body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (enterpriseId == null)
                {
                    throw new ArgumentNullException(enterpriseId);
                }

                // Make the request.
                return(service.Serviceaccountkeys.Insert(body, enterpriseId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Serviceaccountkeys.Insert failed.", ex);
            }
        }