From 13ab6a3842407b481ab536576f8d8517a23baa49 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Thu, 13 Jun 2019 15:37:35 +0800 Subject: Create project_aliases table --- db/migrate/20190613073003_create_project_aliases.rb | 16 ++++++++++++++++ db/schema.rb | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 db/migrate/20190613073003_create_project_aliases.rb diff --git a/db/migrate/20190613073003_create_project_aliases.rb b/db/migrate/20190613073003_create_project_aliases.rb new file mode 100644 index 00000000000..5a2c2ba0cf2 --- /dev/null +++ b/db/migrate/20190613073003_create_project_aliases.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class CreateProjectAliases < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :project_aliases do |t| + t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade }, type: :integer + t.string :name, null: false, index: { unique: true } + + t.timestamps_with_timezone null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a94e5142627..16a9f3e9c2e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2401,6 +2401,15 @@ ActiveRecord::Schema.define(version: 20190620112608) do t.string "encrypted_token_iv", null: false end + create_table "project_aliases", force: :cascade do |t| + t.integer "project_id", null: false + t.string "name", null: false + t.datetime_with_timezone "created_at", null: false + t.datetime_with_timezone "updated_at", null: false + t.index ["name"], name: "index_project_aliases_on_name", unique: true, using: :btree + t.index ["project_id"], name: "index_project_aliases_on_project_id", using: :btree + end + create_table "project_authorizations", id: false, force: :cascade do |t| t.integer "user_id", null: false t.integer "project_id", null: false @@ -3780,6 +3789,7 @@ ActiveRecord::Schema.define(version: 20190620112608) do add_foreign_key "pool_repositories", "projects", column: "source_project_id", on_delete: :nullify add_foreign_key "pool_repositories", "shards", on_delete: :restrict add_foreign_key "project_alerting_settings", "projects", on_delete: :cascade + add_foreign_key "project_aliases", "projects", on_delete: :cascade add_foreign_key "project_authorizations", "projects", on_delete: :cascade add_foreign_key "project_authorizations", "users", on_delete: :cascade add_foreign_key "project_auto_devops", "projects", on_delete: :cascade -- cgit v1.2.1 From 550ac52b143b7d4b77203b81c1b92997c4c63e34 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Thu, 13 Jun 2019 20:04:36 -0800 Subject: Add documentation for feature and API --- doc/api/project_aliases.md | 101 +++++++++++++++++++++++++++++++++++++++++++++ doc/user/project/index.md | 13 ++++++ 2 files changed, 114 insertions(+) create mode 100644 doc/api/project_aliases.md diff --git a/doc/api/project_aliases.md b/doc/api/project_aliases.md new file mode 100644 index 00000000000..4456388c74f --- /dev/null +++ b/doc/api/project_aliases.md @@ -0,0 +1,101 @@ +# Project Aliases API + +All methods require administrator authorization. + +## List all project aliases + +Get a list of all project aliases + +``` +GET /project_aliases +``` + +``` +curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/project_aliases" +``` + +Example response: + +```json +[ + { + "id": 1, + "project_id": 1, + "name": "gitlab-ce" + }, + { + "id": 2, + "project_id": 2, + "name": "gitlab-ee" + } +] +``` + +## Get project alias' details + +Get details of a project alias + +``` +GET /project_aliases/:name +``` + +| Attribute | Type | Required | Description | +|-----------|--------|----------|-----------------------| +| `name` | string | yes | The name of the alias | + +``` +curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/project_aliases/gitlab-ee" +``` + +Example response: + +```json +{ + "id": 1, + "project_id": 1, + "name": "gitlab-ee" +} +``` + +## Create an alias for a project + +Add a new alias for a project. Reponds with a 201 when successful, 400 when there are validation errors (e.g. alias already exists). + +``` +POST /project_aliases +``` + +| Attribute | Type | Required | Description | +|--------------|--------|----------|-----------------------------------------------| +| `project_id` | string | yes | The The ID or URL-encoded path of the project | +| `name` | string | yes | The name of the alias. Must be unique. | + +``` +curl --request POST "https://gitlab.example.com/api/v4/project_aliases" --form "project_id=gitlab-org%2Fgitlab-ee" --form "name=gitlab-ee" +``` + +Example response: + +```json +{ + "id": 1, + "project_id": 1, + "name": "gitlab-ee" +} +``` + +## Delete a project aliase + +Removes a project aliases. Respond with a 204 when project alias exists, 404 when it doesn't. + +``` +DELETE /project_aliases/:name +``` + +| Attribute | Type | Required | Description | +|-----------|--------|----------|-----------------------| +| `name` | string | yes | The name of the alias | + +``` +curl --request DELETE --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/project_aliases/gitlab-ee" +``` diff --git a/doc/user/project/index.md b/doc/user/project/index.md index 587b4121e4e..d9c35165ac8 100644 --- a/doc/user/project/index.md +++ b/doc/user/project/index.md @@ -193,6 +193,18 @@ password To quickly access a project from the GitLab UI using the project ID, visit the `/projects/:id` URL in your browser or other tool accessing the project. +## Project aliases + +Projects' repositories are usually cloned with a namespace and project name. It is +also possible to clone them via a project alias. This feature is only available on Git over SSH. + +A project alias can be created via API only by administrators. Follow the +[Project Aliases API documentation](../../api/project_aliases.md) for more details. + +Once an alias has been created for a project (e.g. gitlab-ce for gitlab-org/gitlab-ce), +the repository can be cloned using the alias (e.g `git clone git@gitlab.com:gitlab-ce.git` +instead of `git clone git@gitlab.com:gitlab-org/gitlab-ce.git`). + ## Project APIs There are numerous [APIs](../../api/README.md) to use with your projects: @@ -212,3 +224,4 @@ There are numerous [APIs](../../api/README.md) to use with your projects: - [Templates](../../api/project_templates.md) - [Traffic](../../api/project_statistics.md) - [Variables](../../api/project_level_variables.md) +- [Aliases](../../api/project_aliases.md) -- cgit v1.2.1 From 6aa0b173e240f7f27c2cc6d1d4c87b7688940283 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 17 Jun 2019 11:56:59 +0800 Subject: Update related documentation Update the newly added documentation to be more precise and fix the typos. Add information about Project aliases into permissions doc. --- doc/api/project_aliases.md | 20 ++++++++++++-------- doc/user/permissions.md | 5 +++++ doc/user/project/index.md | 26 ++++++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/doc/api/project_aliases.md b/doc/api/project_aliases.md index 4456388c74f..20e4e844654 100644 --- a/doc/api/project_aliases.md +++ b/doc/api/project_aliases.md @@ -1,10 +1,12 @@ -# Project Aliases API +# Project Aliases API **[PREMIUM ONLY]** + +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in GitLab 12.1. All methods require administrator authorization. ## List all project aliases -Get a list of all project aliases +Get a list of all project aliases: ``` GET /project_aliases @@ -33,7 +35,7 @@ Example response: ## Get project alias' details -Get details of a project alias +Get details of a project alias: ``` GET /project_aliases/:name @@ -57,9 +59,10 @@ Example response: } ``` -## Create an alias for a project +## Create a project alias -Add a new alias for a project. Reponds with a 201 when successful, 400 when there are validation errors (e.g. alias already exists). +Add a new alias for a project. Responds with a 201 when successful, +400 when there are validation errors (e.g. alias already exists): ``` POST /project_aliases @@ -67,7 +70,7 @@ POST /project_aliases | Attribute | Type | Required | Description | |--------------|--------|----------|-----------------------------------------------| -| `project_id` | string | yes | The The ID or URL-encoded path of the project | +| `project_id` | string | yes | The ID or URL-encoded path of the project. | | `name` | string | yes | The name of the alias. Must be unique. | ``` @@ -84,9 +87,10 @@ Example response: } ``` -## Delete a project aliase +## Delete a project alias -Removes a project aliases. Respond with a 204 when project alias exists, 404 when it doesn't. +Removes a project aliases. Responds with a 204 when project alias +exists, 404 when it doesn't: ``` DELETE /project_aliases/:name diff --git a/doc/user/permissions.md b/doc/user/permissions.md index 7af3d4a0ac3..03abef9fc62 100644 --- a/doc/user/permissions.md +++ b/doc/user/permissions.md @@ -365,3 +365,8 @@ for details about the pipelines security model. Since GitLab 8.15, LDAP user permissions can now be manually overridden by an admin user. Read through the documentation on [LDAP users permissions](../administration/auth/how_to_configure_ldap_gitlab_ee/index.html) to learn more. + +## Project aliases + +Project aliases can only be read, created and deleted by a GitLab administrator. +Read through the documentation on [Project aliases](../user/project/index.md#project-aliases-premium-only) to learn more. diff --git a/doc/user/project/index.md b/doc/user/project/index.md index d9c35165ac8..2d39fdf8154 100644 --- a/doc/user/project/index.md +++ b/doc/user/project/index.md @@ -193,17 +193,27 @@ password To quickly access a project from the GitLab UI using the project ID, visit the `/projects/:id` URL in your browser or other tool accessing the project. -## Project aliases +## Project aliases **[PREMIUM ONLY]** -Projects' repositories are usually cloned with a namespace and project name. It is -also possible to clone them via a project alias. This feature is only available on Git over SSH. +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in GitLab 12.1. -A project alias can be created via API only by administrators. Follow the -[Project Aliases API documentation](../../api/project_aliases.md) for more details. +When migrating repositories to GitLab and they are being accessed by other systems, +it's very useful to be able to access them using the same name especially when +they are a lot. It reduces the risk of changing significant number of Git URLs in +a large number of systems. -Once an alias has been created for a project (e.g. gitlab-ce for gitlab-org/gitlab-ce), -the repository can be cloned using the alias (e.g `git clone git@gitlab.com:gitlab-ce.git` -instead of `git clone git@gitlab.com:gitlab-org/gitlab-ce.git`). +GitLab provides a functionality to help with this. In GitLab, repositories are +usually accessed with a namespace and project name. It is also possible to access +them via a project alias. This feature is only available on Git over SSH. + +A project alias can be only created via API and only by GitLab administrators. +Follow the [Project Aliases API documentation](../../api/project_aliases.md) for +more details. + +Once an alias has been created for a project (e.g., an alias `gitlab-ce` for the +project `https://gitlab.com/gitlab-org/gitlab-ce`), the repository can be cloned +using the alias (e.g `git clone git@gitlab.com:gitlab-ce.git` instead of +`git clone git@gitlab.com:gitlab-org/gitlab-ce.git`). ## Project APIs -- cgit v1.2.1 From 5c3446c01b8a2648b0a83a89e4c52861f80a4fdb Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Tue, 18 Jun 2019 12:15:17 +0800 Subject: Add project_aliases to be imported/exported --- spec/lib/gitlab/import_export/all_models.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 7a250603b6b..7baa52ffb4f 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -397,6 +397,7 @@ project: - incident_management_setting - merge_trains - designs +- project_aliases award_emoji: - awardable - user -- cgit v1.2.1 From 0dc667149be84b18554342559d2612a8f3c23bb5 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Tue, 18 Jun 2019 19:52:36 +0800 Subject: Specify feature was added in GitLab Premium --- doc/api/project_aliases.md | 2 +- doc/user/project/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/project_aliases.md b/doc/api/project_aliases.md index 20e4e844654..65845579409 100644 --- a/doc/api/project_aliases.md +++ b/doc/api/project_aliases.md @@ -1,6 +1,6 @@ # Project Aliases API **[PREMIUM ONLY]** -> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in GitLab 12.1. +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.1. All methods require administrator authorization. diff --git a/doc/user/project/index.md b/doc/user/project/index.md index 2d39fdf8154..06286951e20 100644 --- a/doc/user/project/index.md +++ b/doc/user/project/index.md @@ -195,7 +195,7 @@ visit the `/projects/:id` URL in your browser or other tool accessing the projec ## Project aliases **[PREMIUM ONLY]** -> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in GitLab 12.1. +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/3264) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.1. When migrating repositories to GitLab and they are being accessed by other systems, it's very useful to be able to access them using the same name especially when -- cgit v1.2.1 From 2b4d755df14871a3b77bbfc219d6dd350dbc7667 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Thu, 27 Jun 2019 13:49:45 +0800 Subject: Add @patrickbajao as codeowner of project aliases --- .gitlab/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab/CODEOWNERS b/.gitlab/CODEOWNERS index 0ca6d7a350a..f65e62068d6 100644 --- a/.gitlab/CODEOWNERS +++ b/.gitlab/CODEOWNERS @@ -19,3 +19,5 @@ db/ @abrandl @NikolayS /lib/gitlab/ci/templates/ @nolith @zj /lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @DylanGriffith @mayra-cabrera @tkuah /lib/gitlab/ci/templates/Security/ @plafoucriere @gonzoyumo @twoodham +/ee/app/models/project_alias.rb @patrickbajao +/ee/lib/api/project_aliases.rb @patrickbajao -- cgit v1.2.1