aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/user-tokens.js
blob: ca522f914b4ed7d173dde117790212d587a61dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { getJSON, postJSON, post } from '../helpers/request.js';


/**
 * List tokens for given user login
 * @param {string} login
 * @returns {Promise}
 */
export function getTokens (login) {
  let url = baseUrl + '/api/user_tokens/search';
  let data = { login };
  return getJSON(url, data).then(r => r.userTokens);
}


/**
 * Generate a user token
 * @param {string} userLogin
 * @param {string} tokenName
 * @returns {Promise}
 */
export function generateToken(userLogin, tokenName) {
  let url = baseUrl + '/api/user_tokens/generate';
  let data = { login: userLogin, name: tokenName };
  return postJSON(url, data);
}


/**
 * Revoke a user token
 * @param {string} userLogin
 * @param {string} tokenName
 * @returns {Promise}
 */
export function revokeToken(userLogin, tokenName) {
  let url = baseUrl + '/api/user_tokens/revoke';
  let data = { login: userLogin, name: tokenName };
  return post(url, data);
}