Commit c1d6d65e authored by Petar Prokic's avatar Petar Prokic Committed by Douglas Barbosa Alexandre

Add optional expires_at param to Users API endpoint Add SSH key

parent a45b8ff8
...@@ -71,7 +71,7 @@ GET /users ...@@ -71,7 +71,7 @@ GET /users
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ------------ | ------ | -------- | ----------- | | ------------------ | ------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| `order_by` | string | no | Return users ordered by `id`, `name`, `username`, `created_at`, or `updated_at` fields. Default is `id` | | `order_by` | string | no | Return users ordered by `id`, `name`, `username`, `created_at`, or `updated_at` fields. Default is `id` |
| `sort` | string | no | Return users sorted in `asc` or `desc` order. Default is `desc` | | `sort` | string | no | Return users sorted in `asc` or `desc` order. Default is `desc` |
| `two_factor` | string | no | Filter users by Two-factor authentication. Filter values are `enabled` or `disabled`. By default it returns all users | | `two_factor` | string | no | Filter users by Two-factor authentication. Filter values are `enabled` or `disabled`. By default it returns all users |
...@@ -375,7 +375,7 @@ POST /users ...@@ -375,7 +375,7 @@ POST /users
Parameters: Parameters:
| Attribute | Required | Description | | Attribute | Required | Description |
|:-------------------------------------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------| | :----------------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `admin` | No | User is admin - true or false (default) | | `admin` | No | User is admin - true or false (default) |
| `avatar` | No | Image file for user's avatar | | `avatar` | No | Image file for user's avatar |
| `bio` | No | User's biography | | `bio` | No | User's biography |
...@@ -417,7 +417,7 @@ PUT /users/:id ...@@ -417,7 +417,7 @@ PUT /users/:id
Parameters: Parameters:
| Attribute | Required | Description | | Attribute | Required | Description |
|:-------------------------------------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------| | :----------------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `admin` | No | User is admin - true or false (default) | | `admin` | No | User is admin - true or false (default) |
| `avatar` | No | Image file for user's avatar | | `avatar` | No | Image file for user's avatar |
| `bio` | No | User's biography | | `bio` | No | User's biography |
...@@ -610,7 +610,7 @@ GET /users/:id_or_username/status ...@@ -610,7 +610,7 @@ GET /users/:id_or_username/status
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ---------------- | ------ | -------- | ----------- | | ---------------- | ------ | -------- | ------------------------------------------------- |
| `id_or_username` | string | yes | The ID or username of the user to get a status of | | `id_or_username` | string | yes | The ID or username of the user to get a status of |
```shell ```shell
...@@ -636,8 +636,8 @@ PUT /user/status ...@@ -636,8 +636,8 @@ PUT /user/status
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------ | -------- | ----------- | | --------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `emoji` | string | no | The name of the emoji to use as status, if omitted `speech_balloon` is used. Emoji name can be one of the specified names in the [Gemojione index](https://github.com/bonusly/gemojione/blob/master/config/index.json). | | `emoji` | string | no | The name of the emoji to use as status. If omitted `speech_balloon` is used. Emoji name can be one of the specified names in the [Gemojione index](https://github.com/bonusly/gemojione/blob/master/config/index.json). |
| `message` | string | no | The message to set as a status. It can also contain emoji codes. | | `message` | string | no | The message to set as a status. It can also contain emoji codes. |
When both parameters `emoji` and `message` are empty, the status will be cleared. When both parameters `emoji` and `message` are empty, the status will be cleared.
...@@ -661,7 +661,7 @@ Example responses ...@@ -661,7 +661,7 @@ Example responses
Get the counts (same as in top right menu) of the currently signed in user. Get the counts (same as in top right menu) of the currently signed in user.
| Attribute | Type | Description | | Attribute | Type | Description |
| --------- | ---- | ----------- | | ---------------- | ------ | ------------------------------------------------------------ |
| `merge_requests` | number | Merge requests that are active and assigned to current user. | | `merge_requests` | number | Merge requests that are active and assigned to current user. |
```plaintext ```plaintext
...@@ -722,7 +722,7 @@ GET /users/:id_or_username/keys ...@@ -722,7 +722,7 @@ GET /users/:id_or_username/keys
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ---------------- | ------ | -------- | ----------- | | ---------------- | ------ | -------- | ------------------------------------------------------- |
| `id_or_username` | string | yes | The ID or username of the user to get the SSH keys for. | | `id_or_username` | string | yes | The ID or username of the user to get the SSH keys for. |
## Single SSH key ## Single SSH key
...@@ -758,13 +758,13 @@ Parameters: ...@@ -758,13 +758,13 @@ Parameters:
- `title` (required) - new SSH Key's title - `title` (required) - new SSH Key's title
- `key` (required) - new SSH key - `key` (required) - new SSH key
- `expires_at` (optional) - The expiration date of the SSH key in ISO 8601 format (`YYYY-MM-DDTHH:MM:SSZ`)
```json ```json
{ {
"created_at": "2015-01-21T17:44:33.512Z",
"key": "ssh-dss AAAAB3NzaC1kc3MAAACBAMLrhYgI3atfrSD6KDas1b/3n6R/HP+bLaHHX6oh+L1vg31mdUqK0Ac/NjZoQunavoyzqdPYhFz9zzOezCrZKjuJDS3NRK9rspvjgM0xYR4d47oNZbdZbwkI4cTv/gcMlquRy0OvpfIvJtjtaJWMwTLtM5VhRusRuUlpH99UUVeXAAAAFQCVyX+92hBEjInEKL0v13c/egDCTQAAAIEAvFdWGq0ccOPbw4f/F8LpZqvWDydAcpXHV3thwb7WkFfppvm4SZte0zds1FJ+Hr8Xzzc5zMHe6J4Nlay/rP4ewmIW7iFKNBEYb/yWa+ceLrs+TfR672TaAgO6o7iSRofEq5YLdwgrwkMmIawa21FrZ2D9SPao/IwvENzk/xcHu7YAAACAQFXQH6HQnxOrw4dqf0NqeKy1tfIPxYYUZhPJfo9O0AmBW2S36pD2l14kS89fvz6Y1g8gN/FwFnRncMzlLY/hX70FSc/3hKBSbH6C6j8hwlgFKfizav21eS358JJz93leOakJZnGb8XlWvz1UJbwCsnR2VEY8Dz90uIk1l/UqHkA= loic@call",
"title": "ABC", "title": "ABC",
"id": 4 "key": "ssh-dss AAAAB3NzaC1kc3MAAACBAMLrhYgI3atfrSD6KDas1b/3n6R/HP+bLaHHX6oh+L1vg31mdUqK0Ac/NjZoQunavoyzqdPYhFz9zzOezCrZKjuJDS3NRK9rspvjgM0xYR4d47oNZbdZbwkI4cTv/gcMlquRy0OvpfIvJtjtaJWMwTLtM5VhRusRuUlpH99UUVeXAAAAFQCVyX+92hBEjInEKL0v13c/egDCTQAAAIEAvFdWGq0ccOPbw4f/F8LpZqvWDydAcpXHV3thwb7WkFfppvm4SZte0zds1FJ+Hr8Xzzc5zMHe6J4Nlay/rP4ewmIW7iFKNBEYb/yWa+ceLrs+TfR672TaAgO6o7iSRofEq5YLdwgrwkMmIawa21FrZ2D9SPao/IwvENzk/xcHu7YAAACAQFXQH6HQnxOrw4dqf0NqeKy1tfIPxYYUZhPJfo9O0AmBW2S36pD2l14kS89fvz6Y1g8gN/FwFnRncMzlLY/hX70FSc/3hKBSbH6C6j8hwlgFKfizav21eS358JJz93leOakJZnGb8XlWvz1UJbwCsnR2VEY8Dz90uIk1l/UqHkA= loic@call",
"expires_at": "2016-01-21T00:00:00.000Z"
} }
``` ```
...@@ -797,6 +797,7 @@ Parameters: ...@@ -797,6 +797,7 @@ Parameters:
- `id` (required) - ID of specified user - `id` (required) - ID of specified user
- `title` (required) - new SSH Key's title - `title` (required) - new SSH Key's title
- `key` (required) - new SSH key - `key` (required) - new SSH key
- `expires_at` (optional) - The expiration date of the SSH key in ISO 8601 format (`YYYY-MM-DDTHH:MM:SSZ`)
## Delete SSH key for current user ## Delete SSH key for current user
...@@ -859,7 +860,7 @@ GET /user/gpg_keys/:key_id ...@@ -859,7 +860,7 @@ GET /user/gpg_keys/:key_id
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `key_id` | integer | yes | The ID of the GPG key | | `key_id` | integer | yes | The ID of the GPG key |
```shell ```shell
...@@ -887,7 +888,7 @@ POST /user/gpg_keys ...@@ -887,7 +888,7 @@ POST /user/gpg_keys
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------ | -------- | ----------- | | --------- | ------ | -------- | --------------- |
| key | string | yes | The new GPG key | | key | string | yes | The new GPG key |
```shell ```shell
...@@ -917,7 +918,7 @@ DELETE /user/gpg_keys/:key_id ...@@ -917,7 +918,7 @@ DELETE /user/gpg_keys/:key_id
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `key_id` | integer | yes | The ID of the GPG key | | `key_id` | integer | yes | The ID of the GPG key |
```shell ```shell
...@@ -937,7 +938,7 @@ GET /users/:id/gpg_keys ...@@ -937,7 +938,7 @@ GET /users/:id/gpg_keys
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | ------------------ |
| `id` | integer | yes | The ID of the user | | `id` | integer | yes | The ID of the user |
```shell ```shell
...@@ -967,7 +968,7 @@ GET /users/:id/gpg_keys/:key_id ...@@ -967,7 +968,7 @@ GET /users/:id/gpg_keys/:key_id
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the user | | `id` | integer | yes | The ID of the user |
| `key_id` | integer | yes | The ID of the GPG key | | `key_id` | integer | yes | The ID of the GPG key |
...@@ -996,7 +997,7 @@ POST /users/:id/gpg_keys ...@@ -996,7 +997,7 @@ POST /users/:id/gpg_keys
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the user | | `id` | integer | yes | The ID of the user |
| `key_id` | integer | yes | The ID of the GPG key | | `key_id` | integer | yes | The ID of the GPG key |
...@@ -1027,7 +1028,7 @@ DELETE /users/:id/gpg_keys/:key_id ...@@ -1027,7 +1028,7 @@ DELETE /users/:id/gpg_keys/:key_id
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ------- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the user | | `id` | integer | yes | The ID of the user |
| `key_id` | integer | yes | The ID of the GPG key | | `key_id` | integer | yes | The ID of the GPG key |
...@@ -1348,10 +1349,10 @@ POST /users/:user_id/impersonation_tokens ...@@ -1348,10 +1349,10 @@ POST /users/:user_id/impersonation_tokens
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| ------------ | ------- | -------- | ----------- | | ------------ | ------- | -------- | --------------------------------------------------------------------------- |
| `user_id` | integer | yes | The ID of the user | | `user_id` | integer | yes | The ID of the user |
| `name` | string | yes | The name of the impersonation token | | `name` | string | yes | The name of the impersonation token |
| `expires_at` | date | no | The expiration date of the impersonation token in ISO format (`YYYY-MM-DD`)| | `expires_at` | date | no | The expiration date of the impersonation token in ISO format (`YYYY-MM-DD`) |
| `scopes` | array | yes | The array of scopes of the impersonation token (`api`, `read_user`) | | `scopes` | array | yes | The array of scopes of the impersonation token (`api`, `read_user`) |
```shell ```shell
...@@ -1393,7 +1394,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git ...@@ -1393,7 +1394,7 @@ curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://git
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | ------------------------ | ------- | -------- | --------------------------------- |
| `user_id` | integer | yes | The ID of the user | | `user_id` | integer | yes | The ID of the user |
| `impersonation_token_id` | integer | yes | The ID of the impersonation token | | `impersonation_token_id` | integer | yes | The ID of the impersonation token |
...@@ -1421,7 +1422,7 @@ GET /user/activities ...@@ -1421,7 +1422,7 @@ GET /user/activities
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ------ | -------- | ---------------------------------------------------------------------------------------------- |
| `from` | string | no | Date string in the format YEAR-MONTH-DAY. For example, `2016-03-11`. Defaults to 6 months ago. | | `from` | string | no | Date string in the format YEAR-MONTH-DAY. For example, `2016-03-11`. Defaults to 6 months ago. |
```shell ```shell
...@@ -1468,7 +1469,7 @@ GET /users/:id/memberships ...@@ -1468,7 +1469,7 @@ GET /users/:id/memberships
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ------- | -------- | ------------------------------------------------------------------ |
| `id` | integer | yes | The ID of a specified user | | `id` | integer | yes | The ID of a specified user |
| `type` | string | no | Filter memberships by type. Can be either `Project` or `Namespace` | | `type` | string | no | Filter memberships by type. Can be either `Project` or `Namespace` |
......
...@@ -255,6 +255,7 @@ module API ...@@ -255,6 +255,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user' requires :id, type: Integer, desc: 'The ID of the user'
requires :key, type: String, desc: 'The new SSH key' requires :key, type: String, desc: 'The new SSH key'
requires :title, type: String, desc: 'The title of the new SSH key' requires :title, type: String, desc: 'The title of the new SSH key'
optional :expires_at, type: DateTime, desc: 'The expiration date of the SSH key in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)'
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
post ":id/keys" do post ":id/keys" do
...@@ -720,6 +721,7 @@ module API ...@@ -720,6 +721,7 @@ module API
params do params do
requires :key, type: String, desc: 'The new SSH key' requires :key, type: String, desc: 'The new SSH key'
requires :title, type: String, desc: 'The title of the new SSH key' requires :title, type: String, desc: 'The title of the new SSH key'
optional :expires_at, type: DateTime, desc: 'The expiration date of the SSH key in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)'
end end
post "keys" do post "keys" do
key = current_user.keys.new(declared_params) key = current_user.keys.new(declared_params)
......
...@@ -1242,6 +1242,16 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1242,6 +1242,16 @@ describe API::Users, :do_not_mock_admin_mode do
end.to change { user.keys.count }.by(1) end.to change { user.keys.count }.by(1)
end end
it 'creates SSH key with `expires_at` attribute' do
optional_attributes = { expires_at: '2016-01-21T00:00:00.000Z' }
attributes = attributes_for(:key).merge(optional_attributes)
post api("/users/#{user.id}/keys", admin), params: attributes
expect(response).to have_gitlab_http_status(:created)
expect(json_response['expires_at']).to eq(optional_attributes[:expires_at])
end
it "returns 400 for invalid ID" do it "returns 400 for invalid ID" do
post api("/users/0/keys", admin) post api("/users/0/keys", admin)
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
...@@ -1798,6 +1808,16 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1798,6 +1808,16 @@ describe API::Users, :do_not_mock_admin_mode do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
end end
it 'creates SSH key with `expires_at` attribute' do
optional_attributes = { expires_at: '2016-01-21T00:00:00.000Z' }
attributes = attributes_for(:key).merge(optional_attributes)
post api("/user/keys", user), params: attributes
expect(response).to have_gitlab_http_status(:created)
expect(json_response['expires_at']).to eq(optional_attributes[:expires_at])
end
it "returns a 401 error if unauthorized" do it "returns a 401 error if unauthorized" do
post api("/user/keys"), params: { title: 'some title', key: 'some key' } post api("/user/keys"), params: { title: 'some title', key: 'some key' }
expect(response).to have_gitlab_http_status(:unauthorized) expect(response).to have_gitlab_http_status(:unauthorized)
......
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