summaryrefslogtreecommitdiff
path: root/lib/api/internal.rb
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-05-19 12:58:45 -0700
committerMichael Kozono <mkozono@gmail.com>2017-06-05 05:32:26 -0700
commit23d37382dabe3f7c7f2e11df2731de8e939e0cab (patch)
treec0730c393fef5582dfdfdbbd41ad8340a5c5cd45 /lib/api/internal.rb
parent957edb13fdb21e21efbc68fc342209f4b53a66e4 (diff)
downloadgitlab-ce-23d37382dabe3f7c7f2e11df2731de8e939e0cab.tar.gz
Refactor to let GitAccess errors bubble up
No external behavior change. This allows `GitHttpController` to set the HTTP status based on the type of error. Alternatively, we could have added an attribute to GitAccessStatus, but this pattern seemed appropriate.
Diffstat (limited to 'lib/api/internal.rb')
-rw-r--r--lib/api/internal.rb38
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 9ebd4841296..3d60d1da114 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -32,29 +32,31 @@ module API
actor.update_last_used_at if actor.is_a?(Key)
- access_checker = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
- access_status = access_checker
+ access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
+ access_checker = access_checker_klass
.new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities)
- .check(params[:action], params[:changes])
- response = { status: access_status.status, message: access_status.message }
+ begin
+ access_status = access_checker.check(params[:action], params[:changes])
+ response = { status: access_status.status, message: access_status.message }
+ rescue Gitlab::GitAccess::UnauthorizedError, Gitlab::GitAccess::NotFoundError => e
+ return { status: false, message: e.message }
+ end
- if access_status.status
- log_user_activity(actor)
+ log_user_activity(actor)
- # Project id to pass between components that don't share/don't have
- # access to the same filesystem mounts
- response[:gl_repository] = Gitlab::GlRepository.gl_repository(project, wiki?)
+ # Project id to pass between components that don't share/don't have
+ # access to the same filesystem mounts
+ response[:gl_repository] = Gitlab::GlRepository.gl_repository(project, wiki?)
- # Return the repository full path so that gitlab-shell has it when
- # handling ssh commands
- response[:repository_path] =
- if wiki?
- project.wiki.repository.path_to_repo
- else
- project.repository.path_to_repo
- end
- end
+ # Return the repository full path so that gitlab-shell has it when
+ # handling ssh commands
+ response[:repository_path] =
+ if wiki?
+ project.wiki.repository.path_to_repo
+ else
+ project.repository.path_to_repo
+ end
response
end