dotnet-credentials-in-url-parser
This package replaces both PostgresConnString.NET and mongo-url-parser as they are very basic packages.
It aims to grant general .NET support for parsing and converting urls in the form "scheme://user:password@host:port/database?connectionparameters" also known as Credential-In-Url and converting it to formats easily used by the database service providers for .NET.
Installation
You can install the package from nuget
Install-Package ciu-parser
or
dotnet add package ciu-parser
or for paket
paket add ciu-parser
Usage
Parsing Urls
To parse a url
using CredentialsInUrlParser;
...
var details = CIU.Parse("postgres://someuser:somepassword@somehost:381/somedatabase");
The resulting details contains a subset of the following properties:
Scheme
- Database server scheme
HostName
- Database server hostname
Port
- port on which to connect
UserName
- User with which to authenticate to the server
Password
- Corresponding password
DatabasePath
- Database name within the server
AdditionalQueryParameters
- Additional database parameters provided as query options
Exports
Currently, this library allows for generating an Npgsql compatible connection strings. With the following parameters
pooling
: type: boolean, default: true
trustServerCertificate
: type: boolean, default: true
sslMode
: type: enum, default: Prefer
using CredentialsInUrlParser;
...
var details = CIU.Parse("postgres://someuser:somepassword@somehost:381/somedatabase");
var connString = details.ToNpgsqlSConnectionString();
This library also allows for generating a MongoDB compatible connection string and database name.
using CredentialsInUrlParser;
...
var details = CIU.Parse("mongodb://user:password@host:port/database-name?otheroptions");
var (dbUrl, dbName) = details.ToMongoConnectionSplit();
Contributing
Feel free to make requests and to open P=pull requests with fixes and updates.