Expert1.CloudSqlProxy
2.0.8
dotnet add package Expert1.CloudSqlProxy --version 2.0.8
NuGet\Install-Package Expert1.CloudSqlProxy -Version 2.0.8
<PackageReference Include="Expert1.CloudSqlProxy" Version="2.0.8" />
<PackageVersion Include="Expert1.CloudSqlProxy" Version="2.0.8" />
<PackageReference Include="Expert1.CloudSqlProxy" />
paket add Expert1.CloudSqlProxy --version 2.0.8
#r "nuget: Expert1.CloudSqlProxy, 2.0.8"
#:package Expert1.CloudSqlProxy@2.0.8
#addin nuget:?package=Expert1.CloudSqlProxy&version=2.0.8
#tool nuget:?package=Expert1.CloudSqlProxy&version=2.0.8
Cloud SQL Proxy
This project provides a .NET Standard library for creating and managing a secure connection to Google Cloud SQL instances using a local proxy. The proxy establishes an SSL/TLS connection to the Cloud SQL instance, allowing local applications to communicate with the database securely.
Features
- Secure connection to Google Cloud SQL instances
- Automatic SSL/TLS certificate management
- Supports multiple concurrent connections
- Handles periodic certificate refresh
Prerequisites
- .NET Standard 2.0 or later
- Google Cloud SDK
- Google Cloud SQL instance
Installation
To install the library, add it to your project via NuGet Package Manager:
PM> Install-Package Expert1.CloudSqlProxy
Usage
Authentication
The proxy supports two methods of authentication:
- Credential File: Path to the Google credentials JSON file.
- JSON String: Google credentials JSON file content as a string.
Creating a Proxy Instance
To create and start a proxy instance, use the ProxyInstance.StartProxyAsync method. You can provide the authentication method, instance connection string, and credentials.
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string instance = "your-project:your-region:your-instance-id";
string credentialsPath = "path/to/your/credentials.json";
try
{
var proxyInstance = await ProxyInstance.StartProxyAsync(
AuthenticationMethod.CredentialFile,
instance,
credentialsPath
);
Console.WriteLine($"Proxy started. Connect to your database using DataSource: {proxyInstance.DataSource}");
// Use proxyInstance.DataSource to connect to your database
// When done, dispose the instance to stop the proxy
proxyInstance.Dispose();
}
catch (Exception ex)
{
Console.WriteLine($"Failed to start proxy: {ex.Message}");
}
}
}
Connecting to the Database
Once the proxy is started, you can connect to your Cloud SQL database using the DataSource property of the ProxyInstance. This property provides the 127.0.0.1:<port> string, which can be used in your database connection string.
For example, to connect to a SQL Server instance:
string connectionString = $"Server={proxyInstance.DataSource};Database=your-database;User Id=your-username;Password=your-password;";
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
// Perform database operations
}
Stopping the Proxy
To stop the proxy, you can call the Stop method or dispose of the ProxyInstance:
proxyInstance.Stop(); // Stops the proxy
// Or, simply dispose the instance
proxyInstance.Dispose();
Stopping All Proxies
To stop all running proxies, use the InstanceManager.StopAllInstances method:
InstanceManager.StopAllInstances();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Google.Apis.SQLAdmin.v1beta4 (>= 1.72.0.3963)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0 && < 9.0.0)
-
net9.0
- Google.Apis.SQLAdmin.v1beta4 (>= 1.72.0.3963)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0 && < 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.