danin: API key pindah ke Script Properties BRIDGE_API_KEY + setter
Lint / lint (push) Has been cancelled
Lint / lint (push) Has been cancelled
This commit is contained in:
@@ -22,8 +22,32 @@ projects/danin/
|
|||||||
- `GET ?apiKey=...&op=meta` → info sheet (judul, jumlah baris/kolom, nama tab)
|
- `GET ?apiKey=...&op=meta` → info sheet (judul, jumlah baris/kolom, nama tab)
|
||||||
- `GET ?apiKey=...&op=rows&sheet=DATA&start=1&limit=500` → `{header, rows, range, totalRows}`
|
- `GET ?apiKey=...&op=rows&sheet=DATA&start=1&limit=500` → `{header, rows, range, totalRows}`
|
||||||
|
|
||||||
API key web app (`sk-dta-…`) tersimpan di dalam `Code.js` — JANGAN tampilkan di chat/vault (file ini tidak mencatat nilainya).
|
API key web app tersimpan di **Script Properties** (`BRIDGE_API_KEY`) — TIDAK di dalam kode, tidak di git.
|
||||||
Ganti key: edit di editor Apps Script ATAU ubah `dist/Code.js` lalu `clasp push` (akun bdn).
|
JANGAN tampilkan nilainya di chat/vault.
|
||||||
|
|
||||||
|
## Cara set / rotasi key (akun bdn, sekali per script)
|
||||||
|
|
||||||
|
Opsi A — via editor (klik manusia): project `1IJ4…` → Project Settings (gerigi) →
|
||||||
|
Script Properties → Add property: key `BRIDGE_API_KEY`, value key baru → Save.
|
||||||
|
|
||||||
|
Opsi B — via clasp run (tanpa browser, dari PC/runner setelah `use bdn`):
|
||||||
|
|
||||||
|
```
|
||||||
|
clasp run __setBridgeKey --params '["sk-baru-..."]'
|
||||||
|
```
|
||||||
|
|
||||||
|
dengan fungsi setter di bawah (ada di `dist/Code.js`, boleh dipanggil via API
|
||||||
|
tapi TIDAK terekspos sebagai web app):
|
||||||
|
|
||||||
|
```js
|
||||||
|
function __setBridgeKey(k) {
|
||||||
|
PropertiesService.getScriptProperties().setProperty('BRIDGE_API_KEY', k);
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Ganti key: set property baru (A/B) → pull/tes baca tetap jalan → hapus key lama
|
||||||
|
dari semua pemanggil (`pull-sheets-gas.ps1 -ApiKey`, Scheduler, n8n).
|
||||||
|
|
||||||
## Riwayat
|
## Riwayat
|
||||||
|
|
||||||
|
|||||||
Vendored
+13
-3
@@ -3,12 +3,22 @@
|
|||||||
* Execute as: Me | Who has access: Anyone with the link (baca saja, tanpa tulis).
|
* Execute as: Me | Who has access: Anyone with the link (baca saja, tanpa tulis).
|
||||||
* GET ?apiKey=...&op=meta -> info sheet (judul, jumlah baris/kolom, nama tab)
|
* GET ?apiKey=...&op=meta -> info sheet (judul, jumlah baris/kolom, nama tab)
|
||||||
* GET ?apiKey=...&op=rows&sheet=DATA&start=1&limit=500 -> {header:[...], rows:[[..]], range, totalRows}
|
* GET ?apiKey=...&op=rows&sheet=DATA&start=1&limit=500 -> {header:[...], rows:[[..]], range, totalRows}
|
||||||
* Auth: API_KEY di bawah (ganti setelah tempel, jangan pakai default).
|
* Auth: apiKey via Script Properties BRIDGE_API_KEY (lihat README cara set).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var API_KEY = 'sk-dta-1448h-79d07239dd3565ab747087d920c6deaa';
|
|
||||||
var SPREADSHEET_ID = '1jMWGEq46z3SW-5XvNz9PySoeTJZZaFsSBQhhfm-E5zA';
|
var SPREADSHEET_ID = '1jMWGEq46z3SW-5XvNz9PySoeTJZZaFsSBQhhfm-E5zA';
|
||||||
|
|
||||||
|
function getApiKey() {
|
||||||
|
var k = PropertiesService.getScriptProperties().getProperty('BRIDGE_API_KEY');
|
||||||
|
if (!k) throw new Error('BRIDGE_API_KEY belum diset (lihat README cara set)');
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __setBridgeKey(k) {
|
||||||
|
PropertiesService.getScriptProperties().setProperty('BRIDGE_API_KEY', k);
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
|
|
||||||
function out(obj) {
|
function out(obj) {
|
||||||
return ContentService.createTextOutput(JSON.stringify(obj))
|
return ContentService.createTextOutput(JSON.stringify(obj))
|
||||||
.setMimeType(ContentService.MimeType.JSON);
|
.setMimeType(ContentService.MimeType.JSON);
|
||||||
@@ -17,7 +27,7 @@ function out(obj) {
|
|||||||
function doGet(e) {
|
function doGet(e) {
|
||||||
try {
|
try {
|
||||||
var p = (e && e.parameter) || {};
|
var p = (e && e.parameter) || {};
|
||||||
if (p.apiKey !== API_KEY) return out({ ok: false, error: 'unauthorized' });
|
if (p.apiKey !== getApiKey()) return out({ ok: false, error: 'unauthorized' });
|
||||||
var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
|
var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
|
||||||
var op = p.op || 'meta';
|
var op = p.op || 'meta';
|
||||||
if (op === 'meta') {
|
if (op === 'meta') {
|
||||||
|
|||||||
Reference in New Issue
Block a user