Skip to content

Commit

Permalink
Merge pull request #2 from stape-io/get_api_key_from_headers
Browse files Browse the repository at this point in the history
Getting Stape api keys from headers
  • Loading branch information
Bukashk0zzz authored Nov 18, 2024
2 parents 847892c + ab33ebc commit 794773e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 35 deletions.
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
homepage: "https://stape.io/"
versions:
- sha: 23b0c6fd7552786a25685bd7595d8cbd0a2d80cf
changeNotes: Getting Stape API key from headers.
- sha: 1a8976d84016fdceb0a7f5da4171bfe467569a23
changeNotes: Added Stape Api, updated Google auth.
- sha: 9d93bcf5feb9af77df07d563744dfac20e2267f0
Expand Down
13 changes: 5 additions & 8 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const JSON = require('JSON');
const sendHttpRequest = require('sendHttpRequest');
const encodeUriComponent = require('encodeUriComponent');
const getGoogleAuth = require('getGoogleAuth');
const getRequestHeader = require('getRequestHeader');

const spreadsheetId = data.url.replace('https://docs.google.com/spreadsheets/d/', '').split('/')[0];
const requestUrl = getUrl();
Expand Down Expand Up @@ -44,19 +45,15 @@ function sendGetRequest() {

function getUrl() {
if (data.authFlow === 'stape') {
const containerKey = data.containerKey.split(':');
const containerZone = containerKey[0];
const containerIdentifier = containerKey[1];
const containerApiKey = containerKey[2];
const containerDefaultDomainEnd = containerKey[3] || 'io';
const containerIdentifier = getRequestHeader('x-gtm-identifier');
const defaultDomain = getRequestHeader('x-gtm-default-domain');
const containerApiKey = getRequestHeader('x-gtm-api-key');

return (
'https://' +
enc(containerIdentifier) +
'.' +
enc(containerZone) +
'.stape.' +
enc(containerDefaultDomainEnd) +
enc(defaultDomain) +
'/stape-api/' +
enc(containerApiKey) +
'/v1/spreadsheet/auth-proxy?spreadsheetId=' + spreadsheetId +
Expand Down
127 changes: 100 additions & 27 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,6 @@ ___TEMPLATE_PARAMETERS___
],
"simpleValueType": true,
"defaultValue": "stape"
},
{
"type": "TEXT",
"name": "containerKey",
"displayName": "Stape Container Api Key",
"simpleValueType": true,
"help": "It can be found in the detailed view of the container inside your \u003ca href\u003d\"https://app.stape.io/container/\" target\u003d\"_blank\"\u003eStape account.\u003c/a\u003e",
"enablingConditions": [
{
"paramName": "authFlow",
"paramValue": "stape",
"type": "EQUALS"
}
],
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
}
]
}
Expand All @@ -160,6 +141,7 @@ const JSON = require('JSON');
const sendHttpRequest = require('sendHttpRequest');
const encodeUriComponent = require('encodeUriComponent');
const getGoogleAuth = require('getGoogleAuth');
const getRequestHeader = require('getRequestHeader');

const spreadsheetId = data.url.replace('https://docs.google.com/spreadsheets/d/', '').split('/')[0];
const requestUrl = getUrl();
Expand Down Expand Up @@ -202,19 +184,15 @@ function sendGetRequest() {

function getUrl() {
if (data.authFlow === 'stape') {
const containerKey = data.containerKey.split(':');
const containerZone = containerKey[0];
const containerIdentifier = containerKey[1];
const containerApiKey = containerKey[2];
const containerDefaultDomainEnd = containerKey[3] || 'io';
const containerIdentifier = getRequestHeader('x-gtm-identifier');
const defaultDomain = getRequestHeader('x-gtm-default-domain');
const containerApiKey = getRequestHeader('x-gtm-api-key');
return (
'https://' +
enc(containerIdentifier) +
'.' +
enc(containerZone) +
'.stape.' +
enc(containerDefaultDomainEnd) +
enc(defaultDomain) +
'/stape-api/' +
enc(containerApiKey) +
'/v1/spreadsheet/auth-proxy?spreadsheetId=' + spreadsheetId +
Expand Down Expand Up @@ -304,6 +282,101 @@ ___SERVER_PERMISSIONS___
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "read_request",
"versionId": "1"
},
"param": [
{
"key": "headerWhitelist",
"value": {
"type": 2,
"listItem": [
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "headerName"
}
],
"mapValue": [
{
"type": 1,
"string": "x-gtm-identifier"
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "headerName"
}
],
"mapValue": [
{
"type": 1,
"string": "x-gtm-default-domain"
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "headerName"
}
],
"mapValue": [
{
"type": 1,
"string": "x-gtm-api-key"
}
]
}
]
}
},
{
"key": "headersAllowed",
"value": {
"type": 8,
"boolean": true
}
},
{
"key": "requestAccess",
"value": {
"type": 1,
"string": "specific"
}
},
{
"key": "headerAccess",
"value": {
"type": 1,
"string": "specific"
}
},
{
"key": "queryParameterAccess",
"value": {
"type": 1,
"string": "any"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]

Expand Down

0 comments on commit 794773e

Please sign in to comment.