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 call to move to highest supported REST API version #100
Conversation
c93fea4
to
266bef4
Compare
response = self._session.get(self.server_address + "/auth?format=xml") | ||
info_xml = ET.fromstring(response.content) | ||
prod_version = info_xml.find('.//product_version').text | ||
version = _PRODUCT_TO_REST_VERSION.get(prod_version, '2.1') # 2.1 |
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'll make that comment not a random repetition: 2.1 is the version with permissions changes
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.
Personally, I am not sure I would include this code. The implication of adding this is that we actually test against some of these older versions, which we don't. While believe we should work with most of it, my inclination would be that if the user asks us to pick the latest version, and we can't find it (ie there is no serverInfo endpoint), we set it to 9.3. I am open to discuss, though. I am sure it is helpful, however we do need to be clear about what we actually test against.
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 could just default to 9.3's REST API version -- this was recommended by @RussTheAerialist since I think he plans to decorate versions back farther than 9.3.
I'm fine either way
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.
Overall I like it.
Now the question is: should we have a flag on the server constructor that allows users to say "use server version" upon construction? @LGraber?
except ServerInfoEndpointNotFoundError: | ||
version = self._get_legacy_version() | ||
|
||
finally: |
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 seems a bit weird. We are setting the version, determining the new version, and then resetting the old version. I think with the way this is written, we probably don't need _determine_highest_version to be it's own function. In this case, we could do something like the following pseudo-code
save old version
set version to 2.4
Try to call get rest api version
If exception, try to get legacy version
If no legacy version found, restore old value.
I'm not sure which version would be clearer to understand.
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 currently have it this way so that this function simply retrieves the highest supported version, and the caller is responsible for setting it wherever it wants to be set -- this lets us reuse the function elsewhere (I don't know a use case yet, but I don't think the premature refactor makes it harder to follow).
I'd prefer the separation, if there's a strong objection let me know and I can combine it.
I'm pro-flag that does this automatically!!! I'll let Lee weigh in and can respond accordingly
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 do not have a strong opinion either way, like I said, I wasn't sure which direction was clearer, and you make a good point about reuse.
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.
Prefer the API is set to the highest level (since that is usually what most people expect). If someone wants to fix the version - they can set the version after sign in.
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.
Why do you think if you put this in the use_highest_version() function it could not be used elsewhere? Just because it is a public function doesn't mean you can't call it from other parts of the code. Seems like we don't need two functions.
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 use_highest_version
should do just that, find and set the highest version. get highest version, or do the best guess
is something different, and I think it's cleaner to leave the setting to the caller (use_highest_version
) and the internal machinery of how it finds that version are behind a different function and could change.
As a side benefit I think it keeps the little bits with the try/excepts much easier to follow to a new reader of the code, vs jamming it all into one function that also sets it on the Server
object too
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 waffling around on the server constructor. Generally, though, I prefer constructors to do a minimal amount of work. People tend to forget to put the first set of class declarations inside of try / catch blocks for one thing. The only way I see this as useful is if we set the default to be to use the latest version. Then the constructor flag would be to unset this so that you can explicitly set a value. Let's discuss in the office. Besides that, see my comments. Thanks for adding this!
response = self._session.get(self.server_address + "/auth?format=xml") | ||
info_xml = ET.fromstring(response.content) | ||
prod_version = info_xml.find('.//product_version').text | ||
version = _PRODUCT_TO_REST_VERSION.get(prod_version, '2.1') # 2.1 |
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.
Personally, I am not sure I would include this code. The implication of adding this is that we actually test against some of these older versions, which we don't. While believe we should work with most of it, my inclination would be that if the user asks us to pick the latest version, and we can't find it (ie there is no serverInfo endpoint), we set it to 9.3. I am open to discuss, though. I am sure it is helpful, however we do need to be clear about what we actually test against.
except ServerInfoEndpointNotFoundError: | ||
version = self._get_legacy_version() | ||
|
||
finally: |
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.
Why do you think if you put this in the use_highest_version() function it could not be used elsewhere? Just because it is a public function doesn't mean you can't call it from other parts of the code. Seems like we don't need two functions.
@LGraber I don't follow your comments on the Server constructor -- I didn't change the behavior of |
I was commenting on the question of whether we should add a flag to the constructor to do this versus having them always call the method. It is not actually in your code. |
266bef4
to
3a0583a
Compare
I just rebased on top of the latest changes -- I didn't make any code changes to the PR. I think I saw these issues still open:
|
3a0583a
to
6150175
Compare
* Jekyll Dependencies * First draft of docs -- we'll improve once skeleton is in place * Does not deploy yet, need to do that in github settings page
* Jekyll Dependencies * First draft of docs -- we'll improve once skeleton is in place * Does not deploy yet, need to do that in github settings page
* Jekyll Dependencies * First draft of docs -- we'll improve once skeleton is in place * Does not deploy yet, need to do that in github settings page
Implemented during TC16 Hackathon!
Today, by default we sign in as '2.3' hard coded as our API version.
Now users can call
server.use_highest_version()
and it will negotiate the highest-supported API version for the current Server.