1
1
"use strict" ;
2
- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3
- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4
- } ;
5
2
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
6
3
exports . Rekor = void 0 ;
7
4
/*
@@ -19,37 +16,31 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
16
See the License for the specific language governing permissions and
20
17
limitations under the License.
21
18
*/
22
- const make_fetch_happen_1 = __importDefault ( require ( "make-fetch-happen" ) ) ;
23
- const util_1 = require ( "../util" ) ;
24
- const error_1 = require ( "./error" ) ;
19
+ const fetch_1 = require ( "./fetch" ) ;
25
20
/**
26
21
* Rekor API client.
27
22
*/
28
23
class Rekor {
29
24
constructor ( options ) {
30
- this . fetch = make_fetch_happen_1 . default . defaults ( {
31
- retry : options . retry ,
32
- timeout : options . timeout ,
33
- headers : {
34
- Accept : 'application/json' ,
35
- 'User-Agent' : util_1 . ua . getUserAgent ( ) ,
36
- } ,
37
- } ) ;
38
- this . baseUrl = options . baseURL ;
25
+ this . options = options ;
39
26
}
40
27
/**
41
28
* Create a new entry in the Rekor log.
42
29
* @param propsedEntry {ProposedEntry} Data to create a new entry
43
30
* @returns {Promise<Entry> } The created entry
44
31
*/
45
32
async createEntry ( propsedEntry ) {
46
- const url = `${ this . baseUrl } /api/v1/log/entries` ;
47
- const response = await this . fetch ( url , {
48
- method : 'POST' ,
49
- headers : { 'Content-Type' : 'application/json' } ,
33
+ const { baseURL, timeout, retry } = this . options ;
34
+ const url = `${ baseURL } /api/v1/log/entries` ;
35
+ const response = await ( 0 , fetch_1 . fetchWithRetry ) ( url , {
36
+ headers : {
37
+ 'Content-Type' : 'application/json' ,
38
+ Accept : 'application/json' ,
39
+ } ,
50
40
body : JSON . stringify ( propsedEntry ) ,
41
+ timeout,
42
+ retry,
51
43
} ) ;
52
- await ( 0 , error_1 . checkStatus ) ( response ) ;
53
44
const data = await response . json ( ) ;
54
45
return entryFromResponse ( data ) ;
55
46
}
@@ -59,44 +50,18 @@ class Rekor {
59
50
* @returns {Promise<Entry> } The retrieved entry
60
51
*/
61
52
async getEntry ( uuid ) {
62
- const url = `${ this . baseUrl } /api/v1/log/entries/${ uuid } ` ;
63
- const response = await this . fetch ( url ) ;
64
- await ( 0 , error_1 . checkStatus ) ( response ) ;
65
- const data = await response . json ( ) ;
66
- return entryFromResponse ( data ) ;
67
- }
68
- /**
69
- * Search the Rekor log index for entries matching the given query.
70
- * @param opts {SearchIndex} Options to search the Rekor log
71
- * @returns {Promise<string[]> } UUIDs of matching entries
72
- */
73
- async searchIndex ( opts ) {
74
- const url = `${ this . baseUrl } /api/v1/index/retrieve` ;
75
- const response = await this . fetch ( url , {
76
- method : 'POST' ,
77
- body : JSON . stringify ( opts ) ,
78
- headers : { 'Content-Type' : 'application/json' } ,
53
+ const { baseURL, timeout, retry } = this . options ;
54
+ const url = `${ baseURL } /api/v1/log/entries/${ uuid } ` ;
55
+ const response = await ( 0 , fetch_1 . fetchWithRetry ) ( url , {
56
+ method : 'GET' ,
57
+ headers : {
58
+ Accept : 'application/json' ,
59
+ } ,
60
+ timeout,
61
+ retry,
79
62
} ) ;
80
- await ( 0 , error_1 . checkStatus ) ( response ) ;
81
63
const data = await response . json ( ) ;
82
- return data ;
83
- }
84
- /**
85
- * Search the Rekor logs for matching the given query.
86
- * @param opts {SearchLogQuery} Query to search the Rekor log
87
- * @returns {Promise<Entry[]> } List of matching entries
88
- */
89
- async searchLog ( opts ) {
90
- const url = `${ this . baseUrl } /api/v1/log/entries/retrieve` ;
91
- const response = await this . fetch ( url , {
92
- method : 'POST' ,
93
- body : JSON . stringify ( opts ) ,
94
- headers : { 'Content-Type' : 'application/json' } ,
95
- } ) ;
96
- await ( 0 , error_1 . checkStatus ) ( response ) ;
97
- const rawData = await response . json ( ) ;
98
- const data = rawData . map ( ( d ) => entryFromResponse ( d ) ) ;
99
- return data ;
64
+ return entryFromResponse ( data ) ;
100
65
}
101
66
}
102
67
exports . Rekor = Rekor ;
0 commit comments