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

--headers not working for pilet-publish #705

Closed
2 of 3 tasks
akenned8 opened this issue Jul 25, 2024 · 3 comments
Closed
2 of 3 tasks

--headers not working for pilet-publish #705

akenned8 opened this issue Jul 25, 2024 · 3 comments
Labels
invalid This doesn't seem right

Comments

@akenned8
Copy link

Bug Report

For more information, see the CONTRIBUTING guide.

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version?
  • Did you perform a search in the issues?

Environment Details and Version

Pilet version 1.5.3
Mac OS

Description

When trying to publish to my own feed service
npx pilet publish <.tgz file> --url <feed service url> --headers "{\"foo\":\"bar\"}"
The custom headers I receive are

{
  '0':'{'
  '1':'"'
  '2':'f'
  '3:'o'
  '4':'o'
  '5':'"'
  '6':':'
  '7':'"'
  '8':'b'
  '9:'a'
  '10':'r'
  '11':'"'
  '12':'}'
}

I thought I was passing in the headers in the wrong format, and perhaps I still am (an opportunity for documentation if so), but every way I tried passing the headers had this same result.

Steps to Reproduce

  1. Place a breakpoint on the feed service's /feed/update code
  2. npx pilet publish <.tgz file> --url <feed service url> --headers "{\"foo\":\"bar\"}" (repeat to try any other format for headers)
  3. observe the custom headers

Expected behavior

{
  "foo":"bar"
}

Actual behavior

{
  '0':'{'
  '1':'"'
  '2':'f'
  '3:'o'
  '4':'o'
  '5':'"'
  '6':':'
  '7':'"'
  '8':'b'
  '9:'a'
  '10':'r'
  '11':'"'
  '12':'}'
}

Possible Origin/Solution

I believe the issue stems from converting headers from type 'unknown' to type 'Record<string, string>' in commands.ts

.option('headers', undefined)

headers: args.headers as Record<string, string>,

Then this below causes the results in the faulty headers

Here is a script I used to replicate that same process of unknown -> Record<string,string> -> spread

import axios from 'axios';
import { Agent } from 'https';

async function process() {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_token_here',
  };

  var a: unknown = '{\"abc\":\"ced\"}'
  const test: Record<string, string> = a as Record<string, string>;

  console.log(a)
  console.log(test)

  const newHeaders: Record<string, string> = {
    ...test,
    ...headers,
  };

  console.log(newHeaders)

}

process();
@akenned8 akenned8 added the bug Something isn't working label Jul 25, 2024
@FlorianRappl
Copy link
Contributor

FlorianRappl commented Jul 25, 2024

I believe the issue stems from converting headers from type 'unknown' to type 'Record<string, string>' in commands.ts

This is certainly not the root cause as TS has no effect on runtime code.

Your input seems incorrect; headers as a dictionary -- see yargs (options, see for example the coerce example using options: https://github.com/yargs/yargs/blob/main/docs/api.md#coercekey-fn), e.g.,

npx pilet publish <.tgz file> --url <feed service url> --headers.foo bar

See documentation: https://docs.piral.io/tooling/publish-pilet#flags (type is options and not string!).

Hope that helps!

@FlorianRappl FlorianRappl added invalid This doesn't seem right and removed bug Something isn't working labels Jul 25, 2024
@akenned8
Copy link
Author

Ah my apologies, thanks for the quick reply Florian! Huge fan of your product btw 😃

@FlorianRappl
Copy link
Contributor

Great that it works - and thanks for the feedback!

For me this means that we need to strengthen the docs here (examples for each flag would help) and have better error handling in the CLI. Will pick that up as an improvement for 1.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants