polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
65 lines • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.authAdapter = exports.AuthenticationAdapter = void 0;
const auth_provider_1 = require("./auth-provider");
const errors_1 = require("../utils/errors");
class AuthenticationAdapter {
constructor(authProvider) {
this.authProvider = authProvider || new auth_provider_1.DefaultAuthenticationProvider();
}
getAuthConfig(options) {
const credentials = this.authProvider.getCredentials(options);
if (!credentials) {
const statusMessage = this.authProvider.getStatusMessage(options);
throw new errors_1.ConfigurationError(statusMessage);
}
return {
appId: credentials.appId,
appSecret: credentials.appSecret,
...(credentials.userId && { userId: credentials.userId }),
};
}
tryGetAuthConfig(options) {
if (options) {
const cliAppId = options['appId'];
const cliAppSecret = options['appSecret'];
const hasCliAuthAttempt = cliAppId || cliAppSecret;
if (hasCliAuthAttempt && (!cliAppId || !cliAppSecret)) {
return null;
}
}
const context = this.authProvider.getAuthenticationContext(options);
if (!context) {
return null;
}
return {
config: {
appId: context.credentials.appId,
appSecret: context.credentials.appSecret,
...(context.credentials.userId && { userId: context.credentials.userId }),
},
source: context.source.metadata.source,
...(context.source.metadata.accountName && { accountName: context.source.metadata.accountName }),
};
}
isAuthenticationAvailable(options) {
return this.authProvider.getCredentials(options) !== null;
}
getStatusMessage(options) {
if (options) {
const cliAppId = options['appId'];
const cliAppSecret = options['appSecret'];
const hasCliAuthAttempt = cliAppId || cliAppSecret;
if (hasCliAuthAttempt && (!cliAppId || !cliAppSecret)) {
return 'Auth configuration is incomplete';
}
}
return this.authProvider.getStatusMessage(options);
}
getDiagnostics(options) {
return this.authProvider.getDiagnostics(options);
}
}
exports.AuthenticationAdapter = AuthenticationAdapter;
exports.authAdapter = new AuthenticationAdapter();
//# sourceMappingURL=auth-adapter.js.map