Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
send slack message
  • Loading branch information
enriquezrene committed Sep 24, 2020
commit d5d47e7c8dd62f4268e55a8b92737104c18e7ef7
4 changes: 2 additions & 2 deletions AutomaticClockOuts/clock_out.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MsalClient = require('./msal_client')

const doClockOut = async (context, timer) => {
context.log(`I am going to check how many entries were not clocked out ${new Date()}`);
const {endpoint, key, databaseId, containerId, azureEndpoint} = config;
const {endpoint, key, databaseId, containerId, slackWebHook} = config;
const client = new CosmosClient({endpoint, key});
const database = client.database(databaseId);
const container = database.container(containerId);
Expand All @@ -33,7 +33,7 @@ const doClockOut = async (context, timer) => {
}
}));
if(totalClockOutsExecuted > 0){
axios.post(process.env["SLACK_WEBHOOK"],
axios.post(slackWebHook,
{
"text": `Hey guys, I did a clock out for you. \nVisit https://timetracker.ioet.com/ and set the right end time for your entries :pls: \n- ${usersWithClockOut.join('\n- ')}`
}
Expand Down
11 changes: 6 additions & 5 deletions AutomaticClockOuts/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const config = {
endpoint: "https://time-tracker-db.documents.azure.com:443/",
key: process.env["COSMOS_DB_KEY"],
endpoint: "xxx",
key: "xxx",
databaseId: "time-tracker-db",
containerId: "time_entry",
partitionKey: { kind: "Hash", paths: ["/category"] },
client_id: process.env["MS_CLIENT_ID"],
authority: process.env["MS_AUTHORITY"],
clientSecret: process.env["MS_CLIENT_SECRET"]
clientId: "xxx",
authority: "xxx",
clientSecret: "xxx",
slackWebHook: "xxx"
};

module.exports = config;
15 changes: 7 additions & 8 deletions AutomaticClockOuts/msal_client.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const axios = require("axios")
const msal = require('@azure/msal-node');
const config = require("./config");

const findUsersInMS = async() => {
const {clientId, authority, clientSecret} = config;
const endpoint = 'https://graph.windows.net/ioetec.onmicrosoft.com'
const config = {
const configuration = {
auth: {
clientId: process.env["MS_CLIENT_ID"],
authority: process.env["MS_AUTHORITY"],
clientSecret: process.env["MS_CLIENT_SECRET"]
clientId: clientId,
authority: authority,
clientSecret: clientSecret
}
};

console.log('---------------------------------------------')
console.log(JSON.stringify(config))

const cca = new msal.ConfidentialClientApplication(config);
const cca = new msal.ConfidentialClientApplication(configuration);
const clientCredentialRequest = {
scopes: ['https://graph.windows.net/.default'],
};
Expand Down
11 changes: 1 addition & 10 deletions AutomaticClockOuts/test/msal_client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ const test = require('ava');
const MsalClient = require('../msal_client')

test('Response contains ioet.com since users has it as part their emails', async t => {
const users =
// {
// data: {
// value: '[email protected]'
// }
// }
await MsalClient.findUsersInMS()

console.log('---------------------------value')
console.log(users.data.value)
const users = await MsalClient.findUsersInMS()

t.truthy(JSON.stringify(users.data.value).includes("ioet.com"))
})