Verbindungsprofile verwalten

Mit der Datastream API können Sie Verbindungsprofile programmatisch erstellen und verwalten, in denen Authentifizierungs- und Verbindungsinformationen für Ihre Quellen und Ziele gespeichert werden. Sie können REST API-Aufrufe ausführen oder die Google Cloud CLI verwenden. Sie können beispielsweise Profile für Oracle-, MySQL-, PostgreSQL-, SQL Server-, Salesforce- und MongoDB-Quellen sowie für BigQuery- und Cloud Storage-Ziele erstellen.

Sie können Verbindungsprofile auch abrufen, auflisten, aktualisieren oder löschen und die Struktur einer Quelldatenbank ermitteln. Weitere Informationen zur Befehlsreferenz finden Sie unter gcloud datastream connection-profiles. Eine detaillierte Anleitung finden Sie unter Datastream APIs verwenden.

Verbindungsprofil für eine Oracle-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Oracle-Datenbank mit einem Secret und der IP-Zulassungsliste als Verbindungsmethode.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "oracleProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "databaseService": "DATABASE",
    "secretManagerStoredPassword": "SECRET_MANAGER_RESOURCE"
  },
  "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myOracleCP
{
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "username": "admin",
    "databaseService": "ORCL",
    "secretManagerStoredPassword": "projects/myProjectId/secrets/mySecret/versions/latest"
  },
  "staticServiceIpConnectivity": {}
}

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Oracle-Datenbank und gibt die Verbindungsmethode als private Konnektivität (VPC-Peering) an.

Diese Methode stellt eine sichere Verbindung zwischen Datastream und der Quelldatenbank her (intern innerhalb von Google Cloudoder mit externen Quellen, die über VPN oder Interconnect verbunden sind). Diese Kommunikation erfolgt über eine VPC-Peering-Verbindung.

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "oracleProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "databaseService": "DATABASE"
  },
  "privateConnectivity": {
    "privateConnection": "projects/PROJECT_ID/locations/
    LOCATION/privateConnections/[private-connectivity-configuration-id]"
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myOracleVPCPeeringCP
{
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "username": "admin",
    "password": "12345",
    "databaseService": "ORCL",
  },
    "privateConnectivity": {
      "privateConnection": "projects/myProjectId/locations/us-central1/
      privateConnections/myPrivateConnection"
    }
}

Nachdem das Verbindungsprofil erstellt wurde, können Sie mit der Methode connectionProfiles/get Informationen dazu aufrufen. Ihre Ausgabe sieht in etwa so aus:

{
  "name": "projects/projectId/location/us-central1/connectionProfiles/myOracleVPCPeeringCP",
  "createTime": "2019-12-22T16:17:37.159786963Z",
  "updateTime": "2019-12-22T16:17:37.159786963Z",
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "databaseService": "ORCL",
    "username": "admin"
  },
  "privateConnectivity": {
    "privateConnection": "projects/myProjectId/locations/us-central1/
    privateConnections/myPrivateConnection"
  }
}

gcloud

Weitere Informationen zum Erstellen eines Verbindungsprofils für eine Oracle-Quelldatenbank mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine MySQL-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zur Erstellung eines Verbindungsprofils für eine MySQL-Datenbank und gibt als Verbindungsmethode die Verwendung statischer IP-Adressen (IP-Zulassungsliste) an.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "mysqlProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD"
  },
  "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=mysql-cp
{
  "displayName": "my MySQL database",
  "mysqlProfile": {
    "hostname": "1.2.3.4",
    "port": 3306,
    "username": "root",
    "password": "12345"
  },
  "staticServiceIpConnectivity": {}
}

gcloud

Weitere Informationen zum Erstellen eines Verbindungsprofils für eine MySQL-Quelldatenbank mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine PostgreSQL-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine PostgreSQL-Datenbank.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "postgresqlProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "database": "DATABASE"
  },
  "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=postgres-cp
{
  "displayName": "my PostgreSQL database",
  "postgresqlProfile": {
    "hostname": "1.2.3.4",
    "database": "postgres",
    "port": 5432,
    "username": "root",
    "password": "12345"
  },
  "staticServiceIpConnectivity": {}
}

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine SQL Server-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine SQL Server-Datenbank und gibt die Verbindungsmethode mit statischen IP-Adressen (IP-Zulassungsliste) an.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "sqlserverProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "database": "DATABASE"
  },
  "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=sqlserver-cp
{
  "displayName": "my SQL Server database",
  "sqlserverProfile": {
    "hostname": "1.2.3.4",
    "port": 1433,
    "username": "root",
    "password": "12345"
    "database": "database1"
  },
  "staticServiceIpConnectivity": {}
}

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine Salesforce-Quelle erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Salesforce-Quellinstanz mit einem Nutzernamen und einem Passwort als Authentifizierungsmethode.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "salesforceProfile": {
    "domain": "DOMAIN_NAME",
    "userCredentials": {
      "username": "USERNAME",
      "password": "PASSWORD",
      "securitytoken": "SECURITY_TOKEN"
    }
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=saleforce-cp
{
  "displayName": "My Salesforce connection profile",
  "salesforceProfile": {
    "domain": "domain.my.salesforce.com",
    "userCredentials": {
      "username": "mySalesforceUser",
      "password": "12345",
      "securitytoken": "C08120F510542FFB1C3640F57AF19E2D5D700556A25F7D665C3B428407709D8C"
    }
  }
}
  

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Salesforce-Quellinstanz mit OAuth 2.0-Clientanmeldedaten als Authentifizierungsmethode.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "salesforceProfile": {
    "domain": "DOMAIN_NAME",
    "oauth2ClientCredentials": {
      "clientId": "CLIENT_ID",
      "clientSecret": "CLIENT_SECRET"
    }
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=saleforce-cp
{
  "displayName": "My Salesforce connection profile",
  "salesforceProfile": {
    "domain": "domain.my.salesforce.com",
    "oauth2ClientCredentials": {
      "clientId": "myClientId",
      "clientSecret": "projects/myProject/secrets/sf-client-secret"
    }
  }
}
  

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine MongoDB-Quelle erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine MongoDB-Quellinstanz im SRV-Verbindungsstringformat.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "mongodbProfile": {
    "hostAddresses": [ {
      "hostname": "HOST_URI"
    } ],
    "username": "USERNAME",
    "password": "PASSWORD",
    "srvConnectionFormat": {}
    },
    "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=mongodb-cp
{
  "displayName": "mongodb-cp",
  "mongodbProfile": {
    "hostAddresses": [ {
      "hostname": "cluster85828.ebeek.mongodb.net"
    } ],
    "username": "Cluster85828",
    "password": "password",
    "srvConnectionFormat": {}
    },
    "staticServiceIpConnectivity": {}
}
  

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine MongoDB-Quellinstanz im Standardformat für Verbindungsstrings.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "mongodbProfile": {
    "hostAddresses": [ {
      "hostname": "HOST_IP",
      "port": "PORT_NUMBER"
    } ],
    "replica_set": "SET_ID",
    "username": "USERNAME",
    "password": "PASSWORD",
    "standardConnectionFormat": {
      "directConnection": false
    }
  },
  "staticServiceIpConnectivity": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=mongodb-cp
{
  "displayName": "mongodb-cp",
  "mongodbProfile": {
    "hostAddresses": [ {
      "hostname": "34.19.10.194",
      "port": "27017"
    } ],
    "replicaset": "rs0",
    "username": "root",
    "password": "password",
    "standardConnectionFormat": {
      "directConnection": false
    }
  },
  "staticServiceIpConnectivity": {}
}
  

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für ein BigQuery-Ziel erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für ein BigQuery-Ziel.

REST

POST https://datastream.googleapis.com/v1/projects/[project-id/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "connection-profile-display-name",
  "bigqueryProfile": {}
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myBigqueryCP
{
  "displayName": "my BigQuery destination",
  "bigqueryProfile": {}
}

gcloud

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für ein Cloud Storage-Ziel erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für einen Cloud Storage-Bucket. Da sich Cloud Storage im selben Netzwerk wie Datastream befindet, ist keine spezielle Verbindung erforderlich. Daher wird keine Verbindungsmethode angegeben.

REST

POST https://datastream.googleapis.com/v1/projects/[project-id/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "connection-profile-display-name",
  "gcsProfile": {
    "bucket": "bucket-name",
    "rootPath": "prefix-inside-bucket"
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myGcsCP
{
  "displayName": "my Cloud Storage bucket",
  "gcsProfile": {
    "bucket": "myBucket",
    "rootPath": "prefix-inside-bucket"
  }
}

gcloud

Weitere Informationen zum Erstellen eines Verbindungsprofils für Cloud Storage mit gcloud finden Sie in der Cloud SDK-Dokumentation.

Informationen zu einem Verbindungsprofil abrufen

Der folgende Code zeigt eine Anfrage zum Abrufen von Informationen zu einem Verbindungsprofil für eine Oracle-Quelldatenbank, eine MySQL-Quelldatenbank, ein BigQuery-Ziel oder ein Cloud Storage-Ziel, das erstellt wurde.

REST

GET https://datastream.googleapis.com/v1/projects/project-id/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID

Beispiel:

GET https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP

gcloud

Weitere Informationen zum Abrufen von Informationen zu Ihrem Verbindungsprofil mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofile auflisten

Der folgende Code zeigt eine Anfrage zum Abrufen von Informationen zu allen Verbindungsprofilen.

REST

GET https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles

gcloud

Weitere Informationen zur Verwendung von gcloud zum Abrufen von Informationen zu allen Verbindungsprofilen finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil aktualisieren

Der folgende Code zeigt eine Anfrage zum Ändern des Nutzernamens und des Passworts eines vorhandenen Verbindungsprofils für eine Quelldatenbank.

Bei Verwendung des Parameters updateMask in der Anfrage müssen nur die von Ihnen angegebenen Felder im Text der Anfrage enthalten sein (in diesem Beispiel die Felder username und password, dargestellt durch die Flags oracle_profile.username bzw. oracle_profile.password).

REST

PATCH https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID?
updateMask=oracle_profile.username,oracle_profile.password
{
  "oracleProfile": {
    "username": "USERNAME",
    "password": "PASSWORD"
  }
}

Beispiel:

PATCH https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP?
updateMask=oracle_profile.username,oracle_profile.password
{
  "oracleProfile": {
    "username": "username",
    "password": "password"
  }
}

Der folgende Code zeigt eine Anfrage zum Ändern der Konfiguration für private Konnektivität, die einem Verbindungsprofil zugewiesen ist. Dieses Verbindungsprofil verwendet die Netzwerkverbindungsmethode "VPC-Peering".

In diesem Beispiel weisen Sie dem Verbindungsprofil die Konfiguration new_private_connection zu.

PATCH -d {\"private_connectivity\":{\"private_connection\":\
"projects/PROJECT_ID/locations/LOCATION/privateConnections/
new_private_connection\"}}" -H "Authorization: Bearer $TOKEN" -H 
"Content-Type: application/json" https://datastream.googleapis.com/v1/
projects/PROJECT_ID/locations/LOCATION/connectionProfiles/
CONNECTION_PROFILE_ID?update_mask=private_connectivity.private_connection

Beispiel:

PATCH -d {\"private_connectivity\":{\"private_connection\":\
"projects/myProjectId/locations/us-central1/privateConnections/
new_private_connection\"}}" -H "Authorization: Bearer $TOKEN" -H 
"Content-Type: application/json"
https://datastream.googleapis.com/v1/projects/
myProjectId/locations/us-central1/connectionProfiles/
myOracleVPCPeeringCP?update_mask=private_connectivity.private_connection

gcloud

Weitere Informationen zum Aktualisieren Ihres Verbindungsprofils mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil löschen

Der folgende Code zeigt eine Anfrage zum Löschen eines Verbindungsprofils. Nachdem das Verbindungsprofil gelöscht wurde, schlagen alle Streams fehl, die es verwenden.

REST

DELETE https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID

Beispiel:

DELETE https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP

gcloud

Weitere Informationen zum Löschen Ihres Verbindungsprofils mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Struktur einer Quelldatenbank ermitteln

Verwenden Sie die discoverConnectionProfile API, um die Liste der Entitäten (z. B. Schemas und Tabellen) aus einer Quelle und die mit den Entitäten verknüpften Metadaten abzurufen.

Die API kann als Parameter entweder eine ID eines bestehenden Verbindungsprofils oder eine vollständige Objektdefinition des Verbindungsprofils erhalten. Die Funktion kann eine einzelne Ebene (z. B. alle Schemas in einer Datenbank oder alle Tabellen in einem Schema) oder alle Entitäten rekursiv (z. B. Schemas, Tabellen und Spalten) zurückgeben.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles:discoverConnectionProfile?CONNECTION_PROFILE_ID

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles:discoverConnectionProfile?myOracleCP

gcloud

Weitere Informationen zur Verwendung von gcloud zum Ermitteln der Struktur Ihrer Quelldatenbank finden Sie in der Google Cloud SDK-Dokumentation.

Nächste Schritte