-
Notifications
You must be signed in to change notification settings - Fork 0
/
CredentialStoreManager.js
43 lines (38 loc) · 1.31 KB
/
CredentialStoreManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function refreshCredentials() {
const spreadsheetId = '1SrAoBolkSkz8HcF2ce6o4B6ZeU_6-c2VOaOsKY2C3gE'; // Climbing Clan credentials store
const sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName('Credentials');
const data = sheet.getDataRange().getValues();
const headers = data.shift();
const labelIndex = headers.indexOf('label');
const valueIndex = headers.indexOf('value');
if (labelIndex === -1 || valueIndex === -1) {
throw new Error('Required columns "label" and "value" not found in the Credentials sheet.');
}
data.forEach(row => {
const label = row[labelIndex];
const value = row[valueIndex];
if (label && value) {
PropertiesService.getScriptProperties().setProperty(`cred_${label}`, value);
}
});
}
function createNightlyTrigger() {
// Delete existing triggers
const triggers = ScriptApp.getProjectTriggers();
triggers.forEach(trigger => {
if (trigger.getHandlerFunction() === 'refreshCredentials') {
ScriptApp.deleteTrigger(trigger);
}
});
// Create a new trigger to run at 1:00 AM every day
ScriptApp.newTrigger('refreshCredentials')
.timeBased()
.everyDays(1)
.atHour(1)
.create();
}
// Run this function once to set up the nightly trigger
function setupCredentialRefresh() {
refreshCredentials();
createNightlyTrigger();
}