question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle custom metadata dinamically

See original GitHub issue

Is there any way to handle custom “headers” as metadata when uploading files to S3?

I know the existence of params in plugin’s config, the issue is that it accepts a plain object. I’m looking for a dynamically way to inject such configuration after SSR.

My use case is for each html file attach a Content-Security-Policy header that can then be served from S3. Each file is set a header during SSR by using gatsby-plugin-csp which I intercept and write in ./cache/s3.metadata.json file and skip the html meta tag.

Then, during deployment I would like to retrieve that data and merge with s3.params.json.

I’ve successfully hacked /src/bin.ts#L245 to receive an additional s3.metadata.json file with Metadata objects.

If you think this is not supported, would you see it feasible to implement one of the following solutions:

  1. somehow pass a function to params in config that would run during deployment (not ideal I believe)
  2. during s3.params.json generation merge that info somehow (by passing a new additionalParamsFile optional plugin option).

Thank you.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lightningspiritcommented, Nov 11, 2021

As such, S3 does not permit a user to specify the Content-Security-Policy for the data it serves.

Hi! You’re not incorrect, but while it is not possible to append data without x-amz-meta- prefix, you can use Cloudfront Lambda Edge, as you mentioned, to parse those keys (if present) and return the correct HTTP headers based on a white list.

In my case, that’s exactly what I’m doing. I have .html files with x-amz-meta-content-security-policy metadata. The lambda “copies” the content and creates a Content-Security-Policy header with that value.

1reaction
jarizcommented, Apr 28, 2020

Well, the problem, as you might realise, is that the params are serialised to JSON once the actual deployment phase is running.
We could (before writing the params into s3.params.json) check if any of the values in the params object are of a function type, execute said function, and then serialize the result into the file.
Would that suffice for your use case @lightningspirit? I don’t have the time right now to figure out how the mentioned CSP plugin works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ability to dynamically reference Custom Metadata types for ...
Developer's perspective, we are using dynamic custom metadata types for logical conditions and controls over the automation to manage executions much better ...
Read more >
Building Robust Dynamic Code with Custom Metadata Field ...
The ability to create custom fields is a key feature when it comes to customising. Shortly followed by using features like Validation Rules, ......
Read more >
Dynamic parsing using custom metadata - Packt Subscription
We want to be able, at runtime, to determine how we should map the data provided to us to different fields within Salesforce....
Read more >
Custom Metadata - Your Key to Dynamic Code - YouTube
Are you being pulled away from meaningful work to make small changes to the business logic of custom code?
Read more >
Can you dynamically instantiate a Custom MetaData object in ...
Yes, you can do that. You have to use SObject as follows: SObject so = [SELECT masterlabel FROM Queue_Level_Milestone_SLA__mdt limit 1][0];.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found