Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(VB.NET UWP/WinRT) Google Cloud SQL - Get Instance InformationDemonstrates how to get information about your Cloud SQL instances, including instance summary information, usage data, operation logs, and database logs. For more information, see https://cloud.google.com/sql/docs/mysql/instance-info
' This example assumes the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' In this example, Get Google Cloud SQL OAuth2 Access Token, ' the service account access token was saved to a text file. This example fetches the access token from the file.. Dim sbToken As New Chilkat.StringBuilder sbToken.LoadFile("qa_data/tokens/google_cloud_sql_access_token.txt","utf-8") Dim http As New Chilkat.Http Dim success As Boolean ' Implements the following CURL command: ' curl -X GET \ ' -H "Authorization: Bearer access-token" \ ' https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id ' Use the following online tool to generate HTTP code from a CURL command ' Convert a cURL Command to HTTP Source Code ' Causes the "Authorization: Bearer "$(gcloud auth print-access-token)" header to be added. http.AuthToken = sbToken.GetAsString() ' Replace "project-id" with your actual Google project ID. ' Replace "instance-id" with your database instance ID, which is the name of your database. (For example, when I created my test database I named it "chilkat", and therefore my instance-id is "chilkat".) Dim sbResponseBody As New Chilkat.StringBuilder success = Await http.QuickGetSbAsync("https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",sbResponseBody) If (success = False) Then Debug.WriteLine(http.LastErrorText) Exit Sub End If Dim jResp As New Chilkat.JsonObject jResp.LoadSb(sbResponseBody) jResp.EmitCompact = False Debug.WriteLine("Response Body:") Debug.WriteLine(jResp.Emit()) Dim respStatusCode As Integer = http.LastStatus Debug.WriteLine("Response Status Code = " & respStatusCode) If (respStatusCode = 401) Then Debug.WriteLine("It may be that your access token expired.") Debug.WriteLine("Try refreshing the access token by re-fetching it.") End If If (respStatusCode >= 400) Then Debug.WriteLine("Response Header:") Debug.WriteLine(http.LastHeader) Debug.WriteLine("Failed.") Exit Sub End If ' Sample JSON response: ' (Sample code for parsing the JSON response is shown below) ' { ' "kind": "sql#instance", ' "state": "RUNNABLE", ' "databaseVersion": "MYSQL_5_7", ' "settings": { ' "authorizedGaeApplications": [ ' ], ' "tier": "db-f1-micro", ' "kind": "sql#settings", ' "pricingPlan": "PER_USE", ' "replicationType": "SYNCHRONOUS", ' "activationPolicy": "ALWAYS", ' "ipConfiguration": { ' "authorizedNetworks": [ ' ], ' "ipv4Enabled": true ' }, ' "locationPreference": { ' "zone": "asia-east1-a", ' "kind": "sql#locationPreference" ' }, ' "dataDiskType": "PD_SSD", ' "backupConfiguration": { ' "startTime": "08:00", ' "kind": "sql#backupConfiguration", ' "enabled": true, ' "pointInTimeEnabled": true ' }, ' "settingsVersion": "13", ' "storageAutoResizeLimit": "0", ' "storageAutoResize": true, ' "dataDiskSizeGb": "10" ' }, ' "etag": "etag-id", ' "ipAddresses": [ ' { ' "type": "PRIMARY", ' "ipAddress": "10.0.0.1" ' } ' ], ' "serverCaCert": { ' "kind": "sql#sslCert", ' "certSerialNumber": "0", ' "cert": "certificate-id", ' "commonName": "C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=dn-qualifier-id", ' "sha1Fingerprint": "sha-id", ' "instance": "instance-id", ' "createTime": "2019-06-28T22:46:35.052Z", ' "expirationTime": "2029-06-25T22:47:35.052Z" ' }, ' "instanceType": "CLOUD_SQL_INSTANCE", ' "project": "project-id", ' "serviceAccountEmailAddress": "service-acct-id@gcp-sa-cloud-sql.iam.gserviceaccount.com", ' "backendType": "SECOND_GEN", ' "selfLink": "https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", ' "connectionName": "project-id:region:instance-id", ' "name": "instance-id", ' "region": "asia-east1", ' "gceZone": "asia-east1-a" ' } ' Sample code for parsing the JSON response... ' Use the following online tool to generate parsing code from sample JSON: ' Generate Parsing Code from JSON Dim v_type As String Dim ipAddress As String Dim kind As String = jResp.StringOf("kind") Dim state As String = jResp.StringOf("state") Dim databaseVersion As String = jResp.StringOf("databaseVersion") Dim settingsTier As String = jResp.StringOf("settings.tier") Dim settingsKind As String = jResp.StringOf("settings.kind") Dim settingsPricingPlan As String = jResp.StringOf("settings.pricingPlan") Dim settingsReplicationType As String = jResp.StringOf("settings.replicationType") Dim settingsActivationPolicy As String = jResp.StringOf("settings.activationPolicy") Dim settingsIpConfigurationIpv4Enabled As Boolean = jResp.BoolOf("settings.ipConfiguration.ipv4Enabled") Dim settingsLocationPreferenceZone As String = jResp.StringOf("settings.locationPreference.zone") Dim settingsLocationPreferenceKind As String = jResp.StringOf("settings.locationPreference.kind") Dim settingsDataDiskType As String = jResp.StringOf("settings.dataDiskType") Dim settingsBackupConfigurationStartTime As String = jResp.StringOf("settings.backupConfiguration.startTime") Dim settingsBackupConfigurationKind As String = jResp.StringOf("settings.backupConfiguration.kind") Dim settingsBackupConfigurationEnabled As Boolean = jResp.BoolOf("settings.backupConfiguration.enabled") Dim settingsBackupConfigurationPointInTimeEnabled As Boolean = jResp.BoolOf("settings.backupConfiguration.pointInTimeEnabled") Dim settingsSettingsVersion As String = jResp.StringOf("settings.settingsVersion") Dim settingsStorageAutoResizeLimit As String = jResp.StringOf("settings.storageAutoResizeLimit") Dim settingsStorageAutoResize As Boolean = jResp.BoolOf("settings.storageAutoResize") Dim settingsDataDiskSizeGb As String = jResp.StringOf("settings.dataDiskSizeGb") Dim etag As String = jResp.StringOf("etag") Dim serverCaCertKind As String = jResp.StringOf("serverCaCert.kind") Dim serverCaCertCertSerialNumber As String = jResp.StringOf("serverCaCert.certSerialNumber") Dim serverCaCertCert As String = jResp.StringOf("serverCaCert.cert") Dim serverCaCertCommonName As String = jResp.StringOf("serverCaCert.commonName") Dim serverCaCertSha1Fingerprint As String = jResp.StringOf("serverCaCert.sha1Fingerprint") Dim serverCaCertInstance As String = jResp.StringOf("serverCaCert.instance") Dim serverCaCertCreateTime As String = jResp.StringOf("serverCaCert.createTime") Dim serverCaCertExpirationTime As String = jResp.StringOf("serverCaCert.expirationTime") Dim instanceType As String = jResp.StringOf("instanceType") Dim project As String = jResp.StringOf("project") Dim serviceAccountEmailAddress As String = jResp.StringOf("serviceAccountEmailAddress") Dim backendType As String = jResp.StringOf("backendType") Dim selfLink As String = jResp.StringOf("selfLink") Dim connectionName As String = jResp.StringOf("connectionName") Dim name As String = jResp.StringOf("name") Dim region As String = jResp.StringOf("region") Dim gceZone As String = jResp.StringOf("gceZone") Dim i As Integer = 0 Dim count_i As Integer = jResp.SizeOfArray("settings.authorizedGaeApplications") While i < count_i jResp.I = i i = i + 1 End While i = 0 count_i = jResp.SizeOfArray("settings.ipConfiguration.authorizedNetworks") While i < count_i jResp.I = i i = i + 1 End While i = 0 count_i = jResp.SizeOfArray("ipAddresses") While i < count_i jResp.I = i v_type = jResp.StringOf("ipAddresses[i].type") ipAddress = jResp.StringOf("ipAddresses[i].ipAddress") i = i + 1 End While |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.