Skip to content

Adding metadata to Secure Files API response

Darby Frey requested to merge secure-files-api-metadata into master

What does this MR do and why?

This MR adds the expires_at and metadata fields to the response payload in the Secure Files API for supported file types. This data will be used in the future to show in the UI (a prototype screenshot is below)

Additional Context

image

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. Ensure the feature flags are enabled:
Feature.enable(:ci_secure_files)
Feature.enable(:secure_files_metadata_parsers)
  1. Upload the sample file. To do this you will need an access token with API permissions and a sample project. The sample.cer file is included in the gitlab project at spec/fixtures/ci_secure_files/sample.cer

Request

curl --request POST --header "PRIVATE-TOKEN: <your access token>" "http://localhost:3001/api/v4/projects/<your project id>/secure_files"  --form "name=sample.cer" --form "file=@spec/fixtures/ci_secure_files/sample.cer"

Response

{
  "id": 9,
  "name": "sample.cer",
  "checksum": "f8c7d7884d4d105701273d17ae0363f35ca61e8975d226d69126170cb058d08c",
  "checksum_algorithm": "sha256",
  "created_at": "2022-11-02T13:59:57.313Z",
  "expires_at": null,
  "metadata": null
}
  1. Get a list of Secure Files for the project and verify that the metadata has been included

Request

curl --request GET --header "PRIVATE-TOKEN: <your access token>" "http://localhost:3001/api/v4/projects/<your project id>/secure_files"

Response

[
  {
    "id": 9,
    "name": "sample.cer",
    "checksum": "f8c7d7884d4d105701273d17ae0363f35ca61e8975d226d69126170cb058d08c",
    "checksum_algorithm": "sha256",
    "created_at": "2022-11-02T13:59:57.313Z",
    "expires_at": "2022-04-26T19:20:40.000Z",
    "metadata": {
      "id": "33669367788748363528491290218354043267",
      "issuer": {
        "C": "US",
        "O": "Apple Inc.",
        "CN": "Apple Worldwide Developer Relations Certification Authority",
        "OU": "G3"
      },
      "subject": {
        "C": "US",
        "O": "Darby Frey",
        "CN": "Apple Distribution: Darby Frey (N7SYAN8PX8)",
        "OU": "N7SYAN8PX8",
        "UID": "N7SYAN8PX8"
      },
      "expires_at": "2022-04-26T19:20:40.000Z"
    }
  }
]

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Suraj Tripathi

Merge request reports