Class: Import::Offline::Exports::CreateService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/import/offline/exports/create_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_user, source_hostname, portable_params, storage_config, organization_id) ⇒ CreateService

Returns a new instance of CreateService.

Parameters:

  • current_user (User)

    current user object

  • source_hostname (String)

    source hostname or alias hostname

  • portable_params (Array<Hash>)

    list of portables to export. Each portable hash must have at least its full path. More export options for each portable may be added later. See gitlab.com/gitlab-org/gitlab/-/issues/583383 and gitlab.com/gitlab-org/gitlab/-/issues/583385. E.g.: { full_path: ‘gitlab-org/gitlab’ }

  • storage_config (Hash)

    contains object storage configuation settings: provider [Symbol], bucket [String], and credentials [Hash (content varies by provider)]. E.g.: {

    provider: :aws,
    bucket: 'import-objects',
    credentials: {
      aws_access_key_id: 'AwsUserAccessKey',
      aws_secret_access_key: 'aws/secret+access/key',
      region: 'us-east-1',
      path_style: false
    }
    

    }



28
29
30
31
32
33
34
# File 'app/services/import/offline/exports/create_service.rb', line 28

def initialize(current_user, source_hostname, portable_params, storage_config, organization_id)
  @current_user = current_user
  @source_hostname = source_hostname
  @portable_params = portable_params
  @storage_config = storage_config
  @organization_id = organization_id
end

Instance Method Details

#executeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/services/import/offline/exports/create_service.rb', line 36

def execute
  return feature_flag_disabled_error unless Feature.enabled?(:offline_transfer_exports, current_user)
  return invalid_params_error unless portable_params_valid?
  return insufficient_permissions_error unless user_can_export_all_portables?

  validate_object_storage!

  offline_export = Import::Offline::Export.create!(
    user: current_user,
    organization_id: organization_id,
    source_hostname: source_hostname,
    configuration: configuration
  )

  ServiceResponse.success(payload: offline_export)
rescue ActiveRecord::RecordInvalid => e
  service_error(e.message)
rescue Excon::Error, StandardError => e
  # Providing a nonexistent AWS S3 bucket results in a NoMethodError caused by an excon error.
  # Check if error's cause is an excon error for a more useful error to the user
  raise e unless e.is_a?(Excon::Error) || e.cause.is_a?(Excon::Error)

  # Excon errors may be long and contain sensitive information depending on provider implementation
  service_error(s_('OfflineTransfer|Unable to access object storage bucket.'))
end