Using Kong and Lua to change occurances of a url in the response body

Using the response transformer advanced plugin for kong, it looks like it is possible to replace urls in the body of an api.

The use case: you have an api that you have set to return hypermedia links as absolute urls to other resources.
The problem is that you have given the other party access to your api only by way of kong - an api gateway.
That means that the url's in the response body point to an api they do not have direct access to.

For example your api responds with a body:

{
    "realms": "https://virtualisation.fixes.co.za/realms/",
    "records": "https://virtualisation.fixes.co.za/records/"
}

Your api gateway is https://api.fixes.co.za, so you want to update the response to convert to:

{
    "realms": "https://api.fixes.co.za/virtualisation/realms/",
    "records": "https://api.fixes.co.za/virtualisation/records/"
}

Is it possible?

My search term:

Lua function to replace occurances of base url in json body.

With the standard request transformer it does not look possible.

The closest would be config.replace.json which does List of property:value pairs. If and only if the parameter is already present, replace its old value with the new one. Ignored if the parameter is not already present.

I want to string replace anywhere https://virtualisation.fixes.co.za/ is found and replace it with https://api.fixes.co.za/virtualisation/.
In any value or nested value.

It looks like the only way to do it would be with a custom lua function in aconfig.transform.functions of the pay for response transformer advanced

So you have to pay for kong enterprise, learn lua and then apply the function. To achieve this.

How much does a Mac Battery Replacement Cost and How Long till it Take?

I recently got my macbook pro battery replaced because it said so - when looking at the status.
I was getting a maximum of about 45 minutes of work before the plugin was required.
This is down from the original 8 hours.

So I booked it in for the replacement at my local iStore.

Make a booking on the istore with this link.

How Much Will it Cost?

When making the booking you get this message:

 Ensure that your device has been backed up prior to your booking date. Potential costs once you arrive for your appointment may include:
R200 - fee if device is not purchased from iStore.
R450 - fee for complex tech support if device is not purchased from iStore.
R250 - insurance letter.
R250 - insurance quote for iPhone or iPad.
R600 - insurance quote for Mac when device is out of warranty. 

In my case the device was out of warranty so I had to pay R600 at the iStore - although the item on the bill did not say insurance.
It said technical assessment.

The quote for the battery replacement was: R5743.35 (including VAT)

That included:

  • English INT, Top case with battery ISO, Space Grey. (R4994.23)
  • Labour Fee (R521.74) [Already Prepaid]

Then VAT was added to the above.

The total paid was: R6343.35

How Long Will it Take?

I booked it in at the istore at 15:30 on 2020-09-04.

Ready for collection notifiction came at 15:19 on 19 September 2020

I accepted the quote immediately.

They mentioned that it would take 5-7 business days.
In reality it took 10 business days.

In actual days, it took 15 days or half a month.

Timeline:

  • 2020-09-04: Booked in (and paid technical assement fee)
  • 2020-09-06: Dispatched to Service Centre
  • 2020-09-11: Assessment and quote sent through (Accepted immediately)
  • 2020-09-19: Ready for collection

Info After the Upgrade

It feels like the keycoard was replaced after the upgrade but I cannot be certain.
The battery was clearly replaced as per the system report:

  Charge Information:
  Charge Remaining (mAh):   4594
  Fully Charged:    Yes
  Charging: No
  Full Charge Capacity (mAh):   4827
  Health Information:
  Cycle Count:  1
  Condition:    Normal
  Battery Installed:    Yes
  Amperage (mA):    0
  Voltage (mV): 12805

Then looking at coconut battery history:

Old Macbook Battery History

New battery capacity

Is it Worth it?

The Macbook Pro 13inch 128GB edition cost me R18999 initially.
I have had it 2 and a half years, before requiring the replacement.

As per using personal assets for work purposes, depreciation of assets is done over 3 years.
So it makes sense to do the repair on the 3rd year of service.

Is it worth it...is a question you need to ask yourself.
For me I think it is as I spend alot of time working outside.

Practical Application: Implementing SSH security with TLS certificates

In any organisation of a large size managing access to servers and cloud resources is difficult.
There is often a tradeoff between convenience and security.
Changing these settings is also a bit scary in production as you can be locked out of your servers...

One solution mentioned by facebook engineering and smallstep is to make use of certificates to authenticate and authorise SSH users.

In this post we will look at what we need to achieve better SSH security and how to implement it...

What we need to know

The topics we should read up on are:

  • TLS certificates and public key cryptography
  • OpenSSL
  • Public Key Infrastructure (PKI)
  • SSH
  • Hashicorp Vault

Some books might be:

That is alot of reading.

Sources