Skip to content

Instantly share code, notes, and snippets.

@smaglio81
smaglio81 / SharedFlow.xml
Created July 15, 2018 21:57
Query String or Header API Key Verification Shared Flow
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SharedFlow name="default">
<Step>
<Name>merge-query-string-api-key</Name>
</Step>
<Step>
<Name>verify-api-key</Name>
</Step>
</SharedFlow>
@smaglio81
smaglio81 / Javascript.xml
Created July 15, 2018 22:00
Merge Query String API Key Javascript Policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="merge-query-string-api-key">
<DisplayName>Merge Query String API Key</DisplayName>
<Properties/>
<ResourceURL>jsc://Merge-Query-String-API-Key.js</ResourceURL>
</Javascript>
@smaglio81
smaglio81 / VerifyAPIKey.xml
Created July 15, 2018 22:06
Verify API Key Policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="verify-api-key">
<DisplayName>Verify API Key</DisplayName>
<Properties/>
<APIKey ref="request.header.api-key"/>
</VerifyAPIKey>
@smaglio81
smaglio81 / Merge-Query-String-API-Key.js
Last active July 16, 2018 00:14
Javascript to check for a query string api key and merge it into an Apigee Header variable
/*
* Attempts to "merge" (aka. use) the query string parameter 'api-key'
* into the header variable api-key if the header variable is missing.
* if the header variable exists, then the header variable is always used
* and the query string parameter is ignored.
*/
var hApiKey = context.getVariable("request.header.api-key")
//print("header: " + hApiKey);
@smaglio81
smaglio81 / AssignMessage.xml
Last active July 16, 2018 01:12
Assign Query Param to Header (PreFlow Step includes this condition: <Condition>request.header.api-key !~ "*"</Condition>)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-API-Key-To-Header">
<DisplayName>Assign API Key To Header</DisplayName>
<AssignTo createNew="false" transport="http" type="request"/>
<Properties/>
<Add>
<Headers>
<Header name="api-key">{request.queryparam.api-key}</Header>
</Headers>
</Add>
# This file shouldn't be run on it's own. It should be loaded using the Apigee Module.
<#
.SYNOPSIS
Implementation of the Time-based One-time Password Algorithm used by Google Authenticator.
.DESCRIPTION
# This file shouldn't be run on it's own. It should be loaded using the Apigee Module.
<#
.SYNOPSIS
Makes a call to the Apigee OAuth login endpoint and gets access tokens to use.
This should be used internally by the Apigee module. But, it shouldn't be needed by
the developer.
@smaglio81
smaglio81 / Apigee.psm1
Created August 11, 2018 19:09
Apigee module using the Login upon load
if($global:Apigee -eq $null) {
$global:Apigee = @{}
$global:Apigee.ApiUrl = "https://api.enterprise.apigee.com/v1/organizations/"
# Use OAuth for access credentials. All public info here:
# https://docs.apigee.com/api-platform/system-administration/using-oauth2-security-apigee-edge-management-api
$global:Apigee.OAuthLogin = @{}
# get username / password for management API
@smaglio81
smaglio81 / WebAdmin.ConvertTo-UrlBasedAppPoolName.ps1
Created August 18, 2018 22:01
The name kind of covers it. For example https://unittest.some.company.com should have an application pool of unittest.some.company.com. A second example would be https://unittest.some.company.com/subsitea/ should have an application pool of unittest.some.company.com_subsitea.
<#
.SYNOPSIS
Enforces the formatting standards for application pool names.
This should be used to figure out the application pool name before creating an
new one. The name is also used to create unique ARR rule names.
.PARAMETER Url
The url to parse and convert to our standardized app pool name.
@smaglio81
smaglio81 / WebAdmin.Test-IsLocalComputerName.ps1
Created August 18, 2018 22:01
Tests if the command will need to run locally or remotely.
<#
.SYNOPSIS
Checks if the given ComputerName is for the local computer
.PARAMETER ComputerName
The name of a computer to check.
.EXAMPLE
$session = New-PSSession .
$computerName = $session.ComputerName