Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
fix: auth minor bugs (#17)
Browse files Browse the repository at this point in the history
* fix: keyword array issue

* fix: prettier code

* fix: add implementation as conent
  • Loading branch information
juanpicado authored Dec 23, 2019
1 parent 44bfea3 commit f948088
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
2 changes: 1 addition & 1 deletion generators/app/templates/typescript/auth/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"standard-version": "^7.0.0",
"typescript": "^3.7.2"
},
"keywords": "[<%= keywords %>]",
"keywords": ["<%= keywords %>]"],
"license": "<%= license %>",
"repository": "<%= repository %>",
"author": "<%= authorName %> <<%= authorEmail %>>",
Expand Down
29 changes: 7 additions & 22 deletions generators/app/templates/typescript/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import {
PackageAccess,
IPluginAuth,
RemoteUser,
Logger
} from "@verdaccio/types";
Logger,
} from '@verdaccio/types';

import { CustomConfig } from "../types/index";
import { CustomConfig } from '../types/index';

/**
* Custom Verdaccio Authenticate Plugin.
*/
export default class AuthCustomPlugin implements IPluginAuth<CustomConfig> {
public logger: Logger;
private foo: string;
public constructor(
config: CustomConfig,
options: PluginOptions<CustomConfig>
) {
public constructor(config: CustomConfig, options: PluginOptions<CustomConfig>) {
this.logger = options.logger;
this.foo = config.foo;
return this;
Expand Down Expand Up @@ -47,11 +44,7 @@ export default class AuthCustomPlugin implements IPluginAuth<CustomConfig> {
* @param pkg
* @param cb
*/
public allow_access(
user: RemoteUser,
pkg: PackageAccess,
cb: AuthAccessCallback
): void {
public allow_access(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
/**
* This code is just an example for demostration purpose
if (user.name === this.foo && pkg.access.includes[user.name]) {
Expand All @@ -70,11 +63,7 @@ export default class AuthCustomPlugin implements IPluginAuth<CustomConfig> {
* @param pkg
* @param cb
*/
public allow_publish(
user: RemoteUser,
pkg: PackageAccess,
cb: AuthAccessCallback
): void {
public allow_publish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
/**
* This code is just an example for demostration purpose
if (user.name === this.foo && pkg.access.includes[user.name]) {
Expand All @@ -87,11 +76,7 @@ export default class AuthCustomPlugin implements IPluginAuth<CustomConfig> {
*/
}

public allow_unpublish(
user: RemoteUser,
pkg: PackageAccess,
cb: AuthAccessCallback
): void {
public allow_unpublish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
/**
* This code is just an example for demostration purpose
if (user.name === this.foo && pkg.access.includes[user.name]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"standard-version": "^7.0.0",
"typescript": "^3.7.2"
},
"keywords": "[<%= keywords %>]",
"keywords": ["<%= keywords %>"],
"license": "<%= license %>",
"repository": "<%= repository %>",
"author": "<%= authorName %> <<%= authorEmail %>>",
Expand Down
26 changes: 14 additions & 12 deletions generators/app/templates/typescript/middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ export default class VerdaccioMiddlewarePlugin implements IPluginMiddleware<Cust
/* eslint @typescript-eslint/no-unused-vars: off */
_storage: IStorageManager<CustomConfig>
): void {
/* eslint new-cap:off */
const router = Router();
router.post(
'/custom-endpoint',
(req: Request, res: Response & { report_error?: Function }, next: NextFunction): void => {
const encryptedString = auth.aesEncrypt(Buffer.from(this.foo, 'utf8'));
res.setHeader('X-Verdaccio-Token-Plugin', encryptedString.toString());
next();
}
);

app.use('/-/npm/something-new', router);
/**
* This is just an example of implementation
// eslint new-cap:off
const router = Router();
router.post(
'/custom-endpoint',
(req: Request, res: Response & { report_error?: Function }, next: NextFunction): void => {
const encryptedString = auth.aesEncrypt(Buffer.from(this.foo, 'utf8'));
res.setHeader('X-Verdaccio-Token-Plugin', encryptedString.toString());
next();
}
);
app.use('/-/npm/something-new', router);
*/
}
}
2 changes: 1 addition & 1 deletion generators/app/templates/typescript/storage/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"standard-version": "^7.0.0",
"typescript": "^3.7.2"
},
"keywords": "[<%= keywords %>]",
"keywords": ["<%= keywords %>"],
"license": "<%= license %>",
"repository": "<%= repository %>",
"author": "<%= authorName %> <<%= authorEmail %>>",
Expand Down

0 comments on commit f948088

Please sign in to comment.