Trim newlines of token
tuxmachine opened this issue · 1 comments
Summary
A token with additional newlines is not considered valid and results in a rather unhelpful error message: Failed to retrieve item: Get "http://onepassword-connect:8080/v1/vaults?filter=title+eq+%22engineering%22": net/http: invalid header field value for "Authorization".
Trimming newlines would resolve the problem.
This is not a bug, because headers shouldn't contain newlines, but trimming the token string would result in a better developer-experience. It's rather easy to create such an invalid token with kubectl create secret generic op-token --from-file=token=token.txt
because a lot of text editors are configured to add a trailing newline.
Use cases
Can save a few hours of debugging for anyone that doesn't follow the getting started guide exactly. In my case I integrated it into an existing Kustomize setup. Kustomize emphasises a declarative approach and loading the secret from a file is therefore not a strange approach.
Proposed solution
Please trim the token. I'd open up a PR but I'm not familiar with Go and its toolchain
Is there a workaround to accomplish this today?
Yes, remove newlines with some bash-fu
cat token.txt | tr -d "\n" > trimmed_token.txt
References & Prior Work
n/a
Hey @tuxmachine! 👋
Thank you for raising this enhancement for the SDK.
I can see this come in handy to ensure any leading or following whitespaces and newlines don't break the flow of using the token.
We've tracked this internally and keep you updated when there's progress on it. 😄