Skip to content
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

Merged
merged 10 commits into from
Mar 13, 2019

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Mar 12, 2019

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_SEAL → cell.ModeSeal
  • compare.COMPARE_MATCH → compare.Match
  • keys.KEYTYPE_EC → keys.TypeEC
  • session.STATE_ESTABLISHED → session.StateEstablished
  • (*session.SecureSession) GetRemoteId → GetRemoteID

  • Rename cell.CELL_MODE_* constants
  • Rename compare.COMPARE_* constants
  • Rename keys.KEYTYPE_* constants
  • Rename session.STATE_* constants
  • Rename session.SecureSession.GetRemoteId method

Renaming constants is actually very easy:

  • 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 is true for methods as well.

  • Rename session.SessionCallbacks interface
  • Compatibility 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:

  • 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.

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.

- 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.
@ilammy ilammy added W-GoThemis 🐹 Wrapper: GoThemis, Go API compatibility Backward and forward compatibility, platform interoperability issues, breaking changes labels Mar 12, 2019
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.
@ilammy
Copy link
Collaborator Author

ilammy commented Mar 12, 2019

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?

@Lagovas
Copy link
Collaborator

Lagovas commented Mar 12, 2019

imho will be better to update constants according to golang conventions but leave as is callback's interface as is for now

@vixentael
Copy link
Contributor

💯 agree with @Lagovas, let's leave callbacks as is

@ilammy
Copy link
Collaborator Author

ilammy commented Mar 12, 2019

Okay then. I have reverted the two commits touching the callbacks. Now we only rename the constants and that one method of Secure Session.

@ilammy ilammy merged commit 419d5a3 into cossacklabs:master Mar 13, 2019
@ilammy ilammy deleted the deprecate-gothemis-api-0.11 branch July 26, 2019 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Backward and forward compatibility, platform interoperability issues, breaking changes W-GoThemis 🐹 Wrapper: GoThemis, Go API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants