-
Notifications
You must be signed in to change notification settings - Fork 502
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
Collect HTTP Headers from Coursier for authentication #2533
Conversation
db79b9d
to
251b1f1
Compare
Codecov Report
@@ Coverage Diff @@
## main #2533 +/- ##
==========================================
- Coverage 81.32% 80.65% -0.68%
==========================================
Files 146 146
Lines 2592 2621 +29
Branches 43 45 +2
==========================================
+ Hits 2108 2114 +6
- Misses 484 507 +23
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of minor details that could be discussed (e.g., the usage of Option[List[Header]]
vs List[Header]
, and the way headers are serialized in JSON — I would just write ["foo", "bar"]
instead of { "key": "foo", "value": "bar" }
), but overall it looks correct to me, and it would unblock all the people that use a gitlab package registry!
251b1f1
to
31205be
Compare
Thanks for having a look. I replaced the |
May I kindly request a review from the maintainers? |
} else { | ||
Some( | ||
new Authentication( | ||
credentials.fold("")(_.user), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q) Does ""
for user
works ?
If not, error message like "Authentication error: missing user name" might help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that what's Coursier also does internally when just specifying headers. See: https://github.com/coursier/coursier/blob/2cb552ea934a100f52ce79f94278304c90d808a4/modules/util/shared/src/main/scala/coursier/core/Authentication.scala#L88
modules/core/src/test/scala/org/scalasteward/core/update/PruningAlgTest.scala
Show resolved
Hide resolved
31205be
to
d63d865
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Great job!!
I will wait other maintainers for a week.
@markvandertol, could u also update the gitlab docs on how we can use this new feature? |
d63d865
to
62de957
Compare
@cipriansofronia I've added a few lines explaining how to authenticate against a Gitlab repository. Does this clarify enough how it works? No specific code for Scala Steward is needed. |
docs/running.md
Outdated
Scala Steward is compatible with Coursier authentication using headers. To authenticate | ||
using the [Gitlab CI/CD job token](https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html), while also supporting your own private token when performing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
62de957
to
2fd7178
Compare
Looking forward to this one being released, thanks a lot @markvandertol |
@fthomas can this PR get some ❤️ from you? 😇 |
Is there anything preventing this PR from being merged? 🙂 |
@fthomas Do you have a time to test this with your test Steward instance ?? |
csrConfiguration.value.authenticationByRepositoryId.toList | ||
if repositoryId == name | ||
(headerKey, headerValue) <- authentication.headers | ||
} yield Resolver.Header(headerKey, headerValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should not only take the headers from the csrConfiguration
but also username and password.
Setting these via csrConfiguration
is not wrong. And I would prefer csrConfiguration
over credentials
if present, since it is more specific/explicit.
Funny enough, I did not see this pr and coded it myself that way. Maybe you can have a look :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot the @markvandertol :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to merge as-is since markvandertol seems busy now.
@987Nabil You can submit a PR for that change 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not replying to this earlier. It indeed looks more consistent, but I'm not entirely sure how large of a breaking change would be, e.g. for people who disabled coursier in their projects. Retrieving the credentials old way, but looking for headers in csrConfiguration
shouldn't be breaking, so I propose to do that in a different PR so the impact can better be assessed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this in another PR for sure. But I think, deactivating coursier and then relying on csrConfiguration
where csr = coursier and the description in sbt also explicitly mentions coursier, seems to be odd.
👋 is there anything holding up the merge at this point? |
I am wondering that to. This would really be a good thing to have when managing dependencies in private gilab repos |
It is not only gitlb. Also Google Cloud Storage or Artifactregistry or managing packages in AWS need this feature. |
@markvandertol Sorry for waiting so long. Could you resolve the conflict? 🙇 |
2fd7178
to
c806d3b
Compare
No worries. I resolved the merge conflict. 🙂 |
Thanks Mark for this PR! It looks promising. Any chance to have it merged some time soon? |
Having the fields optional allows to read in persisted
Another alternative would be to bump the version of the Other than that, this PR looks good to me. |
c806d3b
to
ffd36e5
Compare
Thanks @fthomas for having a look at the PR. I fixed the issue by using a default value of @annotation.nowarn("cat=unused-locals")
implicit val resolverCodec: Codec[Resolver] = {
implicit val customConfig: Configuration = Configuration.default.withDefaults
deriveConfiguredCodec
} I had to suppress the warning, as the implicit is only used by a macro. I could also have used the compiler flag |
Sorry for the late response. |
Any chance this can get shipped in a new release? 😃 🙏 thanks! |
Just noticed that this change broke |
This PR lets Scala Steward also pick up custom headers used for authentication. This is for example needed for Gitlab. I think looking at
csrConfiguration.value.authenticationByRepositoryId
is the cleanest and most generic way to achieve this.Example snippet of a .sbt file from a project that sets a custom HTTP-header for authentication with Coursier:
It works for SBT and Mill, but doesn't work for Maven