DartStreamMachineClient constructor
DartStreamMachineClient({})
Implementation
DartStreamMachineClient({
required DartStreamConfig config,
required this.clientId,
required String clientSecret,
this.tenantId,
required this.projectId,
http.Client? httpClient,
DateTime Function()? now,
}) : _secret = clientSecret,
_http = httpClient ?? http.Client(),
_ownsHttp = httpClient == null,
_config = config,
_now = now ?? DateTime.now {
if (clientId.trim().isEmpty ||
clientSecret.isEmpty ||
(tenantId != null && tenantId!.trim().isEmpty) ||
projectId.trim().isEmpty) {
throw ArgumentError(
'Machine credentials require a client and project.',
);
}
final url = config.billingBaseUrl;
if (url.scheme != 'https' &&
!(url.scheme == 'http' &&
['localhost', '127.0.0.1', '::1'].contains(url.host))) {
throw ArgumentError(
'Machine credential exchange requires HTTPS (or local loopback).',
);
}
client = DartStreamClient(config: config, httpClient: _http);
}