about method scope in the required package

greetings,

One of the package (giving name Foo) I am using has required SSL::OpenSSL.
But I want to access a special option from SSL::OpenSSL in my package.
(for instance, ssl_verify_hostname: false, is the option provided by
SSL::OpenSSL).

How can I access this option and make package Foo influneced by this option?

Thank you.

Hello,

> I want to access a special option from SSL::OpenSSL in my package.
(for instance, ssl_verify_hostname: false, is the option provided by
SSL::OpenSSL).

   Sorry - not really sure what you are asking. Maybe you can post a
code snippet of what are your trying to do.

  Anyways, I coded a little wrapper library / gem using OpenSSL
"under the hood" last year called
elliptic with the tagline elliptic curve digital signature algorithm
(ECDSA) cryptography with OpenSSL made easy (incl. secp256k1 curve).
  You might browse the ruby script code [1] and see if that helps and
answers your question and learn by studying (real-world) examples.

  Cheers.

[1] blockchain/elliptic.rb at master · rubycoco/blockchain · GitHub

As I understand, you want to only make the option affect your library, while not affecting anything else. I would suggest the following pattern:

module Foo
def self.with_openssl(&block)
old_value = SSL::OpenSSL.ssl_verify_hostname
SSL::OpenSSL.ssl_verify_hostname = false
ret = yield
SSL::OpenSSL.ssl_verify_hostname = old_value
ret
end

def do_something
Foo.with_openssl do
execute_some_network_request
end
end
end

Do note this won't be threadsafe.

···

On 7/30/22 10:30, pengyh wrote:

greetings,

One of the package (giving name Foo) I am using has required SSL::OpenSSL.
But I want to access a special option from SSL::OpenSSL in my package.
(for instance, ssl_verify_hostname: false, is the option provided by
SSL::OpenSSL).

How can I access this option and make package Foo influneced by this option?

Thank you.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hello,

The real life case is I am using ruby-kafka library for accessing to kafka.

however I want to setup "ssl_verify_hostname: false" in SSL::OpenSSL
which is required by ruby-kafka.

if ruby-kafka doesn't provide this option directly, how can I setup it
in SSL::OpenSSL?

Thanks.

···

As I understand, you want to only make the option affect your library,
while not affecting anything else. I would suggest the following pattern:

My suggestion would be to fork ruby-kafka to add that feature, then issue a pull request. While the pull request isn't accepted yet, you can just refer to your fork in your Gemfile:

gem "ruby-kafka", git: "https://github.com/your-username/ruby-kafka&quot;

···

On 7/30/22 14:11, pengyh wrote:

Hello,

The real life case is I am using ruby-kafka library for accessing to kafka.

however I want to setup "ssl_verify_hostname: false" in SSL::OpenSSL
which is required by ruby-kafka.

if ruby-kafka doesn't provide this option directly, how can I setup it
in SSL::OpenSSL?

Thanks.

As I understand, you want to only make the option affect your library,
while not affecting anything else. I would suggest the following pattern:

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Does this not work?

  Kafka.new(ssl_verify_hostname: false)

    # @param ssl_verify_hostname [Boolean, true] whether to verify that
    # the host serving the SSL certificate and the signing chain of the
    # certificate have the correct domains based on the CA certificate

···

On 7/30/22, pengyh <pengyh@web.de> wrote:

The real life case is I am using ruby-kafka library for accessing to kafka.
however I want to setup "ssl_verify_hostname: false" in SSL::OpenSSL
which is required by ruby-kafka.

The new version does have. but for other special cases I am using the
older version who didn't have this option.

Thanks

···

  Kafka.new(ssl_verify_hostname: false)

What version are you using? The v1.1 and v1.2 README list the param as
just "verify_hostname" rather than "ssl_verify_hostname".

The v1.0 README does not list the param.

···

On 7/31/22, pengyh <pengyh@web.de> wrote:

The new version does have. but for other special cases I am using the
older version who didn't have this option.

  Kafka.new(ssl_verify_hostname: false)

for this case how can I enable that option? if it can't be setup in
ruby-kafka which is used by current program.

Thanks

···

The v1.0 README does not list the param.

Upon further review, the option was added in v0.7.8 just not mentioned in the README until v1.1.

One option would be as hmdne suggested to fork the upstream repo, set the option in your copy, and point your Gemfile at your git repo. (Long-term it would be better if you can address the issues that are keeping you on the old version.)

Here the option was added:

···

On August 1, 2022 2:34:00 AM UTC, pengyh <pengyh@web.de> wrote:

for this case how can I enable that option? if it can't be setup in
ruby-kafka which is used by current program.

The v1.0 README does not list the param.

Thank you.

ruby-kafka is a absolutate great library who helps us a lot
but we were using the very old kafka version, so I have to deal with the
lower version of ruby-kafka.

Regards

···

One option would be as hmdne suggested to fork the upstream repo, set the option in your copy, and point your Gemfile at your git repo. (Long-term it would be better if you can address the issues that are keeping you on the old version.)