Skip to content
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

load_var friendly format for metadata.json #248

Open
vixus0 opened this issue Jan 10, 2021 · 3 comments
Open

load_var friendly format for metadata.json #248

vixus0 opened this issue Jan 10, 2021 · 3 comments

Comments

@vixus0
Copy link
Contributor

vixus0 commented Jan 10, 2021

The current output format for metadata.json that gets populated on a get step is a list of maps:

[{"name": "item1", "value": "bla"},
 {"name": "item2", "value": "foo"},
 ...]

Instead, a simple map like {"item1": "bla", "item2": "foo"} would be more useful for Concourse's load_var step and then we wouldn't need a separate load_var for every metadata file that gets dumped.

@ljluestc
Copy link

ljluestc commented Sep 4, 2023

Currently, the metadata.json is being populated with a list of maps:

[
  {"name": "item1", "value": "bla"},
  {"name": "item2", "value": "foo"},
  ...
]

To change this to a simple map structure like:

{
  "item1": "bla",
  "item2": "foo",
  ...
}

You'll need to modify the logic that generates the metadata.json file in Concourse. Here's a high-level approach to achieve this:

  1. Modify the Metadata Generation Logic:
    Locate the part of your Concourse pipeline or resource definition where the metadata.json is generated after a get step. This is typically done in a custom script or resource script.

  2. Transform List of Maps to Map:
    Inside the script, after fetching the metadata, you'll need to transform the list of maps into the desired map structure. You can achieve this by iterating through the list of maps and constructing the new map:

    # Fetch metadata.json content
    metadata_json=$(cat metadata.json)
    
    # Transform list of maps to map
    map_json="{}"
    for item in $(echo "$metadata_json" | jq -r '.[] | @base64'); do
      name=$(echo "$item" | base64 --decode | jq -r '.name')
      value=$(echo "$item" | base64 --decode | jq -r '.value')
      map_json=$(echo "$map_json" | jq --arg name "$name" --arg value "$value" '.[$name] = $value')
    done
    
    # Output the transformed map as JSON
    echo "$map_json" > transformed_metadata.json
  3. Use the Transformed Metadata:
    The transformed_metadata.json file now contains the desired map structure. You can use this transformed metadata in your Concourse tasks or steps that rely on it.

@bgandon
Copy link

bgandon commented May 10, 2024

Unfortunately, there is no hope that you get any further support here (#246 was 2+y ago).

But recent news is that the Cloud Foundry community is now maintaining a fork of this resource at cloudfoundry-community/github-pr-resource.

In that new repo, the PR #276 that I had submitted here has been ported as cloudfoundry-community#7 and has been merged.

On our Concourse installation at Gstack, the latest version is working fine. Could you give a try and provide feedback there?

(the new resource is a drop-in replacement; you only have to switch telia-ossto cfcommunity in in the resource_types: declaration, i.e. specify repository: cfcommunity/github-pr-resource)

@bgandon
Copy link

bgandon commented May 11, 2024

Now that PR cloudfoundry-community#7 is shipped (see v0.25.0), could you please closed this issue @schmurfy? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants