Skip to content

Commit

Permalink
Preparing release 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
queue-it committed Nov 3, 2021
1 parent 36d258e commit ed8a9f2
Show file tree
Hide file tree
Showing 16 changed files with 8,520 additions and 3 deletions.
40 changes: 40 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[merge]
tool = kdiff3
guitool = kdiff3
[diff]
guitool = kdiff3
tool = vsdiffmerge
[core]
editor = \"F:/Program Files (x86)/GitExtensions/GitExtensions.exe\" fileeditor
autocrlf = false
[user]
name = Vasil
email = [email protected]
[pull]
rebase = false
[fetch]
prune = false
[rebase]
autoStash = false
[winUpdater]
recentlySeenVersion = 2.26.1.windows.1
[mergetool "kdiff3"]
path = C:/Program Files/KDiff3/kdiff3.exe
cmd = \"C:/Program Files/KDiff3/kdiff3.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"
[difftool "kdiff3"]
path = C:/Program Files/KDiff3/kdiff3.exe
cmd = \"C:/Program Files/KDiff3/kdiff3.exe\" \"$LOCAL\" \"$REMOTE\"
[url "[email protected]:"]
insteadOf = https://git.smartmodule.net/
[difftool]
prompt = true
[difftool "vsdiffmerge"]
cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
keepBackup = false
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[credential]
helper = "!f() { /root/.vscode-server/bin/2b9aebd5354a3629c3aba0a5f5df49f43d6689f8/node /tmp/vscode-remote-containers-9669530c1ddca4fa7b1438b95129151b954035ef.js $*; }; f"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kuedge.tgz
outDir/
/.idea
/.vs
/node_modules
/dist
5 changes: 5 additions & 0 deletions .gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
}
}
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ Installing the edge worker the first time requires uploading an archive file (TG
- 3.3 Push integration config to Akamai EdgeKV
- Step 4: Upload the Queue-it edge worker bundle
- Step 5: Update the bundle.js file in the Edge Worker manager with a new version and deploy the new version of EdgeWorker
- Step 6: In Akamai Propery, add queue-it required variables named as 'PMUSER_QUEUEIT_CUSTOMERID', 'PMUSER_QUEUEIT_CONFIG_TYPE', 'PMUSER_QUEUEIT_SECRET_KEY' and 'PMUSER_QUEUEIT_API_KEY' optional if 'PMUSER_QUEUEIT_CONFIG_TYPE' is cache. Section 'QueueIT variables' describes queue-it varibles in details.
- Step 6: In Akamai Propery, add queue-it required **hidden** variables named as
'PMUSER_QUEUEIT_CUSTOMERID', 'PMUSER_QUEUEIT_CONFIG_TYPE', 'PMUSER_QUEUEIT_SECRET_KEY'
and if 'PMUSER_QUEUEIT_CONFIG_TYPE' is set to `cache` then
- 'PMUSER_QUEUEIT_API_KEY' set for the API key
Section 'QueueIT variables' describes queue-it varibles in details.
- Step 7: In Akamai Property, create a behaviour for the URL/Hostname/Conditions where the edge worker will apply choose the name of EdgeWorker created in the upper section (make sure you are not executing edgeworker for static resources)
- Step 8: Add a Site Failover behavior to retry if EdgeWorker fails
- Step 9: Add integration config download criteria condition, behavior and cache if integration config download method is used.
Expand All @@ -49,7 +53,7 @@ Latest integration config can be downloaded from GO Queue-it Platform and then u
To use the inline integration config, set 'QUEUEIT_CONFIG_TYPE' queue-it variable value to 'inline' in Akamai property manager.

### 3.2 Dynamically download and cache integration config
#### NOTE: If you are deploying to a staging environment that has an IP-filter applied, make sure to whitelist the path to the integration config, so the IP-filter doesn’t apply. Otherwise the Queue-it Edge Worker will be blocked from accessing the configuration path.
#### NOTE: If you are deploying to a staging environment that has an IP-filter applied, make sure to whitelist the path to the integration config, so the IP-filter doesn’t apply. Otherwise, the Queue-it Edge Worker will be blocked from accessing the configuration path.
Integration config can be downloaded by calling Queue-IT API endpoint and then cached in Akamai network. In Akamai property manager, set variables 'PMUSER_QUEUEIT_CONFIG_TYPE' to 'cache' and 'PMUSER_QUEUEIT_API_KEY' to your API key. Configure the following Akamai property rules by setting the criteria, out going request path and caching behavior to download and cache the integration config.

#### Edgeworker rule
Expand Down Expand Up @@ -138,7 +142,9 @@ export { edgekv_access_tokens };
```

### QueueIT variables
To integrate with QueueIT Akamai connector it is required to define queueit variables in your Akamai property. These variables should be named as 'PMUSER_QUEUEIT_CUSTOMERID', 'PMUSER_QUEUEIT_CONFIG_TYPE', 'PMUSER_QUEUEIT_SECRET_KEY', 'PMUSER_QUEUEIT_API_KEY' and of type 'Hidden' in Akamai property manager. The following table describes the options for variable values.
To integrate with QueueIT Akamai connector it is required to define queueit variables in your Akamai property.
These variables should be named as 'PMUSER_QUEUEIT_CUSTOMERID', 'PMUSER_QUEUEIT_CONFIG_TYPE', 'PMUSER_QUEUEIT_SECRET_KEY', 'PMUSER_QUEUEIT_API_KEY'
and of type **Hidden** in Akamai property manager. The following table describes the options for variable values.

| Variable | Required | Value |
| :---: | :---: | :---: |
Expand Down
84 changes: 84 additions & 0 deletions akamaiHttpContextProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/// <reference path="types/akamai.d.ts"/>
import {Cookies} from 'cookies';

export class AkamaiHttpContextProvider {
private _httpRequest: AkamaiHttpRequest;
private _httpResponse: AkamaiHttpResponse;

public constructor(akamiNativeRequest: any, akamaiNativeResponse: any) {
this._httpRequest = new AkamaiHttpRequest(akamiNativeRequest);
this._httpResponse = new AkamaiHttpResponse(akamaiNativeResponse);
}

public getHttpRequest() {
return this._httpRequest;
}

public getHttpResponse() {
return this._httpResponse;
}
}

class AkamaiHttpRequest {
constructor(private _akamiNativeRequest: any) {
}

public getUserAgent() {
return this.getHeader("user-agent");
}

public getHeader(headerNameArg: string) {
return (this._akamiNativeRequest.getHeader(headerNameArg) || []).toString();
}

public getAbsoluteUri() {
return `${this._akamiNativeRequest.scheme}://${this._akamiNativeRequest.host}${this._akamiNativeRequest.url}`;
}

public getUserHostAddress() {
return this._akamiNativeRequest.getVariable('PMUSER_TRUE_CLIENT_IP');
}

public getCookieValue(cookieKey: string) {
try {
let cookies = new Cookies(this._akamiNativeRequest.getHeader('Cookie'));
let cookieValue = cookies.get(cookieKey);
if (cookieValue)
return decodeURIComponent(cookieValue);

} catch {
return undefined;
}
}

public getRequestBodyAsString() {
return "";
}
}

class AkamaiHttpResponse {
constructor(private _akamiNativeRequest: any) {
}

public setCookie(cookieName: string, cookieValue: string, domain: string, expiration, httpOnly: boolean, isSecure: boolean) {

// expiration is in secs, but Date needs it in milisecs
let expirationDate = new Date(expiration * 1000);

let setCookieString = `${cookieName}=${encodeURIComponent(cookieValue)}; expires=${expirationDate.toUTCString()};`;
if (domain) {
setCookieString += ` domain=${domain};`;
}

if (httpOnly) {
setCookieString += " HttpOnly;"
}

if (isSecure) {
setCookieString += " Secure;"
}

setCookieString += " path=/";
this._akamiNativeRequest.storeCookie(setCookieString);
}
}
75 changes: 75 additions & 0 deletions gulpfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const {src, dest} = require("gulp");
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');
const modifyFile = require('gulp-modify-file');
const path = require('path')

function addExports(content) {
content = "var exportObject = {};\n" + content;
content += `
var Utils = exportObject.Utils;
var KnownUser = exportObject.KnownUser;
export { KnownUser, Utils };`;
const lastPropertyDefinition = content.lastIndexOf('Object.defineProperty(');
const newLine = content.indexOf('\n', lastPropertyDefinition);
const firstPart = content.substring(0, newLine);
const secondPart = content.substring(newLine + 1);
return firstPart + `
exportObject.KnownUser = KnownUser_1.KnownUser;
exportObject.Utils = QueueITHelpers_1.Utils;
` + secondPart;
}

exports.packageArtifacts = () => {
return src([
'bundle.json',
'outDir/*.js',
'outDir/**/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename !== 'queueit-knownuserv3-sdk.js') {
return content;
}
content = addExports(content);
return content;
}))
.pipe(tar('kuedge.tar'))
.pipe(gzip())
.pipe(dest('dist'));
}

exports.prepare = ()=>{
return src([
'sdk/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename !== 'queueit-knownuserv3-sdk.js') {
return content;
}
content = addExports(content);
return content;
}))
.pipe(dest('outDir/sdk'));
}

exports.packageForDeployment = () => {
return src([
'bundle.json',
'edgegrid.edgerc',
'outDir/*.js',
'outDir/**/*.js'
])
.pipe(modifyFile((content, filePath, _) => {
let filename = path.basename(filePath);
if (filename !== 'queueit-knownuserv3-sdk.js') {
return content;
}
content = addExports(content);
return content;
}))
.pipe(tar('kuedge.deployment.tar'))
.pipe(gzip())
.pipe(dest('dist'));
}
41 changes: 41 additions & 0 deletions integrationConfigProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*INLINE config*/
const inlineIntegrationConfig = 'IF YOU ARE USING INLINE CONFIGURATION: GET YOUR INTEGRATION CONFIG IN JSON FORMAT FROM GO QUEUE-IT PLATFORM AND PASTE IT HERE';
/*INLINE config*/

import { httpRequest } from 'http-request';
import { EdgeKV } from './lib/edgekv.js';

export { IntegrationConfigProvider };
class IntegrationConfigProvider {
public static getIntegrationConfig = async function (configType: string, apiKey: string) {

switch (configType.toLowerCase()) {
case 'inline':
return inlineIntegrationConfig;
case 'cache':
return IntegrationConfigProvider.getIntegrationConfigFromCache(apiKey);
case 'edgekv':
return IntegrationConfigProvider.getIntegrationConfigFromEdgeKV();
}
return '';

}
private static getIntegrationConfigFromCache = async function (apiKey: string) {
const options: any = {}
options.method = "GET";
options.headers = { "api-key": apiKey };
options.timeout = 950;
return (await httpRequest("/queueit/integrationconfig/", options)).text();
}
private static getIntegrationConfigFromEdgeKV = async function () {
let edgeKV = new EdgeKV("QueueIT", "integrations");

return await edgeKV.requestHandlerTemplate(
() => edgeKV.getRequest({ namespace: 'QueueIT', group: 'integrations', item: 'integrationConfig' }),
(response) => response.text(),
async (response) => await edgeKV.streamText(response.body),
"GET JSON string",
null);
}

}
Loading

0 comments on commit ed8a9f2

Please sign in to comment.