1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-17 07:45:52 +01:00
verdaccio/website/translated_docs/zh-Hans/dev-plugins.md

139 lines
4.0 KiB
Markdown
Raw Normal View History

New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
---
id: dev-plugins
title: "Developing Plugins"
New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
---
There are many ways to extend `verdaccio`, currently we support `authentication plugins`, `middleware plugins` (since `v2.7.0`) and `storage plugins` since (`v3.x`).
New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
## Authentication Plugins
This section will describe how it looks like a Verdaccio plugin in a ES5 way. Basically we have to return an object with a single method called `authenticate` that will recieve 3 arguments (`user, password, callback`). Once the authentication has been executed there is 2 options to give a response to `verdaccio`.
### API
```js
function authenticate (user, password, callback) {
...more stuff
}
```
New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
##### OnError
Either something bad happened or auth was unsuccessful.
callback(null, false)
##### OnSuccess
The auth was successful.
`groups` is an array of strings where the user is part of.
callback(null, groups);
### Example
```javascript
function Auth(config, stuff) {
var self = Object.create(Auth.prototype);
self._users = {};
// config for this module
self._config = config;
// verdaccio logger
self._logger = stuff.logger;
// pass verdaccio logger to ldapauth
self._config.client_options.log = stuff.logger;
return self;
}
Auth.prototype.authenticate = function (user, password, callback) {
var LdapClient = new LdapAuth(self._config.client_options);
....
LdapClient.authenticate(user, password, function (err, ldapUser) {
...
var groups;
...
callback(null, groups);
});
};
module.exports = Auth;
```
And the setup
```yaml
auth:
htpasswd:
file: ./htpasswd
```
New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
Where `htpasswd` is the sufix of the plugin name. eg: `verdaccio-htpasswd` and the rest of the body would be the plugin configuration params.
New Crowdin translations (#456) * New translations ansible.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations repositories.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations index.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations dev-plugins.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations build.md (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations en.json (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations en.json (Spanish) * New translations config.md (Chinese Simplified) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations config.md (Chinese Traditional, Hong Kong) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional)
2018-01-08 20:45:03 +01:00
## Middleware Integration
Middleware plugins have the capability to modify the API layer, either adding new endpoints or intercepting requests. A pretty good example of middleware plugin is the (sinopia-github-oauth)[https://github.com/soundtrackyourbrand/sinopia-github-oauth]) compatible with `verdaccio`.
### API
```js
function register_middlewares(expressApp, auth, storage) {
...more stuff
}
```
To register a middleware we need an object with a single method called `register_middlewares` that will recieve 3 arguments (`expressApp, auth, storage`). *Auth* is the authentification instance and *storage* is also the main Storage instance that will give you have access to all to the storage actions.
## Storage Plugins
Since `verdaccio@3.x` we also can plug a custom storage.
### API
The storage API is a bit more complex, you will need to create a class that return a `ILocalData` implementation. Please see details bellow.
```js
<br />class LocalDatabase<ILocalData>{
constructor(config: Config, logger: Logger): ILocalData;
}
interface ILocalData {
add(name: string): SyncReturn;
remove(name: string): SyncReturn;
get(): StorageList;
getPackageStorage(packageInfo: string): IPackageStorage;
sync(): ?SyncReturn;
}
interface ILocalPackageManager {
writeTarball(name: string): IUploadTarball;
readTarball(name: string): IReadTarball;
readPackage(fileName: string, callback: Callback): void;
createPackage(name: string, value: any, cb: Callback): void;
deletePackage(fileName: string, callback: Callback): void;
removePackage(callback: Callback): void;
updatePackage(pkgFileName: string,
updateHandler: Callback,
onWrite: Callback,
transformPackage: Function,
onEnd: Callback): void;
savePackage(fileName: string, json: Package, callback: Callback): void;
}
interface IUploadTarball extends stream$PassThrough {
abort(): void;
done(): void;
}
interface IReadTarball extends stream$PassThrough {
abort(): void;
done(): void;
}
```
> This API still is experimental and might change next minor versions. The default [LocalStorage plugin](https://github.com/verdaccio/local-storage) it comes built-in in `verdaccio` and it is being loaded if any storage plugin has been defined.