Closed svenXY closed 2 years ago
@svenXY Hi
thank you for this contribution. Maybe I would rather have the approach of a static method in ClodfoundryClient named build_from_cf_config
that read the file, the token, instanciate the client according to the info, init it with the read values and return it once built.
What do you thnk of it?
I followed the way you implemented it. In all of your use cases you first call the class constructor with an endpoint as the first required argument and then a login method.
I agree that passing a string instead of an endpoint is sub optimal but at least it still follows the general pattern...
But if you insist on using the static method I can come up with some code until tomorrow - even if I still think that it changes the patterns.
I agrree it changes the pattern; otherwise it introduce an unclear implementation
From what I see, you could follow the same pattern by
What do you think of it?
Ok. Sounds like a compromise. I'll see what I can come up with
Good morning @antechrestos,
thinking about this again, I'm still not sure if this is the right way to do it.
Your proposed solution would mean that
That sounds so wrong to me... I cannot see where this makes the implementation any clearer. Besides, it forces the developer to provide data (endpoint) again even though it is already there.
The problem imho is really that CloudFoundryClient.__init__()
already expects the endpoint as a required argument to be able to call _get_info() on it. You could change the constructor and make target_endpoint an optional argument. Then, when no endpoint is provided, the constructor could already try to parse an endpoint from a config file (with an optional path argument for non-default config locations).
That would make the implementation clear again: either provide an endpoint - but then really use the one provided - or don't provide one - then use the one from config file.
The drawback here would be that the constructor of your main entry point would change, but maybe this can be implemented downward-compatible.
I would either prefer that or - sigh - use the static method you proposed from the beginning, even if it breaks the pattern. In the end it is not me who gets questions and issues...
OK, I tried making target_endpoint optional and the tests succeed with no changes at all. Now - me at least - I like the implementation as it is now. What do you think?
@svenXY good morning.
The things I was not clear enough; the client has the responsibility to provide an agnostic implementation reflecting the way the api is made ie
There is a provided implementation for shell use provided yet this is not the main aim of the library: this library shall be agnostic of the use and allow developper to use it in a python backend , robotframework tests (my first use case).
This contribution brings the following thing: it breaks the agnostism and link the python library with a cli tool. That is why I though a static method (or a method in the package or elsewhere) could do the trick. Because, behing honest, this is not a feature this is just a helper...
That is why in a functional point of view this need is to build a client based on info provided in a file ie
Where does making target_endpoint optional harm this?
Hi @antechrestos, I opened #175 which implements the staticmethod you proposed as an alternative
I gusss this one should be closed
Implements parts of #172:
client.init_with_cf_config() will read a config file generated with
cf login
and use endpoint and token from thereThe problem was that the constructor for CloudFoundryClient already expects the endpoint and uses the endpoint to retrieve further information. Therefore, the constructor already needs to know that it needs to parse the file to get the endpoint.