UNPKG

2.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const debug_1 = tslib_1.__importDefault(require("debug"));
5const env_1 = require("../constants/env");
6const CustomErrors_1 = require("../errors/CustomErrors");
7const Feathers_1 = require("./Feathers");
8const debug = debug_1.default('ops:RegistryAuthService');
9class RegistryAuthService {
10 constructor(api = new Feathers_1.FeathersClient()) {
11 this.api = api;
12 }
13 async create(accessToken, teamname, opName, opVersion, pullAccess, pushAccess) {
14 try {
15 const response = await this.api.create('registry/token', {
16 teamName: teamname,
17 opName,
18 opVersion,
19 pullAccess,
20 pushAccess,
21 }, {
22 headers: { Authorization: accessToken },
23 });
24 const { teamName = '', robotAccountName = '', token = '', robotID, } = response.data;
25 const projectFullName = `${env_1.OPS_REGISTRY_HOST}/${teamName}`;
26 const projectUrl = `https://${projectFullName}`;
27 const registryAuth = {
28 authconfig: {
29 username: robotAccountName,
30 password: token,
31 serveraddress: projectUrl,
32 },
33 projectFullName,
34 robotID,
35 };
36 return registryAuth;
37 }
38 catch (err) {
39 debug('%O', err);
40 throw new CustomErrors_1.UserUnauthorized(err);
41 }
42 }
43 async delete(accessToken, id, teamName, opName, opVersion) {
44 try {
45 await this.api.remove(`registry/token/`, id.toString(), {
46 query: {
47 teamName,
48 opName,
49 opVersion,
50 },
51 headers: { Authorization: accessToken },
52 });
53 }
54 catch (err) {
55 debug('%0', err);
56 throw new CustomErrors_1.UserUnauthorized(err);
57 }
58 }
59}
60exports.RegistryAuthService = RegistryAuthService;