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

Rationalise TLSConfiguration construction. #299

Merged
merged 2 commits into from
May 14, 2021

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented May 13, 2021

Motivation:

Currently whenever we add new config to TLSConfiguration, we add a new
static factory function that needs to provide the field. This is because
we currently allow configuration primarily by way of initializers. This
is increasingly not scaling, leading to a proliferation of almost
identical static factory functions.

We can replace this proliferation by having only "default" constructions
that default basically everything, and then having users use
getters/setters to initialize things. This also works well when we have
multiple ways of interacting with config, e.g. with the various cipher
suite operations.

Modifications:

  • Deprecate all existing factory functions.
  • Replace with two: forClient() and
    forServer(certificateChain:privateKey:). These configure only the
    mandatory things for each mode.
  • Replace all uses of the deprecated initializers with the new ones,
    configuring fields manually as needed.

Result:

More consistent configuration objects.

@Lukasa Lukasa added the semver/minor Adds new public API. label May 13, 2021
/// contexts, you should use `forServer` instead.
///
/// For customising fields, modify the returned TLSConfiguration object.
public static func forClient() -> TLSConfiguration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm okay with .forClient/Server but we should consciously decide that we're not sticking to the "Begin names of factory methods with “make”, e.g. x.makeIterator()." Swift naming guideline here.

Other options could be:

  • (TLSConfiguration).makeClientTLSConfiguration()
  • (TLSConfiguration).makeClientConfiguration()

Sadly, we can't really go for inits here because the client constructor doesn't have arguments so there's no where to stick the word "client".

/// Create a TLS configuration for use with server-side contexts. This allows setting the `NIOTLSCipher` property specifically.
///
/// This provides sensible defaults while requiring that you provide any data that is necessary
/// for server-side function. For client use, try `forClient` instead.
@available(*, deprecated, renamed: "TLSConfiguration.forServer(certificateChain:privateKey:)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right (and elsewhere)? I think we want just "forServer(certificateChain:privateKey:)" here otherwise Xcode shoves in the TLSConfiguration as well when you apply the fix its.

@Lukasa Lukasa requested review from glbrntt and weissi May 13, 2021 12:59
@Lukasa Lukasa force-pushed the cb-new-config-init branch 2 times, most recently from 865fbf3 to 3ed9d64 Compare May 13, 2021 13:09
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the CI turns green

Motivation:

Currently whenever we add new config to TLSConfiguration, we add a new
static factory function that needs to provide the field. This is because
we currently allow configuration primarily by way of initializers. This
is increasingly not scaling, leading to a proliferation of almost
identical static factory functions.

We can replace this proliferation by having only "default" constructions
that default basically everything, and then having users use
getters/setters to initialize things. This also works well when we have
multiple ways of interacting with config, e.g. with the various cipher
suite operations.

Modifications:

- Deprecate all existing factory functions.
- Replace with two: forClient() and
  forServer(certificateChain:privateKey:). These configure only the
  mandatory things for each mode.
- Replace all uses of the deprecated initializers with the new ones,
  configuring fields manually as needed.

Result:

More consistent configuration objects.
Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a very sensible change!

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this looks great to me!

@Lukasa
Copy link
Contributor Author

Lukasa commented May 13, 2021

@swift-nio-bot test this please

Co-authored-by: Fabian Fett <fabianfett@apple.com>
@Lukasa
Copy link
Contributor Author

Lukasa commented May 13, 2021

@swift-nio-bot test this please

2 similar comments
@Lukasa
Copy link
Contributor Author

Lukasa commented May 13, 2021

@swift-nio-bot test this please

@Lukasa
Copy link
Contributor Author

Lukasa commented May 13, 2021

@swift-nio-bot test this please

@Lukasa Lukasa merged commit 9c457d0 into apple:main May 14, 2021
@Lukasa Lukasa deleted the cb-new-config-init branch May 14, 2021 07:52
mackoj added a commit to mackoj/APNSwift that referenced this pull request Sep 16, 2021
Since you use `.makeClientConfiguration()` and it has been introduce in PR apple/swift-nio-ssl#299 please update your base requirement of `swift-nio-ssl`.
Please consider release a point update.

Thanks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants