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
Implement RtGithub Constructors For Custom Domain #1517
Comments
@amihaiemil/z please, pay attention to this issue |
@kkashi01/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot! |
I think you can do that right when you are instantiating the Request. See how its done in the constructors that we have now. I believe all you have to do is the following (for token) final Github github = new RtGithub (
new ApacheRequest("https://your.githubdomain.com")
.header(
HttpHeaders.USER_AGENT,
new FromProperties("jcabigithub.properties").format()
)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.header( //HERE, set the auth token
HttpHeaders.AUTHORIZATION,
String.format("token %s", token)
)
.through(AutoRedirectingWire.class)
); or the following for password final Github github = new RtGithub (
new ApacheRequest("https://your.githubdomain.com")
.header(
HttpHeaders.USER_AGENT,
new FromProperties("jcabigithub.properties").format()
)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.header( //HERE, set auth with username/pwd
HttpHeaders.AUTHORIZATION,
String.format(
"Basic %s",
DatatypeConverter.printBase64Binary(
String.format("%s:%s", user, pwd)
.getBytes(StandardCharsets.UTF_8)
)
)
)
.through(AutoRedirectingWire.class)
); Is it not possible to do this? Or do you think it's ugly? |
@kkashi01 On a second thought, I think we will implement a few extra constructors so you can specify a custom domain without bothering with all the configuration of a Request. But in the meantime, the above snippets of code should work fine :) |
@amihaiemil Thanks for the code-snippet. Constructor for custom domain would definitely help. [1] 406 Not Acceptable [http://github.example.com/repos/MyRepoName/propertySynchronizer/pulls?status=all] [2] [http://github.example.com/MyRepoName/propertySynchronizer/pulls?status=all] |
@kkashi01 I'm afraid changing URI paths is not possible. Github's URI paths are at the core of this library's architecture. Encapsulation and the objects' precedence/fluency all follow Github's URIs. This cannot be changed without breaking encapsulation or changing the architecture fundamentally. If you have your own Github instance deployed, my advice is to not change URIs. Changing the domain is definetely not a problem, but do not change or mask URIs. |
@amihaiemil thanks. Unfortunately I don't have control over our github and [2] above is just how the URL is set up. I do find your library very elegant and useful. Need to see how to handle this. |
@kkashi01 I think you could "highjack" the URI building logic by providing your own
But this would be very painful and error-prone. First of all, you would have to study all the classes and methods of this library to see what paths are being added and where. It would be dirty and painful, but it could work to some extent... |
#1517 added ctors for custom domains
@amihaiemil Thanks for the update. Will wait for v1.1 and give it a try. Do you think it makes sense to update Repo class to have "/repos" as default attribute and allow setting it through a constructor method? That way, all above classes ( like above) can just call a helper method on Repo to get that value (the default or the the custom one; e.g. blank): BTW. You mentioned below. Do you mean
|
Yes, this would be an option, I'll look into it tomorrow :)
This will surely not happen. Helper methods are against our principles and besides that, encapsulation would be broken. Repo would become some sort of utility class. But you are right, most classes should set their root paths (e.g. RtRepos -> /repos; RtIssues -> /issues etc) in their ctor rather than hardcoding them throughout methods.
Yes, that's actually the interface that would need decoration, but you would have to start from the top Request anyway, because that's what the constructor of RtGithub expects. |
@kkashi01 I assume the end result would be something like this: Github github = new RtGithub();
Repos repos = github.repos(); // What we have now; adds the default /repos path
Repos myRepos = github.repos("/myReposPath"); // Adds /myReposPath instead of the default /repos |
@amihaiemil getting much closer 👍 THANKS |
@kkashi01 I looked into it. Having the paths injected through the constructor is a good idea, but only for us, internally -- for instance, if Github's paths will change in the future, then it will be easier for us to do the change as well. But, to be honest with you, I don't like the idea of letting the user specify paths when calling methods such as However, I remembered we have the I hope this is ok with you. You could also fork the repo and make the changes yourself. |
Agreed and this will definitely be a good change:
I totally understand your point. However, this library will possibly have limitation that it won't work for enterprise Custom Domains unless a workaround is provided
I don't think this will be true because all your classes are modeled around Github
if Github.entry works for updating the Request, then I think this should be good and solves mine (and alike custom domain) issues
Sure. If you are refactoring to remove the hard-coding, I would wait till you are finished and then go from there and fork / update / put in PR if needed. Thanks again for quick turn-around and library -Hossein Amerkashi. |
Job |
This job is not in scope |
Thanks for quick turn-around on issue below and updating README.
Relates to: #1516
Follow-up, does it make sense to update code to a constructor that takes Request and token?
Or a way to set Token and/or userid/pwd in RtGithub? Per your suggestion, if RtGithub is instantiated with custom-domain, we won't be able to set token (or userid/pwd). Is my understanding correct?
The text was updated successfully, but these errors were encountered: