Sha256: e835d59314fc842cbe294213650d566cbc91854f3a6dd0bb7fa16b6568882284

Contents?: true

Size: 1.8 KB

Versions: 25

Compression:

Stored size: 1.8 KB

Contents

#  Copyright 2023. Couchbase, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# frozen_string_literal: true

require "base64"

require_relative "timeouts"

module Couchbase
  module Protostellar
    # @api private
    class ConnectOptions
      attr_reader :timeouts

      def initialize(timeouts: Timeouts.new,
                     username: nil,
                     password: nil,
                     root_certificates: nil,
                     client_certificate: nil,
                     private_key: nil)
        @timeouts = timeouts
        @username = username
        @password = password
        @root_certificates = root_certificates
        @client_certificate = client_certificate
        @private_key = private_key
      end

      def grpc_credentials
        if @root_certificates
          GRPC::Core::ChannelCredentials.new(@root_certificates, @client_certificate, @private_key)
        else
          # Use default certificates
          GRPC::Core::ChannelCredentials.new(nil, @client_certificate, @private_key)
        end
      end

      def grpc_call_metadata
        if @username && @password
          {"authorization" => ["Basic #{Base64.strict_encode64("#{@username}:#{@password}")}"]}
        else
          {}
        end
      end

      def grpc_channel_args
        {}
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
couchbase-3.5.4 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.4-arm64-darwin lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.4-x86_64-darwin lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.4-x86_64-linux lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.4-x86_64-linux-musl lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.3-x86_64-linux-musl lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.3 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.3-arm64-darwin lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.3-x86_64-darwin lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.3-x86_64-linux lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.2 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.2-x86_64-linux lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.2-x86_64-darwin lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.2-x86_64-linux-musl lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.1 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.1-x86_64-linux lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.1-x86_64-darwin-20 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.1-arm64-darwin-22 lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.1-x86_64-linux-musl lib/couchbase/protostellar/connect_options.rb
couchbase-3.5.0-arm64-darwin-23 lib/couchbase/protostellar/connect_options.rb