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';
2
2
import { RequestHandler } from 'express' ;
3
3
4
4
import 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' ;
16
6
17
7
const basicAuthentication : Authentication < {
18
8
username : string ;
@@ -40,8 +30,10 @@ const builtin: Record<string, Authentication> = {
40
30
41
31
let scheme : Authentication ;
42
32
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 ] ) {
45
37
scheme = builtin [ authConfig . type ] ;
46
38
} else {
47
39
const moduleName = `oc-auth-${ authConfig . type } ` ;
Original file line number Diff line number Diff line change @@ -113,6 +113,22 @@ export interface VM {
113
113
type : 'oc-registry' | 'oc-registry-local' ;
114
114
}
115
115
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
+
116
132
export interface Config {
117
133
baseUrl : string ;
118
134
baseUrlFunc ?: ( opts : { host ?: string ; secure : boolean } ) => string ;
@@ -135,11 +151,7 @@ export interface Config {
135
151
port : number ;
136
152
postRequestPayloadSize ?: number ;
137
153
prefix : string ;
138
- publishAuth ?: {
139
- type : string ;
140
- username : string ;
141
- password : string ;
142
- } ;
154
+ publishAuth ?: PublishAuthConfig ;
143
155
publishValidation : ( data : unknown ) =>
144
156
| {
145
157
isValid : boolean ;
You can’t perform that action at this time.
0 commit comments