1//
2// Copyright 2018, Patrick Webster
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17package gitlab
18
19import (
20 "fmt"
21 "time"
22)
23
24// KeysService handles communication with the
25// keys related methods of the GitLab API.
26//
27// GitLab API docs:
28// https://docs.gitlab.com/ee/api/keys.html
29type KeysService struct {
30 client *Client
31}
32
33// Key represents a GitLab user's SSH key.
34//
35// GitLab API docs:
36// https://docs.gitlab.com/ee/api/keys.html
37type Key struct {
38 ID int `json:"id"`
39 Title string `json:"title"`
40 Key string `json:"key"`
41 CreatedAt *time.Time `json:"created_at"`
42 User User `json:"user"`
43}
44
45// GetKeyWithUser gets a single key by id along with the associated
46// user information.
47//
48// GitLab API docs:
49// https://docs.gitlab.com/ee/api/keys.html#get-ssh-key-with-user-by-id-of-an-ssh-key
50func (s *KeysService) GetKeyWithUser(key int, options ...OptionFunc) (*Key, *Response, error) {
51 u := fmt.Sprintf("keys/%d", key)
52
53 req, err := s.client.NewRequest("GET", u, nil, options)
54 if err != nil {
55 return nil, nil, err
56 }
57
58 k := new(Key)
59 resp, err := s.client.Do(req, k)
60 if err != nil {
61 return nil, resp, err
62 }
63
64 return k, resp, err
65}