-
Notifications
You must be signed in to change notification settings - Fork 144
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
Deprecate incorrectly named API #424
Deprecate incorrectly named API #424
Conversation
- Provide new names that don't offend golint - Use new names throughout the code base - Mark the old names deprecated and redefine constants using new values
- Provide new names that don't offend golint - Use new names throughout the code base - Mark the old names deprecated and redefine constants using new values
- Provide new names that don't offend golint - Use new names throughout the code base - Mark the old names deprecated and redefine constants using new values
- Provide new names that don't offend golint - Use new names throughout the code base - Mark the old names deprecated and redefine constants using new values
This renaming is more involved that other ones. Interfaces are hard. First of all, introduce a new interface with identifiers that do not offend golint: - use "Callbacks" instead of "SessionCallbacks" to avoid stuttering when importing (it will be called "session.Callbacks" in user code) - use "GetPublicKeyID" method name instead of "GetPublicKeyId" Then update all existing code to use the new interface. Secure Session itself should call the new method, accept and store Callbacks instance. Users of Secure Session should implement the new GetPublicKeyID method. However, in order to maintain backwards compatibility we have to allow the old code to continue using the old SessionCallbacks interface with GetPublicKeyId method. We implement this using an adapter struct that translates new method calls into the old ones. Since Go does not have method overloading we have to accept an "interface {}" instance and check its type dynamically. These compatibility shims can be removed when we drop the old interface.
- Provide new name that don't offend golint - Use the new name throughout the code base - Mark the old method deprecated and reimplement it using the new one
All these dynamic checks in session.New() warrant a test which verifies that we actually can handle the old interface values and reject invalid ones. This test can be removed together with the old SessionCallbacks API.
It turns out that CGo actually does export C defines as Go constants, therefore we don't need to use intermediate variables for that. Previous code actually does not compile with Go 1.9.2 that we have on CI, but it is fine with my Go 1.12. The new code is fine in both environments.
Uh... @vixentael, @Lagovas, you know what? I've just refreshed Go Report Card for Themis with the current master that does not include this PR. It seems that we're A-OK with the current names and don't have to rename anything. I'm not really sure why. Should we proceed with this PR then? |
imho will be better to update constants according to golang conventions but leave as is callback's interface as is for now |
💯 agree with @Lagovas, let's leave callbacks as is |
Okay then. I have reverted the two commits touching the callbacks. Now we only rename the constants and that one method of Secure Session. |
PRs #422, #423 have fixed up miscellaneous golint warnings. Some of them are for incorrectly named constants and methods. This PR renames the affected identifiers into something acceptable by golint while simultaneously deprecating the old names.
We cannot remove the old names immediately due to backwards compatibility concerns. They will be actually removed in some later release, once all existing users have migrated to the new API. But for now we keep compatibility shims of various complexity to allow usage of the old API.
Summary of changes:
cell.CELL_MODE_*
constantscompare.COMPARE_*
constantskeys.KEYTYPE_*
constantssession.STATE_*
constantssession.SecureSession.GetRemoteId
methodRenaming constants is actually very easy:
This is true for methods as well.
Renamesession.SessionCallbacks
interfaceCompatibility test for old Secure Session API(Edit: these two commits were removed later during code review.)
This renaming is more involved that other ones. Interfaces are hard.
First of all, introduce a new interface with identifiers that do not offend golint:
Callbacks
instead ofSessionCallbacks
to avoid stuttering when importing (it will be calledsession.Callbacks
in user code)GetPublicKeyID
method name instead ofGetPublicKeyId
Then update all existing code to use the new interface. Secure Session itself should call the new method, accept and store
Callbacks
instance. Users of Secure Session should implement the newGetPublicKeyID
method.However, in order to maintain backwards compatibility we have to allow the old code to continue using the old
SessionCallbacks
interface withGetPublicKeyId
method. We implement this using an adapter struct that translates new method calls into the old ones. Since Go does not have method overloading we have to accept aninterface {}
instance and check its type dynamically. These compatibility shims can be removed when we drop the old interface.All these dynamic checks in
session.New()
warrant a test which verifies that we actually can handle the old interface values and reject invalid ones. This test can be removed together with the old SessionCallbacks API.