Open thekid opened 1 year ago
Create search indexes
We could do that using the Atlas Search API. We would need to ask users to create an API key in MongoDB Atlas for setting up Dialog, and enter public and private key in input fields. It would be great if Atlas were an OAuth provider where we could just request this access programmatically (much like Atlas CLI does!), but it doesn't seem there is a publicly documented way to do this.
use peer\http\DigestAuthorization;
use util\Secret;
use util\cmd\Console;
use webservices\rest\Endpoint;
// From https://cloud.mongodb.com/v2/622a7a8...b1#access/apiKeys/create
const PUBLIC_KEY = 'djfeabwg';
const PRIVATE_KEY= '...';
// Set up API with DigestAuth
$api= new Endpoint('https://cloud.mongodb.com/api/atlas/v1.0');
$api->with(['Authorization' => DigestAuthorization::fromChallenge(
$api->resource('.')->get()->header('WWW-Authenticate'),
PUBLIC_KEY,
new Secret(PRIVATE_KEY)
)]);
// Access clusters. This is where we would perform the setup, creating users, databases,
// search indexes etcetera
$r= $api->resource('clusters')->get();
Console::writeLine($r->value());
// [
// links => [[
// href => "https://cloud.mongodb.com/api/atlas/v1.0/clusters"
// rel => "self"
// ]]
// results => [[
// clusters => [[
// alertCount => 0
// authEnabled => true
// availability => "available"
// backupEnabled => false
// clusterId => "631b94f...64"
// dataSizeBytes => 0
// name => "Dialog"
// nodeCount => 3
// sslEnabled => true
// type => "replica set"
// versions => ["5.0.13"]
// ]]
// groupId => "622a7a8...b1"
// groupName => "Dialog"
// orgId => "622a7a8...a5"
// orgName => "Timm's Org - 2022-03-10"
// planType => "Atlas"
// tags => []
// ]]
// totalCount => 1
// ]
If freshly installed: