@cto.ai/ops
Version:
💻 CTO.ai - The CLI built for Teams 🚀
46 lines (45 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegistryAuthService = void 0;
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const env_1 = require("./../constants/env");
const CustomErrors_1 = require("./../errors/CustomErrors");
const Feathers_1 = require("./../services/Feathers");
const debug = (0, debug_1.default)('ops:RegistryAuthService');
class RegistryAuthService {
constructor(api = new Feathers_1.FeathersClient()) {
this.api = api;
}
async create(accessToken, teamname, opName, opVersion, pullAccess, pushAccess) {
try {
const response = await this.api.create('/private/registry/token', {
teamName: teamname,
opName,
opVersion,
pullAccess,
pushAccess,
}, {
headers: { Authorization: accessToken },
});
const { teamName = '', robotAccountName = '', token = '', robotID, } = response.data;
const projectFullName = `${env_1.OPS_REGISTRY_HOST}/${teamName}`;
const projectUrl = `https://${projectFullName}`;
const registryAuth = {
authconfig: {
username: robotAccountName,
password: token,
serveraddress: projectUrl,
},
projectFullName,
robotID,
};
return registryAuth;
}
catch (err) {
debug('%O', err);
throw new CustomErrors_1.UserUnauthorized(err);
}
}
}
exports.RegistryAuthService = RegistryAuthService;