-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work in progress, adduser and authentication working with registry br…
…idge
- Loading branch information
Showing
13 changed files
with
162 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { FleetbaseRegistryAuthConfig } from './config'; | ||
export interface IFleetbaseClient extends AxiosInstance { | ||
} | ||
export declare const createFleetbaseClient: (config: FleetbaseRegistryAuthConfig) => IFleetbaseClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFleetbaseClient = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const createFleetbaseClient = (config) => { | ||
const instance = axios_1.default.create({ | ||
baseURL: `${config.fleetbaseHost}/~registry/v1/`, | ||
headers: { | ||
Authorization: `Bearer ${config.fleetbaseApiKey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
return instance; | ||
}; | ||
exports.createFleetbaseClient = createFleetbaseClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Config } from '@verdaccio/legacy-types'; | ||
export interface FleetbaseRegistryAuthConfig extends Config { | ||
fleetbaseHost: string; | ||
fleetbaseApiKey: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IPluginAuth, Callback, Config, RemoteUser, AllowAccess, AuthAccessCallback, PackageAccess } from '@verdaccio/types'; | ||
import { FleetbaseRegistryAuthConfig } from './config'; | ||
export { FleetbaseRegistryAuthConfig }; | ||
export default class FleetbaseAuthPlugin implements IPluginAuth<Config> { | ||
private config; | ||
private fleetbaseClient; | ||
private logger; | ||
constructor(config: Config, options: any); | ||
authenticate(identity: string, password: string, callback: Callback): Promise<void>; | ||
adduser(identity: string, password: string, callback: Callback): Promise<void>; | ||
allow_access(user: RemoteUser, pkg: (Config & PackageAccess) | (AllowAccess & PackageAccess), cb: AuthAccessCallback): void; | ||
allow_publish(user: RemoteUser, pkg: PackageAccess, cb: Callback): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const commons_api_1 = require("@verdaccio/commons-api"); | ||
const fleetbaseClient_1 = require("./fleetbaseClient"); | ||
class FleetbaseAuthPlugin { | ||
config; | ||
fleetbaseClient; | ||
logger; | ||
constructor(config, options) { | ||
this.config = Object.assign(config, config.auth['@fleetbase/verdaccio-fleetbase-auth']); | ||
this.logger = options.logger; | ||
this.fleetbaseClient = (0, fleetbaseClient_1.createFleetbaseClient)(this.config); | ||
} | ||
async authenticate(identity, password, callback) { | ||
this.logger.debug({ identity }, 'Auth::authenticate() - Authenticating user with identity: @{identity}'); | ||
try { | ||
const response = await this.fleetbaseClient.post('auth/authenticate', { identity, password }); | ||
const { groups } = response.data; | ||
callback(null, groups); | ||
} | ||
catch (error) { | ||
const errorMessage = error instanceof Error ? error.message : 'Authentication failed for creating developer account'; | ||
const conflict = (0, commons_api_1.getConflict)(errorMessage); | ||
this.logger.debug({ error: errorMessage }, 'Auth::authenticate() - Authentication failed with error: @{error}'); | ||
callback(conflict); | ||
} | ||
} | ||
async adduser(identity, password, callback) { | ||
this.logger.debug({ identity, password }, 'Auth::addUser() - Creating registry user with identity: @{identity} and password: @{password}'); | ||
try { | ||
const response = await this.fleetbaseClient.post('auth/add-user', { identity, password }); | ||
this.logger.debug({ response }, 'Auth::addUser() - Respone from Fleetbase: @{response}'); | ||
const { token } = response.data; | ||
this.logger.debug({ token }, 'Auth::addUser() - Token Generated: @{token}'); | ||
callback(null, true); | ||
} | ||
catch (error) { | ||
// Handle errors and call the callback with the error | ||
callback(error); | ||
} | ||
} | ||
allow_access(user, pkg, cb) { | ||
// Example implementation, modify based on your access logic | ||
} | ||
allow_publish(user, pkg, cb) { | ||
// Example implementation, adjust according to your publish logic | ||
} | ||
} | ||
exports.default = FleetbaseAuthPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const _default: (configValue: any) => string; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (configValue) => { | ||
const envValue = process.env[configValue]; | ||
return envValue || configValue; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Config } from '@verdaccio/legacy-types'; | ||
|
||
export interface FleetbaseRegistryAuthConfig extends Config { | ||
fleetbaseHost: string; | ||
fleetbaseApiKey: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,57 @@ | ||
import { IPluginAuth, AuthPluginPackage, Callback, Config, IAuth } from '@verdaccio/types'; | ||
import { createFleetbaseClient, IFleetbaseClient } from './FleetbaseClient'; | ||
import { IPluginAuth, AuthPluginPackage, Callback, Config, RemoteUser, AllowAccess, AuthAccessCallback, PackageAccess, Logger } from '@verdaccio/types'; | ||
import { getConflict } from '@verdaccio/commons-api'; | ||
import { createFleetbaseClient, IFleetbaseClient } from './fleetbaseClient'; | ||
import { FleetbaseRegistryAuthConfig } from './config'; | ||
import { Application } from 'express'; | ||
|
||
export { FleetbaseRegistryAuthConfig }; | ||
export default class FleetbaseAuthPlugin implements IPluginAuth<Config> { | ||
private config: Config; | ||
private config: FleetbaseRegistryAuthConfig; | ||
private fleetbaseClient: IFleetbaseClient; | ||
private logger: Logger; | ||
|
||
public constructor(config: Config, options: any) { | ||
this.config = config; | ||
this.fleetbaseClient = createFleetbaseClient(); | ||
this.config = Object.assign(config, config.auth['@fleetbase/verdaccio-fleetbase-auth']); | ||
this.logger = options.logger; | ||
this.fleetbaseClient = createFleetbaseClient(this.config); | ||
} | ||
|
||
public authenticate(user: string, password: string, cb: Callback): void { | ||
// Custom authentication logic here | ||
} | ||
public async authenticate(identity: string, password: string, callback: Callback): Promise<void> { | ||
this.logger.debug({ identity }, 'Auth::authenticate() - Authenticating user with identity: @{identity}'); | ||
|
||
try { | ||
const response = await this.fleetbaseClient.post('auth/authenticate', { identity, password }); | ||
const { groups } = response.data; | ||
|
||
public adduser(user: string, password: string, cb: Callback): void { | ||
// Here you can add your custom logic for adduser command | ||
// This should include your Fleetbase authentication and token handling | ||
callback(null, groups); | ||
} catch (error) { | ||
const errorMessage = error instanceof Error ? error.message : 'Authentication failed for creating developer account'; | ||
const conflict = getConflict(errorMessage); | ||
this.logger.debug({ error: errorMessage }, 'Auth::authenticate() - Authentication failed with error: @{error}'); | ||
callback(conflict); | ||
} | ||
} | ||
|
||
public allow_access(user: AuthPluginPackage, pkg: any, cb: Callback): void { | ||
// Access control logic | ||
public async adduser(identity: string, password: string, callback: Callback): Promise<void> { | ||
this.logger.debug({ identity, password }, 'Auth::addUser() - Creating registry user with identity: @{identity} and password: @{password}'); | ||
try { | ||
const response = await this.fleetbaseClient.post('auth/add-user', { identity, password }); | ||
this.logger.debug({ response }, 'Auth::addUser() - Respone from Fleetbase: @{response}'); | ||
const { token } = response.data; | ||
this.logger.debug({ token }, 'Auth::addUser() - Token Generated: @{token}'); | ||
|
||
callback(null, true); | ||
} catch (error) { | ||
// Handle errors and call the callback with the error | ||
callback(error); | ||
} | ||
} | ||
|
||
public allow_publish(user: AuthPluginPackage, pkg: any, cb: Callback): void { | ||
// Publish control logic | ||
public allow_access(user: RemoteUser, pkg: (Config & PackageAccess) | (AllowAccess & PackageAccess), cb: AuthAccessCallback): void { | ||
// Example implementation, modify based on your access logic | ||
} | ||
|
||
public register_middlewares(app: Application): void { | ||
// Middleware registration if needed | ||
public allow_publish(user: RemoteUser, pkg: PackageAccess, cb: Callback): void { | ||
// Example implementation, adjust according to your publish logic | ||
} | ||
} |