generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating to add Bulk scanning api to new Management API service. #543
Draft
davejones74
wants to merge
3
commits into
master
Choose a base branch
from
PAY-6602-APIM-Migration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Plan Result (aat)
Change Result (Click me) # azurerm_template_deployment.bulk-scanning-payment[0] will be updated in-place
~ resource "azurerm_template_deployment" "bulk-scanning-payment" {
id = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/core-infra-aat/providers/Microsoft.Resources/deployments/bulk-scanning-payment-aat"
name = "bulk-scanning-payment-aat"
~ parameters = {
~ "policy" = <<-EOT
<policies>
<backend>
<base/>
</backend>
<inbound>
<base/>
<choose>
- <when condition="@(context.Request.Certificate == null || context.Request.Certificate.NotAfter < DateTime.Now || context.Request.Certificate.NotBefore > DateTime.Now || !(new string[] {"7744A2F56BD3B73C0D7FED61309E1C65AF08538C","792265A947D0C76D4F67A0878B1D06E60976DFDA","4396D69786566676383DD5BFF84B95E2A9975263"}.Any(c => c == context.Request.Certificate.Thumbprint)))" >
+ <when condition="@(context.Request.Certificate == null || context.Request.Certificate.NotAfter < DateTime.Now || context.Request.Certificate.NotBefore > DateTime.Now || !(new string[] {"7744A2F56BD3B73C0D7FED61309E1C65AF08538C","792265A947D0C76D4F67A0878B1D06E60976DFDA","4396D69786566676383DD5BFF84B95E2A9975263","BFE89B4BA1F47E048CFDF125C2E1BB4E2CC26083"}.Any(c => c == context.Request.Certificate.Thumbprint)))" >
<return-response>
<set-status code="403" reason="Invalid client certificate."/>
</return-response>
</when>
</choose>
<!-- generate totp -->
<set-variable name="client_id" value="api_gw" />
<set-variable name="client_secret" value="C5OI566EGMPHT3CC" />
<set-variable name="one_time_password" value="@{
const string Base32AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
var bits = "C5OI566EGMPHT3CC".ToUpper().ToCharArray().Select(c => Convert.ToString(Base32AllowedCharacters.IndexOf(c), 2).PadLeft(5, '0')).Aggregate((a, b) => a + b);
var secretKeyBytes = Enumerable.Range(0, bits.Length / 8).Select(i => Convert.ToByte(bits.Substring(i * 8, 8), 2)).ToArray();
var unixTimestamp = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var timeIndex = unixTimestamp / 30;
byte[] challenge = BitConverter.GetBytes(timeIndex);
if (BitConverter.IsLittleEndian) {
Array.Reverse(challenge);
}
HMACSHA1 hmac = new HMACSHA1(secretKeyBytes);
byte[] hash = hmac.ComputeHash(challenge);
int offset = hash[19] & 0xf;
int truncatedHash = hash[offset] & 0x7f;
for (int i = 1; i < 4; i++)
{
truncatedHash <<= 8;
truncatedHash |= hash[offset + i] & 0xff;
}
truncatedHash %= 1000000;
return truncatedHash.ToString("D6");
}"/>
<send-request ignore-error="false" timeout="20" response-variable-name="s2sBearerToken" mode="new">
<set-url>http://rpe-service-auth-provider-aat.service.core-compute-aat.internal/lease</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
return new JObject(
new JProperty("microservice", (string)context.Variables["client_id"]),
new JProperty("oneTimePassword", (string)context.Variables["one_time_password"])
).ToString();
}</set-body>
</send-request>
<set-header name="ServiceAuthorization" exists-action="override">
<value>@("Bearer " + ((IResponse)context.Variables["s2sBearerToken"]).Body.As<string>())</value>
</set-header>
</inbound>
<outbound>
<base/>
</outbound>
<on-error>
<base/>
</on-error>
</policies>
EOT
# (5 unchanged elements hidden)
}
# (4 unchanged attributes hidden)
# (1 unchanged block hidden)
}
# azurerm_template_deployment.cft-bulk-scanning-payment[0] will be created
+ resource "azurerm_template_deployment" "cft-bulk-scanning-payment" {
+ deployment_mode = "Incremental"
+ id = (known after apply)
+ name = "cft-bulk-scanning-payment-aat"
+ outputs = (known after apply)
+ parameters = {
+ "apiBasePath" = "bulk-scanning-payment"
+ "apiManagementServiceName" = "cft-api-mgmt-aat"
+ "apiName" = "bulk-scanning-payment-api"
+ "apiProductName" = "bulk-scanning-payment"
+ "policy" = <<-EOT
<policies>
<backend>
<base/>
</backend>
<inbound>
<base/>
<choose>
<when condition="@(context.Request.Certificate == null || context.Request.Certificate.NotAfter < DateTime.Now || context.Request.Certificate.NotBefore > DateTime.Now || !(new string[] {"7744A2F56BD3B73C0D7FED61309E1C65AF08538C","792265A947D0C76D4F67A0878B1D06E60976DFDA","4396D69786566676383DD5BFF84B95E2A9975263","BFE89B4BA1F47E048CFDF125C2E1BB4E2CC26083"}.Any(c => c == context.Request.Certificate.Thumbprint)))" >
<return-response>
<set-status code="403" reason="Invalid client certificate."/>
</return-response>
</when>
</choose>
<!-- generate totp -->
<set-variable name="client_id" value="api_gw" />
<set-variable name="client_secret" value="C5OI566EGMPHT3CC" />
<set-variable name="one_time_password" value="@{
const string Base32AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
var bits = "C5OI566EGMPHT3CC".ToUpper().ToCharArray().Select(c => Convert.ToString(Base32AllowedCharacters.IndexOf(c), 2).PadLeft(5, '0')).Aggregate((a, b) => a + b);
var secretKeyBytes = Enumerable.Range(0, bits.Length / 8).Select(i => Convert.ToByte(bits.Substring(i * 8, 8), 2)).ToArray();
var unixTimestamp = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var timeIndex = unixTimestamp / 30;
byte[] challenge = BitConverter.GetBytes(timeIndex);
if (BitConverter.IsLittleEndian) {
Array.Reverse(challenge);
}
HMACSHA1 hmac = new HMACSHA1(secretKeyBytes);
byte[] hash = hmac.ComputeHash(challenge);
int offset = hash[19] & 0xf;
int truncatedHash = hash[offset] & 0x7f;
for (int i = 1; i < 4; i++)
{
truncatedHash <<= 8;
truncatedHash |= hash[offset + i] & 0xff;
}
truncatedHash %= 1000000;
return truncatedHash.ToString("D6");
}"/>
<send-request ignore-error="false" timeout="20" response-variable-name="s2sBearerToken" mode="new">
<set-url>http://rpe-service-auth-provider-aat.service.core-compute-aat.internal/lease</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
return new JObject(
new JProperty("microservice", (string)context.Variables["client_id"]),
new JProperty("oneTimePassword", (string)context.Variables["one_time_password"])
).ToString();
}</set-body>
</send-request>
<set-header name="ServiceAuthorization" exists-action="override">
<value>@("Bearer " + ((IResponse)context.Variables["s2sBearerToken"]).Body.As<string>())</value>
</set-header>
</inbound>
<outbound>
<base/>
</outbound>
<on-error>
<base/>
</on-error>
</policies>
EOT
+ "serviceUrl" = "http://ccpay-bulkscanning-api-aat.service.core-compute-aat.internal"
}
+ resource_group_name = "cft-aat-network-rg"
+ template_body = jsonencode(
{
+ "$schema" = "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
+ contentVersion = "1.0.0.0"
+ parameters = {
+ apiBasePath = {
+ metadata = {
+ description = "Path to the API (excluding host)"
}
+ type = "string"
}
+ apiManagementServiceName = {
+ metadata = {
+ description = "API Management service name"
}
+ type = "string"
}
+ apiName = {
+ metadata = {
+ description = "Name of the API (gateway)"
}
+ type = "string"
}
+ apiProductName = {
+ metadata = {
+ description = "API Management product name"
}
+ type = "string"
}
+ policy = {
+ type = "string"
}
+ serviceUrl = {
+ metadata = {
+ description = "URL of the backend service (to be protected by the API)"
}
+ type = "string"
}
}
+ resources = [
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = []
+ name = "[concat(parameters('apiManagementServiceName') ,'/', parameters('apiProductName'))]"
+ properties = {
+ approvalRequired = true
+ displayName = "[parameters('apiProductName')]"
+ state = "published"
+ subscriptionRequired = true
}
+ type = "Microsoft.ApiManagement/service/products"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[resourceId('Microsoft.ApiManagement/service/products', parameters('apiManagementServiceName'), parameters('apiProductName'))]",
]
+ name = "[concat(parameters('apiManagementServiceName') ,'/', parameters('apiProductName'), '/', variables('developersGroupName'))]"
+ properties = {
+ builtIn = true
+ description = "Developers group"
+ displayName = "Developers"
+ type = "system"
}
+ type = "Microsoft.ApiManagement/service/products/groups"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiName'))]"
+ properties = {
+ displayName = "bulk-scanning payments API"
+ path = "[parameters('apiBasePath')]"
+ protocols = [
+ "HTTPS",
]
+ serviceUrl = "[parameters('serviceUrl')]"
}
+ resources = [
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiName')]",
]
+ name = "bulk-scanning-payments-api"
+ properties = {
+ description = "Insert payment data from scanning third party"
+ displayName = "bulk-scanning payments api "
+ method = "POST"
+ request = {
+ description = "Used by third party scanning service to insert payments data in Bulk-scanning service"
+ representations = [
+ {
+ contentType = "application/json"
+ parameters = [
+ {
+ description = "BulkScanPayment"
+ in = "body"
+ name = "bulkScanPayment"
},
]
},
]
}
+ responses = [
+ {
+ description = "Created"
+ statusCode = 201
},
+ {
+ description = "Request failed due to malformed syntax"
+ statusCode = 400
},
+ {
+ description = "Failed authentication"
+ statusCode = 401
},
+ {
+ description = "Failed authorisation"
+ statusCode = 403
},
+ {
+ description = "Conflict"
+ statusCode = 409
},
]
+ urlTemplate = "/bulk-scan-payment"
}
+ type = "operations"
},
]
+ type = "Microsoft.ApiManagement/service/apis"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
+ "[variables('fullApiName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiProductName'), '/', parameters('apiName'))]"
+ type = "Microsoft.ApiManagement/service/products/apis"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
+ "[variables('fullApiName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiName'),'/policy')]"
+ properties = {
+ policyContent = "[parameters('policy')]"
}
+ type = "Microsoft.ApiManagement/service/apis/policies"
},
]
+ variables = {
+ developersGroupName = "Developers"
+ fullApiName = "[concat('Microsoft.ApiManagement/service/', parameters('apiManagementServiceName'), '/apis/', parameters('apiName'))]"
+ fullApiProductName = "[concat('Microsoft.ApiManagement/service/', parameters('apiManagementServiceName'), '/products/', parameters('apiProductName'))]"
}
}
)
}
Plan: 1 to add, 1 to change, 0 to destroy. |
Plan Result (prod)
Change Result (Click me) # azurerm_template_deployment.cft-bulk-scanning-payment[0] will be created
+ resource "azurerm_template_deployment" "cft-bulk-scanning-payment" {
+ deployment_mode = "Incremental"
+ id = (known after apply)
+ name = "cft-bulk-scanning-payment-prod"
+ outputs = (known after apply)
+ parameters = {
+ "apiBasePath" = "bulk-scanning-payment"
+ "apiManagementServiceName" = "cft-api-mgmt-prod"
+ "apiName" = "bulk-scanning-payment-api"
+ "apiProductName" = "bulk-scanning-payment"
+ "policy" = <<-EOT
<policies>
<backend>
<base/>
</backend>
<inbound>
<base/>
<choose>
<when condition="@(context.Request.Certificate == null || context.Request.Certificate.NotAfter < DateTime.Now || context.Request.Certificate.NotBefore > DateTime.Now || !(new string[] {"A78ED211FD9CE9DE2EEC47FD1A87F40CE0F4A1A5","F4A976E4967F8F4F621C87C67B9E258563F80F0E","B35BCF6C5C9DAEE7D0C756B666FFEDE2CF4659BA","B1BF8007527F85085D7C4A3DC406A9A6D124D721","E4E5673792DA616E14BEEF63F75DD96590124734","3FEBC1DE5DFBAF97B1F1CEEC80A1B192F999596A","CC852B5D1349041E1309AC5F9918ECE1FE5C023C"}.Any(c => c == context.Request.Certificate.Thumbprint)))" >
<return-response>
<set-status code="403" reason="Invalid client certificate."/>
</return-response>
</when>
</choose>
<!-- generate totp -->
<set-variable name="client_id" value="api_gw" />
<set-variable name="client_secret" value="JBSAAHPPEHPK3PXP" />
<set-variable name="one_time_password" value="@{
const string Base32AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
var bits = "JBSAAHPPEHPK3PXP".ToUpper().ToCharArray().Select(c => Convert.ToString(Base32AllowedCharacters.IndexOf(c), 2).PadLeft(5, '0')).Aggregate((a, b) => a + b);
var secretKeyBytes = Enumerable.Range(0, bits.Length / 8).Select(i => Convert.ToByte(bits.Substring(i * 8, 8), 2)).ToArray();
var unixTimestamp = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var timeIndex = unixTimestamp / 30;
byte[] challenge = BitConverter.GetBytes(timeIndex);
if (BitConverter.IsLittleEndian) {
Array.Reverse(challenge);
}
HMACSHA1 hmac = new HMACSHA1(secretKeyBytes);
byte[] hash = hmac.ComputeHash(challenge);
int offset = hash[19] & 0xf;
int truncatedHash = hash[offset] & 0x7f;
for (int i = 1; i < 4; i++)
{
truncatedHash <<= 8;
truncatedHash |= hash[offset + i] & 0xff;
}
truncatedHash %= 1000000;
return truncatedHash.ToString("D6");
}"/>
<send-request ignore-error="false" timeout="20" response-variable-name="s2sBearerToken" mode="new">
<set-url>http://rpe-service-auth-provider-prod.service.core-compute-prod.internal/lease</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
return new JObject(
new JProperty("microservice", (string)context.Variables["client_id"]),
new JProperty("oneTimePassword", (string)context.Variables["one_time_password"])
).ToString();
}</set-body>
</send-request>
<set-header name="ServiceAuthorization" exists-action="override">
<value>@("Bearer " + ((IResponse)context.Variables["s2sBearerToken"]).Body.As<string>())</value>
</set-header>
</inbound>
<outbound>
<base/>
</outbound>
<on-error>
<base/>
</on-error>
</policies>
EOT
+ "serviceUrl" = "http://ccpay-bulkscanning-api-prod.service.core-compute-prod.internal"
}
+ resource_group_name = "cft-prod-network-rg"
+ template_body = jsonencode(
{
+ "$schema" = "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
+ contentVersion = "1.0.0.0"
+ parameters = {
+ apiBasePath = {
+ metadata = {
+ description = "Path to the API (excluding host)"
}
+ type = "string"
}
+ apiManagementServiceName = {
+ metadata = {
+ description = "API Management service name"
}
+ type = "string"
}
+ apiName = {
+ metadata = {
+ description = "Name of the API (gateway)"
}
+ type = "string"
}
+ apiProductName = {
+ metadata = {
+ description = "API Management product name"
}
+ type = "string"
}
+ policy = {
+ type = "string"
}
+ serviceUrl = {
+ metadata = {
+ description = "URL of the backend service (to be protected by the API)"
}
+ type = "string"
}
}
+ resources = [
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = []
+ name = "[concat(parameters('apiManagementServiceName') ,'/', parameters('apiProductName'))]"
+ properties = {
+ approvalRequired = true
+ displayName = "[parameters('apiProductName')]"
+ state = "published"
+ subscriptionRequired = true
}
+ type = "Microsoft.ApiManagement/service/products"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[resourceId('Microsoft.ApiManagement/service/products', parameters('apiManagementServiceName'), parameters('apiProductName'))]",
]
+ name = "[concat(parameters('apiManagementServiceName') ,'/', parameters('apiProductName'), '/', variables('developersGroupName'))]"
+ properties = {
+ builtIn = true
+ description = "Developers group"
+ displayName = "Developers"
+ type = "system"
}
+ type = "Microsoft.ApiManagement/service/products/groups"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiName'))]"
+ properties = {
+ displayName = "bulk-scanning payments API"
+ path = "[parameters('apiBasePath')]"
+ protocols = [
+ "HTTPS",
]
+ serviceUrl = "[parameters('serviceUrl')]"
}
+ resources = [
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiName')]",
]
+ name = "bulk-scanning-payments-api"
+ properties = {
+ description = "Insert payment data from scanning third party"
+ displayName = "bulk-scanning payments api "
+ method = "POST"
+ request = {
+ description = "Used by third party scanning service to insert payments data in Bulk-scanning service"
+ representations = [
+ {
+ contentType = "application/json"
+ parameters = [
+ {
+ description = "BulkScanPayment"
+ in = "body"
+ name = "bulkScanPayment"
},
]
},
]
}
+ responses = [
+ {
+ description = "Created"
+ statusCode = 201
},
+ {
+ description = "Request failed due to malformed syntax"
+ statusCode = 400
},
+ {
+ description = "Failed authentication"
+ statusCode = 401
},
+ {
+ description = "Failed authorisation"
+ statusCode = 403
},
+ {
+ description = "Conflict"
+ statusCode = 409
},
]
+ urlTemplate = "/bulk-scan-payment"
}
+ type = "operations"
},
]
+ type = "Microsoft.ApiManagement/service/apis"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
+ "[variables('fullApiName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiProductName'), '/', parameters('apiName'))]"
+ type = "Microsoft.ApiManagement/service/products/apis"
},
+ {
+ apiVersion = "2017-03-01"
+ dependsOn = [
+ "[variables('fullApiProductName')]",
+ "[variables('fullApiName')]",
]
+ name = "[concat(parameters('apiManagementServiceName'), '/', parameters('apiName'),'/policy')]"
+ properties = {
+ policyContent = "[parameters('policy')]"
}
+ type = "Microsoft.ApiManagement/service/apis/policies"
},
]
+ variables = {
+ developersGroupName = "Developers"
+ fullApiName = "[concat('Microsoft.ApiManagement/service/', parameters('apiManagementServiceName'), '/apis/', parameters('apiName'))]"
+ fullApiProductName = "[concat('Microsoft.ApiManagement/service/', parameters('apiManagementServiceName'), '/products/', parameters('apiProductName'))]"
}
}
)
}
Plan: 1 to add, 0 to change, 0 to destroy. |
Thor-tech-of-metal
approved these changes
Jun 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JIRA link (if applicable)
https://tools.hmcts.net/jira/browse/PAY-6602
Change description
Infra to add bulk scanning payment api to cft mgmt gateway.
Does this PR introduce a breaking change? (check one with "x")