Skip to content

Commit 2fa6944

Browse files
feat: get rid of legacy mode
Closes #78
1 parent d3d083b commit 2fa6944

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ the following:
1717

1818
> This is experimental!
1919
20-
## Gitlab Version Compatibility
21-
22-
- If `legacy_mode: false` or undefined (default mode): Gitlab 11.2+
23-
- If `legacy_mode: true`: Gitlab 9.0+
24-
2520
## Use it
2621

2722
You need at least node version 8.x.x, codename **carbon**.
@@ -137,11 +132,6 @@ For instance, assuming the following configuration:
137132
- `@group3/project`
138133
- error if the user tries to publish any package under `@group2/**`
139134

140-
### Legacy Mode
141-
142-
If using the legacy mode, the system behaves as in normal mode with
143-
fixed configuration `auth.gitlab.publish` = `$owner`
144-
145135
## Configuration Options
146136

147137
The full set of configuration options is:
@@ -153,7 +143,6 @@ auth:
153143
authCache:
154144
enabled: <boolean>
155145
ttl: <integer>
156-
legacy_mode: <boolean>
157146
publish: <string>
158147
```
159148
@@ -163,8 +152,7 @@ auth:
163152
| `url` | `<empty>` | url | mandatory, the url of the gitlab server |
164153
| `authCache: enabled` | `true` | boolean | activate in-memory authentication cache |
165154
| `authCache: ttl` | `300` (`0`=unlimited) | integer | time-to-live of entries in the authentication cache, in seconds |
166-
| `legacy_mode` | `false` | boolean | gitlab versions pre-11.2 do not support groups api queries based on access level; this enables the legacy behaviour of only allowing npm publish operations on groups where the logged in user has owner rights |
167-
| `publish` | `$maintainer` | [`$guest`, `$reporter`, `$developer`, `$maintainer`, `$owner`] | group minimum access level of the logged in user required for npm publish operations (does not apply in legacy mode) |
155+
| `publish` | `$maintainer` | [`$guest`, `$reporter`, `$developer`, `$maintainer`, `$owner`] | group minimum access level of the logged in user required for npm publish operations |
168156
<!-- markdownlint-enable MD013 -->
169157

170158
## Authentication Cache

src/gitlab.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type VerdaccioGitlabConfig = {
1616
enabled?: boolean;
1717
ttl?: number;
1818
};
19-
legacy_mode?: boolean;
2019
publish?: VerdaccioGitlabAccessLevel;
2120
};
2221

@@ -65,20 +64,16 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
6564
this.logger.info(`[gitlab] initialized auth cache with ttl: ${ttl} seconds`);
6665
}
6766

68-
if (this.config.legacy_mode) {
69-
this.publishLevel = '$owner';
70-
this.logger.info('[gitlab] legacy mode pre-gitlab v11.2 active, publish is only allowed to group owners');
71-
} else {
72-
this.publishLevel = '$maintainer';
73-
if (this.config.publish) {
74-
this.publishLevel = this.config.publish;
75-
}
7667

77-
if (!Object.keys(ACCESS_LEVEL_MAPPING).includes(this.publishLevel)) {
78-
throw Error(`[gitlab] invalid publish access level configuration: ${this.publishLevel}`);
79-
}
80-
this.logger.info(`[gitlab] publish control level: ${this.publishLevel}`);
68+
this.publishLevel = '$maintainer';
69+
if (this.config.publish) {
70+
this.publishLevel = this.config.publish;
8171
}
72+
73+
if (!Object.keys(ACCESS_LEVEL_MAPPING).includes(this.publishLevel)) {
74+
throw Error(`[gitlab] invalid publish access level configuration: ${this.publishLevel}`);
75+
}
76+
this.logger.info(`[gitlab] publish control level: ${this.publishLevel}`);
8277
}
8378

8479
authenticate(user: string, password: string, cb: Callback) {
@@ -111,13 +106,8 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
111106
// Set the groups of an authenticated user, in normal mode:
112107
// - for access, depending on the package settings in verdaccio
113108
// - for publish, the logged in user id and all the groups they can reach as configured with access level `$auth.gitlab.publish`
114-
//
115-
// In legacy mode, the groups are:
116-
// - for access, depending on the package settings in verdaccio
117-
// - for publish, the logged in user id and all the groups they can reach as fixed `$auth.gitlab.publish` = `$owner`
118-
const gitlabPublishQueryParams = this.config.legacy_mode
119-
? { owned: true }
120-
: { min_access_level: publishLevelId };
109+
const gitlabPublishQueryParams = { min_access_level: publishLevelId };
110+
121111
// @ts-ignore
122112
this.logger.trace('[gitlab] querying gitlab user groups with params:', gitlabPublishQueryParams);
123113

0 commit comments

Comments
 (0)