Class: Packages::Debian::GenerateDistributionKeyService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/debian/generate_distribution_key_service.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(params: {}) ⇒ GenerateDistributionKeyService

Returns a new instance of GenerateDistributionKeyService.


8
9
10
# File 'app/services/packages/debian/generate_distribution_key_service.rb', line 8

def initialize(params: {})
  @params = params
end

Instance Method Details

#executeObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/packages/debian/generate_distribution_key_service.rb', line 12

def execute
  using_pinentry do |ctx|
    # Generate key
    ctx.generate_key generate_key_params

    key = ctx.keys.first # rubocop:disable Gitlab/KeysFirstAndValuesFirst
    fingerprint = key.fingerprint

    # Export private key
    data = GPGME::Data.new
    ctx.export_keys fingerprint, data, GPGME::EXPORT_MODE_SECRET
    data.seek 0
    private_key = data.read

    # Export public key
    data = GPGME::Data.new
    ctx.export_keys fingerprint, data
    data.seek 0
    public_key = data.read

    {
      private_key: private_key,
      public_key: public_key,
      passphrase: passphrase,
      fingerprint: fingerprint
    }
  end
end