Skip to content

Commit

Permalink
Add generateAuthToken function to repositories.service.js
Browse files Browse the repository at this point in the history
  • Loading branch information
FLYBYME committed Dec 5, 2023
1 parent cc67e2d commit 5a49763
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions services/repositories.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,44 @@ module.exports = {
}
},

/**
* generate auth token for repository
*
* @actions
* @param {String} id - id of repository
*
* @returns {String} - repository auth token
*/
generateAuthToken: {
rest: {
method: "GET",
path: "/:id/token",
},
params: {
id: {
type: "string",
optional: false,
},
},
async handler(ctx) {
const params = Object.assign({}, ctx.params);

// get repository
const repository = await this.getById(ctx, params.id);

// check repository exists
if (!repository) {
throw new MoleculerClientError("repository not found", 404);
}

// generate auth token
const authToken = await this.generateAuthToken(ctx, repository);

// return auth token
return authToken;
}
},

// clean db
clean: {
async handler(ctx) {
Expand Down Expand Up @@ -801,6 +839,25 @@ module.exports = {
return repositoryPath;
},

/**
* generate auth token for repository
*
* @param {Context} ctx - context of request
* @param {Object} repository - repository object
*
* @returns {Promise<String>} - repository auth token
*/
async generateAuthToken(ctx, repository) {
// generate auth token
const authToken = await ctx.call('v1.tokens.generate', {
type: 'api-key',
owner: repository.owner,
});

// return auth token
return authToken;
},

},


Expand Down

0 comments on commit 5a49763

Please sign in to comment.