summaryrefslogtreecommitdiff
path: root/qa/qa/vendor/one_password/cli.rb
blob: 3cb69391783559768eebaa28a72d13e995d56a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module QA
  module Vendor
    module OnePassword
      class CLI
        def initialize
          @email = QA::Runtime::Env.gitlab_qa_1p_email
          @password = QA::Runtime::Env.gitlab_qa_1p_password
          @secret = QA::Runtime::Env.gitlab_qa_1p_secret
          @github_uuid = QA::Runtime::Env.gitlab_qa_1p_github_uuid
        end

        def otp
          `#{op_path} get totp #{@github_uuid} --session=#{session_token}`.to_i
        end

        private

        def session_token
          `echo '#{@password}' | #{op_path} signin gitlab.1password.com #{@email} #{@secret} --output=raw --shorthand=gitlab_qa`
        end

        def op_path
          File.expand_path(File.join(%W[qa vendor one_password #{os} op]))
        end

        def os
          RUBY_PLATFORM.include?("darwin") ? "darwin" : "linux"
        end
      end
    end
  end
end