Class: Packages::Nuget::CreateOrUpdatePackageService
- Inherits:
-
CreatePackageService
- Object
- BaseService
- CreatePackageService
- Packages::Nuget::CreateOrUpdatePackageService
- Includes:
- ExclusiveLeaseGuard, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/packages/nuget/create_or_update_package_service.rb
Constant Summary collapse
- DEFAULT_LEASE_TIMEOUT =
used by ExclusiveLeaseGuard
1.hour.to_i.freeze
- DUPLICATE_ERROR =
ServiceResponse.error( message: 'A package with the same name and version already exists', reason: :conflict ).freeze
- LEASE_TAKEN_ERROR =
ServiceResponse.error( message: 'Failed to obtain a lock. Please try again.', reason: :conflict ).freeze
- UNAUTHORIZED_ERROR =
ServiceResponse.error(message: 'Unauthorized', reason: :unauthorized).freeze
Constants inherited from CreatePackageService
CreatePackageService::ERROR_RESPONSE_PACKAGE_PROTECTED
Constants inherited from BaseService
BaseService::UnauthorizedError
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
Methods included from ExclusiveLeaseGuard
#exclusive_lease, #lease_release?, #lease_taken_log_level, #lease_taken_message, #log_lease_taken, #release_lease, #renew_lease!, #try_obtain_lease
Methods inherited from BaseService
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#execute ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/packages/nuget/create_or_update_package_service.rb', line 24 def execute return UNAUTHORIZED_ERROR unless can?(current_user, :create_package, project) return DUPLICATE_ERROR unless ::Namespace::PackageSetting.duplicates_allowed?(existing_package) if package_protected?(package_name: [:package_name], package_type: :nuget) return ERROR_RESPONSE_PACKAGE_PROTECTED end package = try_obtain_lease { process_package } return LEASE_TAKEN_ERROR unless package ServiceResponse.success(payload: { package: }) rescue ActiveRecord::RecordInvalid => e ServiceResponse.error(message: e., reason: :bad_request) end |