-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding functionality to switch user terminal to dom. #15892
Conversation
✅ E2E Happy path tests succeed 🎉 See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) |
E2E tests of Eclipse Che Multiuser on OCP has been successful:
|
Can one of the admins verify this patch? |
constructor(@inject(CLASSES.RequestHandler) private readonly requestHandler: RequestHandler) { | ||
} | ||
|
||
public async setTerminalToDom() { |
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.
Method implementation looks overflowed, please try to clean up method and make it more readable.
(Simplifying logic, extracting steps to the atomic private methods ...)
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.
yeah... I would actually do two changes here.
- I would change this method to be more general (something like
setTerminalType(string/enum)
so we can switch back and forth if needed. This shouldn't be a big change. - I would also prefer separation to for example two methods - this one would be handling the requests (get/post) and second one would be handling the work with json (parsing&editing the json object)
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've simplified the logic, so now I don't think we need to separate it to methods. WDYT? Can you please review it again?
581cc8f
to
1d9b28e
Compare
✅ E2E Happy path tests succeed 🎉 See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) |
E2E tests of Eclipse Che Multiuser on OCP has been successful:
|
…tion between singe/multi user approach.
❌ E2E Happy path tests failed ❗ See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) ℹ️ |
crw-ci-test |
✅ E2E Happy path tests succeed 🎉 See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) |
E2E tests of Eclipse Che Multiuser on OCP has been successful:
|
❌ E2E Happy path tests failed ❗ See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) ℹ️ |
E2E tests of Eclipse Che Multiuser on OCP has been successful:
|
014a550
to
80b66cf
Compare
✅ E2E Happy path tests succeed 🎉 See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) |
constructor(@inject(TYPES.HeaderHandler) private readonly headerHandler: IHeaderHandler) { | ||
} | ||
|
||
async get(url: string) : Promise<AxiosResponse> { |
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.
On my opinion the relativeUrl
will be more convenient here.
Because simple url
may leads to confusion,
for example if I see url
I think about full url http://www.example....
but in this case, uses relative URL.
return await axios.get(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} | ||
|
||
async post(url: string, data?: string) : Promise<AxiosResponse> { |
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.
} | ||
} | ||
|
||
async delete(url: string) : Promise<AxiosResponse> { |
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.
return await axios.delete(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} | ||
|
||
private assembleUrl(url: string) : string { |
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.
async post(url: string, data?: string) : Promise<AxiosResponse> { | ||
if ( data === undefined ) { | ||
return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders()); | ||
} else { |
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.
Redundant else
async post(url: string, data?: string): Promise<AxiosResponse> {
if (data === undefined) {
return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders());
}
return await axios.post(this.assembleUrl(url), data, await this.headerHandler.getHeaders());
}
Do you agree that it looks more clear than:
async post(url: string, data?: string) : Promise<AxiosResponse> {
if ( data === undefined ) {
return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders());
} else {
return await axios.post(this.assembleUrl(url), data, await this.headerHandler.getHeaders());
}
}
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 don't see much difference in this specific case. I understand that the form you are suggesting could be very beneficial in some other cases.
If it would be for my personal feeling, then here (and I emphasize here), the version with else
is a bit more nicer to my eyes.
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.
Here you can read an extended description of the rule I mentioned.
Of course, this is not a very serious resource, but if you want
I can find a more serious source.
https://www.geeksforgeeks.org/writing-clean-else-statements
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 would suggest to prefer If
without else
where it's possible, because it shortens possible execution paths and so makes the code easier to read and understand.
This specific case Smalltalk calls "guard clauses" https://softwareengineering.stackexchange.com/a/18459
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.
Heh... This conversation about ifs and elses is starting to be almost "decadent" :-D
Nobody is questioning, that the approach you are suggesting here and all the resources you are linking here are talking about is the right approach in general and in most of the cases, but in some specific cases writing else
statement could be "neutral" (nor good, nor bad) :-D
Anyway... To close this pointless discussion... Isn't this if
unecessary after all? Because axios.post
has data
as optional:
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
Thus we don't have to care about that at all, isn't that right?
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.
Of course, you are right, if axios can apply null data. But I am not 100% that axios handle null data in the way we expected. Should be verified I guess.
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.
Ok, I'll try that and if it handles null data correctly, I'll push this.
constructor(@inject(CLASSES.TokenHandler) private readonly tokenHandler: TokenHandler) { | ||
} | ||
async getHeaders() : Promise<AxiosRequestConfig> { | ||
let token = await this.tokenHandler.getCheBearerToken(); |
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.
According to the best practices, we should use "const" where it possible.
In this case, token
will not be changed so better to use const
instead let
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.
Also, it would be great don't forget about types, so declare the "string" type here, please.
|
||
@injectable() | ||
export class SingleUserHeaderHandler implements IHeaderHandler { | ||
async getHeaders() { |
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.
getHeaders() : Promise<AxiosRequestConfig>
?
tests/e2e/utils/TokenHandler.ts
Outdated
import { TestConstants } from '../TestConstants'; | ||
|
||
@injectable() | ||
export class TokenHandler { |
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.
It also would be great to make the TokenHandler
optional (ITokenHandler).
This will make it possible to fully manage queries with inversify and not think about rebuilding logic in the future.
Because for now, it looks like a bottleneck in the queries handling logic.
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'm not sure what you mean by this. Could you please elaborate a bit more?
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 mean that with current changes we may easily configure all parts of the RequestHandler
except token obtaining part. And I see that it may be a problem in the future. For example if we will need test "Che" with external keycloak
. And this is only one example.
In this case we will not be able to reconfigure RequestHandler
for successful queries
using inversify.
And I suggest to lay this opportunity.
Besides, it doesn't require a lot of changes, minutes on this stage may save hours or even days in the future.
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.
Hmm.. Hosted che is not using keycloak.. So the logic for obtaining active token there is completely different.
@Katka92 How did you plan to deal with that on hosted che side? Did you want to create your own implementation of IHeaderHandler
and there use your own logic (possible own class, as it's here) for token obtaining?
I wouldn't even be against having token obtaining part (what is now TokenHandler
) implemented direclty inside MultiUserHeaderHandler
.
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.
@rhopp I was for having the code from TokenHandler
directly in MultiUserHeaderHandler
, but as @Ohrimenko1988 wanted it strictly separated I created this class.
When I was creating it, I was thinking about having class (e.g. HostedCheHeaderHandler
) implementing IHeaderHandler
which will use our own token handling logic.
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.
@Ohrimenko1988 If I compare your solution to mine, we only differ in the fact, that you put "another layer" there. I didn't... just because I don't find this necessary.
Thinking about it now, I can think of only one reason to keep the mechanism of obtaining token separate - And that's if somebody would need to use the token without using CheApiRequestHandler
... Is that why you separated this into own layer? If we have good (future) use case for this, let's go with this separation. If no, I would prefer to use "simpler" approach.
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 have several different places. My variant gives us huge flexibility and the possibility to reuse all separated modules (for example "Token") in other places.
Let's agree to stop discussing about placing all to the one place, at least this approach doesn't respect SOLID principles, and I don't see any reason for intentional misconduct these principles and reducing the quality of the code.
I strongly disagree with your point that if the proposed solution resolves a specific problem we don't care about anything else. And for forwarding the best practices we need additional reasons.
Just resolve a problem don't enough for me. We should think strategically. This solution should respect the code quality, clean code principles and don't reduce tests flexibility.
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.
ok. Let's go with your variant.
I don't particularly like the (in my opinion unecessary) overengineering, but I see I don't have any strong case against (except of simplicity).
@Katka92 Can you please act on this and provide update when you have time to do so? Or should somebody else take this responsibility?
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.
@Ohrimenko1988 Could you please make a PR with your branch to mine? It will be easier for me to apply all the changes. I'll test it and commit changes here for the final review. Thank you
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.
This is not overengineering, just respecting best practices.
E2E tests of Eclipse Che Multiuser on OCP has failed:
|
@Katka92: what about storing PreferencesHandler.ts and TokenHandler.ts together with other files in the utils/requestHandlers/ directory? |
Signed-off-by: Ihor Okhrimenko <[email protected]>
✅ E2E Happy path tests succeed 🎉 See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1) |
E2E tests of Eclipse Che Multiuser on OCP has been successful:
|
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.
Looks good for me. Thank you for collaboration.
What does this PR do?
Add functionality to switch terminal to dom. This would allow us to check the text in the terminal.
What issues does this PR fix or reference?
Part of #15038