2017-03-14 19:31:15 +01:00
|
|
|
const firebaseAdmin = require('firebase-admin');
|
2017-03-25 08:40:25 +08:00
|
|
|
const firebase = require('firebase');
|
|
|
|
|
|
2018-01-18 15:41:39 -03:00
|
|
|
/** Database URL of the dashboard firebase project. */
|
2017-06-10 01:09:26 +02:00
|
|
|
const dashboardDatabaseUrl = 'https://material2-board.firebaseio.com';
|
|
|
|
|
|
|
|
|
|
/** Opens a connection to the Firebase dashboard app using a service account. */
|
2017-06-13 20:48:02 +02:00
|
|
|
export function openFirebaseDashboardApp() {
|
2017-03-25 08:40:25 +08:00
|
|
|
// Initialize the Firebase application with firebaseAdmin credentials.
|
2017-03-14 19:31:15 +01:00
|
|
|
// Credentials need to be for a Service Account, which can be created in the Firebase console.
|
2017-05-23 22:56:40 +02:00
|
|
|
return firebaseAdmin.initializeApp({
|
2017-06-10 01:09:26 +02:00
|
|
|
databaseURL: dashboardDatabaseUrl,
|
2017-03-14 19:31:15 +01:00
|
|
|
credential: firebaseAdmin.credential.cert({
|
2017-06-05 20:13:05 +02:00
|
|
|
project_id: 'material2-board',
|
|
|
|
|
client_email: 'material2-board@appspot.gserviceaccount.com',
|
2017-03-14 19:31:15 +01:00
|
|
|
// In Travis CI the private key will be incorrect because the line-breaks are escaped.
|
|
|
|
|
// The line-breaks need to persist in the service account private key.
|
2017-11-01 19:03:57 +01:00
|
|
|
private_key: decode(process.env['MATERIAL2_BOARD_FIREBASE_SERVICE_KEY']!)
|
2017-03-14 19:31:15 +01:00
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-10 01:09:26 +02:00
|
|
|
/** Opens a connection to the Firebase dashboard app with no authentication. */
|
|
|
|
|
export function openFirebaseDashboardAppAsGuest() {
|
|
|
|
|
return firebase.initializeApp({ databaseURL: dashboardDatabaseUrl });
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 19:31:15 +01:00
|
|
|
/** Decodes a Travis CI variable that is public in favor for PRs. */
|
|
|
|
|
export function decode(str: string): string {
|
|
|
|
|
// In Travis CI the private key will be incorrect because the line-breaks are escaped.
|
|
|
|
|
// The line-breaks need to persist in the service account private key.
|
2017-03-25 08:40:25 +08:00
|
|
|
return (str || '').replace(/\\n/g, '\n');
|
|
|
|
|
}
|
|
|
|
|
|