private async Task <string> GetInstance() { try { ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(ServiceAccountEmail) { Scopes = new[] { ComputeService.Scope.Compute, ComputeService.Scope.CloudPlatform } }.FromPrivateKey(PrivateKey)); var cs = new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "GCloud Get Instance" }; var t = new ComputeService(cs); var zoneRegion = Region + "-" + Zone; InstancesResource.GetRequest request = t.Instances.Get(Project, zoneRegion, InstanceName); Google.Apis.Compute.v1.Data.Instance response = await request.ExecuteAsync(); return(JsonConvert.SerializeObject(response)); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Gets the Cloud SQL instances for the given project and name. /// </summary> /// <returns>The Cloud SQL instance.</returns> public async Task <DatabaseInstance> GetInstanceAsync(string name) { try { InstancesResource.GetRequest request = Service.Instances.Get(ProjectId, name); return(await request.ExecuteAsync()); } catch (GoogleApiException ex) { Debug.WriteLine($"Failed to get database instance: {ex.Message}"); throw new DataSourceException(ex.Message, ex); } }