File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,7 @@ import basicAuth from 'basic-auth-connect';
22import { RequestHandler } from 'express' ;
33
44import strings from '../../resources/' ;
5-
6- type Validate < T = unknown > = ( config : T ) => {
7- isValid : boolean ;
8- message : string ;
9- } ;
10- type Middleware < T > = ( config : T ) => any ;
11-
12- type Authentication < T = any > = {
13- validate : Validate < T > ;
14- middleware : Middleware < T > ;
15- } ;
5+ import { Authentication , PublishAuthConfig } from '../../types' ;
166
177const basicAuthentication : Authentication < {
188 username : string ;
@@ -40,8 +30,10 @@ const builtin: Record<string, Authentication> = {
4030
4131let scheme : Authentication ;
4232
43- export function validate ( authConfig : { type : string } ) {
44- if ( builtin [ authConfig . type ] ) {
33+ export function validate ( authConfig : PublishAuthConfig ) {
34+ if ( typeof authConfig . type !== 'string' ) {
35+ scheme = authConfig . type ;
36+ } else if ( builtin [ authConfig . type ] ) {
4537 scheme = builtin [ authConfig . type ] ;
4638 } else {
4739 const moduleName = `oc-auth-${ authConfig . type } ` ;
Original file line number Diff line number Diff line change @@ -113,6 +113,22 @@ export interface VM {
113113 type : 'oc-registry' | 'oc-registry-local' ;
114114}
115115
116+ export type Authentication < T = any > = {
117+ validate : ( config : T ) => {
118+ isValid : boolean ;
119+ message : string ;
120+ } ;
121+ middleware : ( config : T ) => any ;
122+ } ;
123+
124+ export type PublishAuthConfig =
125+ | {
126+ type : 'basic' ;
127+ username : string ;
128+ password : string ;
129+ }
130+ | ( { type : string | Authentication } & Record < string , any > ) ;
131+
116132export interface Config {
117133 baseUrl : string ;
118134 baseUrlFunc ?: ( opts : { host ?: string ; secure : boolean } ) => string ;
@@ -135,11 +151,7 @@ export interface Config {
135151 port : number ;
136152 postRequestPayloadSize ?: number ;
137153 prefix : string ;
138- publishAuth ?: {
139- type : string ;
140- username : string ;
141- password : string ;
142- } ;
154+ publishAuth ?: PublishAuthConfig ;
143155 publishValidation : ( data : unknown ) =>
144156 | {
145157 isValid : boolean ;
You can’t perform that action at this time.
0 commit comments