@@ -8,10 +8,10 @@ class ArboristClient {
8
8
this . baseEndpoint = arboristEndpoint ;
9
9
}
10
10
11
- listAuthorizedResources ( jwt ) {
11
+ listAuthMapping ( jwt ) {
12
12
// Make request to arborist for list of resources with access
13
13
const resourcesEndpoint = `${ this . baseEndpoint } /auth/mapping` ;
14
- log . debug ( '[ArboristClient] listAuthorizedResources jwt: ' , jwt ) ;
14
+ log . debug ( '[ArboristClient] listAuthMapping jwt: ' , jwt ) ;
15
15
16
16
const headers = ( jwt ) ? { Authorization : `bearer ${ jwt } ` } : { } ;
17
17
return fetch (
@@ -40,87 +40,6 @@ class ArboristClient {
40
40
log . error ( err ) ;
41
41
throw new CodedError ( 500 , err ) ;
42
42
} ,
43
- ) . then (
44
- ( result ) => {
45
- const data = {
46
- resources : [ ] ,
47
- } ;
48
- Object . keys ( result ) . forEach ( ( key ) => {
49
- // logic: you have access to a project if you have the following access:
50
- // method 'read' (or '*' - all methods) to service 'guppy' (or '*' - all services)
51
- // on the project resource.
52
- if ( result [ key ] && result [ key ] . some ( ( x ) => (
53
- ( x . method === 'read' || x . method === '*' )
54
- && ( x . service === 'guppy' || x . service === '*' )
55
- ) ) ) {
56
- data . resources . push ( key ) ;
57
- }
58
- } ) ;
59
- log . debug ( '[ArboristClient] data: ' , data ) ;
60
- return data ;
61
- } ,
62
- ( err ) => {
63
- log . error ( err ) ;
64
- throw new CodedError ( 500 , err ) ;
65
- } ,
66
- ) ;
67
- }
68
-
69
- listAuthorizedCreateResources ( jwt ) {
70
- // Make request to arborist for list of resources with access
71
- const resourcesEndpoint = `${ this . baseEndpoint } /auth/mapping` ;
72
- log . debug ( '[ArboristClient] listAuthorizedCreateResources jwt: ' , jwt ) ;
73
-
74
- const headers = ( jwt ) ? { Authorization : `bearer ${ jwt } ` } : { } ;
75
- return fetch (
76
- resourcesEndpoint ,
77
- {
78
- method : 'POST' ,
79
- headers,
80
- } ,
81
- ) . then (
82
- ( response ) => {
83
- if ( response . status === 400 ) {
84
- // Retry with GET instead of POST. Older version of Arborist POST auth/mapping
85
- // didn't support token authentication.
86
- // This catch block can be removed in a little while, when it will likely not cause issues
87
- return fetch (
88
- resourcesEndpoint ,
89
- {
90
- method : 'GET' ,
91
- headers,
92
- } ,
93
- ) . then ( ( res ) => res . json ( ) ) ;
94
- }
95
- return response . json ( ) ;
96
- } ,
97
- ( err ) => {
98
- log . error ( err ) ;
99
- throw new CodedError ( 500 , err ) ;
100
- } ,
101
- ) . then (
102
- ( result ) => {
103
- const data = {
104
- resources : [ ] ,
105
- } ;
106
- Object . keys ( result ) . forEach ( ( key ) => {
107
- // logic: you have access to a project if you have the following access:
108
- // method 'create' (or '*' - all methods) to service 'guppy' (or '*' - all services)
109
- // on the project resource.
110
- if ( result [ key ] && result [ key ] . some ( ( x ) => (
111
- ( x . method === 'create' || x . method === '*' )
112
- && ( x . service === 'guppy' || x . service === '*' )
113
- ) ) ) {
114
- data . resources . push ( key ) ;
115
- }
116
- } ) ;
117
- log . debug ( '[ArboristClient] data: ' , data ) ;
118
- return data ;
119
- } ,
120
- ( err ) => {
121
- log . error ( err ) ;
122
- throw new CodedError ( 500 , err ) ;
123
- } ,
124
43
) ;
125
44
}
126
45
}
0 commit comments