Commit 35df28bc authored by Ethan Reesor's avatar Ethan Reesor Committed by Ethan Reesor

Work on Go module proxy

- Call package authorization helpers
- Add change long entry
- Fix rubocop violations
- Add basic documentation
parent d43bff87
......@@ -13,6 +13,7 @@ The Packages feature allows GitLab to act as a repository for the following:
| [Conan Repository](../../user/packages/conan_repository/index.md) | The GitLab Conan Repository enables every project in GitLab to have its own space to store [Conan](https://conan.io/) packages. | 12.4+ |
| [Maven Repository](../../user/packages/maven_repository/index.md) | The GitLab Maven Repository enables every project in GitLab to have its own space to store [Maven](https://maven.apache.org/) packages. | 11.3+ |
| [NPM Registry](../../user/packages/npm_registry/index.md) | The GitLab NPM Registry enables every project in GitLab to have its own space to store [NPM](https://www.npmjs.com/) packages. | 11.7+ |
| [Go Proxy](../../user/packages/go_proxy/index.md) | The GitLab Go Proxy enables every project in GitLab to be fetched via the [Go proxy protocol](https://proxy.golang.org/). | ??.??+ |
Don't you see your package management system supported yet?
Please consider contributing
......
# GitLab Go Proxy **(PREMIUM)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/27376) in [GitLab Premium](https://about.gitlab.com/pricing/) ??.??.
The GitLab Go Proxy implements the Go proxy protocol.
NOTE: **Note:**
GitLab does not (yet) display Go modules in the **Packages** section of a project.
Only the Go proxy protocol is supported at this time.
## Enabling the Go proxy
NOTE: **Note:**
This option is available only if your GitLab administrator has
[enabled support for the Package Registry](../../../administration/packages/index.md). **(PREMIUM ONLY)**
After the Package Registry is enabled, it will be available for all new projects
by default. To enable it for existing projects, or if you want to disable it:
1. Navigate to your project's **Settings > General > Permissions**.
1. Find the Packages feature and enable or disable it.
1. Click on **Save changes** for the changes to take effect.
You should then be able to see the **Packages** section on the left sidebar.
# frozen_string_literal: true
class Packages::GoModule #< ApplicationRecord
class Packages::GoModule
SEMVER_TAG_REGEX = Regexp.new("^#{::Packages::GoModuleVersion::SEMVER_REGEX.source}$").freeze
# belongs_to :project
attr_reader :project, :name, :path, :versions
attr_reader :project, :name, :path
def initialize(project, name)
@project = project
......@@ -15,17 +15,17 @@ class Packages::GoModule #< ApplicationRecord
if @name == package_base
''
elsif @name.start_with?(package_base + '/')
@name[(package_base.length+1)..]
@name[(package_base.length + 1)..]
else
nil
end
end
def versions
@versions ||= project.repository.tags.
filter { |tag| SEMVER_TAG_REGEX.match?(tag.name) && !tag.dereferenced_target.nil? }.
map { |tag| ::Packages::GoModuleVersion.new self, tag }.
filter { |ver| ver.valid? }
@versions ||= project.repository.tags
.filter { |tag| SEMVER_TAG_REGEX.match?(tag.name) && !tag.dereferenced_target.nil? }
.map { |tag| ::Packages::GoModuleVersion.new self, tag }
.filter { |ver| ver.valid? }
end
def find_version(name)
......
# frozen_string_literal: true
class Packages::GoModuleVersion #< ApplicationRecord
class Packages::GoModuleVersion
SEMVER_REGEX = /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([-.A-Z0-9]+))?(?:\+([-.A-Z0-9]+))?/i.freeze
VERSION_SUFFIX_REGEX = /\/v([1-9]\d*)$/i.freeze
......
......@@ -16,4 +16,4 @@ module Packages
end
end
end
end
\ No newline at end of file
end
---
title: Implement Go module proxy MVC (package manager for Go)
merge_request: 27746
author: Ethan Reesor
type: added
......@@ -3,7 +3,9 @@ module API
class GoProxy < Grape::API
helpers ::API::Helpers::PackagesHelpers
MODULE_VERSION_REQUIREMENTS = { :module_version => ::Packages::GoModuleVersion::SEMVER_REGEX }
MODULE_VERSION_REQUIREMENTS = { module_version: ::Packages::GoModuleVersion::SEMVER_REGEX }.freeze
before { require_packages_enabled! }
helpers do
def find_module
......@@ -23,6 +25,11 @@ module API
requires :module_name, type: String, desc: 'Module name'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_read_package!
authorize_packages_feature!
end
namespace ':id/packages/go/*module_name/@v' do
desc 'Get all tagged versions for a given Go module' do
detail 'See `go help goproxy`, GET $GOPROXY/<module>/@v/list'
......@@ -41,7 +48,7 @@ module API
params do
requires :module_version, type: String, desc: 'Module version'
end
get ':module_version.info', :requirements => MODULE_VERSION_REQUIREMENTS do
get ':module_version.info', requirements: MODULE_VERSION_REQUIREMENTS do
mod = find_module
ver = mod.find_version params[:module_version]
......@@ -56,7 +63,7 @@ module API
params do
requires :module_version, type: String, desc: 'Module version'
end
get ':module_version.mod', :requirements => MODULE_VERSION_REQUIREMENTS do
get ':module_version.mod', requirements: MODULE_VERSION_REQUIREMENTS do
mod = find_module
ver = mod.find_version params[:module_version]
......@@ -72,7 +79,7 @@ module API
params do
requires :module_version, type: String, desc: 'Module version'
end
get ':module_version.zip', :requirements => MODULE_VERSION_REQUIREMENTS do
get ':module_version.zip', requirements: MODULE_VERSION_REQUIREMENTS do
mod = find_module
ver = mod.find_version params[:module_version]
......@@ -95,4 +102,4 @@ module API
end
end
end
end
\ No newline at end of file
end
# frozen_string_literal: true
module EE
module API
module Entities
class GoModuleVersion < Grape::Entity
expose :name, as: 'Version'
expose :time, as: 'Time'
end
module API
module Entities
class GoModuleVersion < Grape::Entity
expose :name, as: 'Version'
expose :time, as: 'Time'
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment