Class: Import::ValidateRemoteGitEndpointService

Inherits:
Object
  • Object
show all
Defined in:
app/services/import/validate_remote_git_endpoint_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ValidateRemoteGitEndpointService



7
8
9
10
11
12
# File 'app/services/import/validate_remote_git_endpoint_service.rb', line 7

def initialize(params)
  @params = params
  @uri = Gitlab::Utils.parse_url(@params[:url])
  @user = @params[:user].presence
  @password = @params[:password].presence
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'app/services/import/validate_remote_git_endpoint_service.rb', line 5

def password
  @password
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'app/services/import/validate_remote_git_endpoint_service.rb', line 5

def uri
  @uri
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/services/import/validate_remote_git_endpoint_service.rb', line 5

def user
  @user
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/import/validate_remote_git_endpoint_service.rb', line 14

def execute
  if uri && uri.hostname && Project::VALID_IMPORT_PROTOCOLS.include?(uri.scheme)
    ensure_auth_credentials!

    return ServiceResponse.success if Gitlab::GitalyClient::RemoteService.exists?(uri.to_s) # rubocop: disable CodeReuse/ActiveRecord -- false positive
  end

  failure_response
rescue GRPC::BadStatus
  # There are a several subclasses of GRPC::BadStatus, but in our case the
  # scenario we're interested in the presence of a valid, accessible
  # repository, so this treats them all as equivalent.
  failure_response
end