Skip to content

Commit

Permalink
Merge pull request #2 from stape-io/get_api_url_from_headers
Browse files Browse the repository at this point in the history
Making Stape API url from headers
  • Loading branch information
Bukashk0zzz authored Nov 15, 2024
2 parents 225546a + 87e5d91 commit d5b1c59
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 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: 29ec1df58d8f80587fbe27870e325811a7ebc993
changeNotes: Getting Stape API key from headers.
- sha: d5eb06bbb54b4a59ea2fba8cfd2a77a1c180011b
changeNotes: Added Stape API, updated Google Auth.
- sha: 75945e29bfd95c835b9b9b21fe9c5a2dce2a89eb
Expand Down
13 changes: 4 additions & 9 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const traceId = getRequestHeader('trace-id');
const spreadsheetId = data.url.replace('https://docs.google.com/spreadsheets/d/', '').split('/')[0];
let method = data.type === 'add' ? 'POST' : 'PUT';
const postBody = getData();

const postUrl = getUrl();


Expand Down Expand Up @@ -103,19 +102,15 @@ function sendStoreRequest() {

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');
Expand Down
77 changes: 49 additions & 28 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,6 @@ ___TEMPLATE_PARAMETERS___
}
],
"simpleValueType": true
},
{
"type": "TEXT",
"name": "containerKey",
"displayName": "Stape Container API key",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
],
"enablingConditions": [
{
"paramName": "authFlow",
"paramValue": "stape",
"type": "EQUALS"
}
],
"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."
}
]
},
Expand Down Expand Up @@ -186,7 +167,6 @@ const traceId = getRequestHeader('trace-id');
const spreadsheetId = data.url.replace('https://docs.google.com/spreadsheets/d/', '').split('/')[0];
let method = data.type === 'add' ? 'POST' : 'PUT';
const postBody = getData();

const postUrl = getUrl();


Expand Down Expand Up @@ -275,19 +255,15 @@ function sendStoreRequest() {

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');
Expand Down Expand Up @@ -450,6 +426,51 @@ ___SERVER_PERMISSIONS___
"string": "trace-id"
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "headerName"
}
],
"mapValue": [
{
"type": 1,
"string": "x-gtm-api-key"
}
]
},
{
"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-identifier"
}
]
}
]
}
Expand Down

0 comments on commit d5b1c59

Please sign in to comment.