geoserver-node-client 0.0.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -9
- package/dist/geoserver-rest-client.js +92 -0
- package/dist/package.json +56 -0
- package/dist/src/about.js +145 -0
- package/dist/src/datastore.js +1117 -0
- package/dist/src/imagemosaic.js +297 -0
- package/dist/src/layer.js +1263 -0
- package/dist/src/namespace.js +315 -0
- package/dist/src/reset-reload.js +160 -0
- package/dist/src/security.js +297 -0
- package/dist/src/settings.js +345 -0
- package/dist/src/style.js +597 -0
- package/dist/src/util/geoserver.js +97 -0
- package/dist/src/workspace.js +321 -0
- package/geoserver-rest-client.js +18 -52
- package/package.json +24 -6
- package/src/about.js +59 -0
- package/src/datastore.js +196 -200
- package/src/imagemosaic.js +75 -98
- package/src/layer.js +469 -328
- package/src/namespace.js +84 -83
- package/src/reset-reload.js +70 -0
- package/src/security.js +61 -84
- package/src/settings.js +76 -91
- package/src/style.js +165 -171
- package/src/util/geoserver.js +41 -0
- package/src/workspace.js +89 -81
- package/.eslintrc.json +0 -20
- package/.github/workflows/ci-geoserver-node-client.yml +0 -54
- package/.github/workflows/ci-publish-docs.yml +0 -24
- package/.github/workflows/wait-for.sh +0 -145
- package/.vscode/settings.json +0 -3
- package/DOCS_HOME.md +0 -26
- package/demo/index.js +0 -188
- package/release-it.json +0 -8
- package/test/sample_data/iceland.gpkg +0 -0
- package/test/sample_data/world.geotiff +0 -0
- package/test/test.js +0 -502
package/src/datastore.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
4
|
+
import AboutClient from './about.js'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Client for GeoServer data stores
|
|
@@ -11,13 +13,11 @@ export default class DatastoreClient {
|
|
|
11
13
|
* Creates a GeoServer REST DatastoreClient instance.
|
|
12
14
|
*
|
|
13
15
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
14
|
-
* @param {String}
|
|
15
|
-
* @param {String} password The password for the GeoServer REST API
|
|
16
|
+
* @param {String} auth The Basic Authentication string
|
|
16
17
|
*/
|
|
17
|
-
constructor (url,
|
|
18
|
-
this.url = url
|
|
19
|
-
this.
|
|
20
|
-
this.password = password;
|
|
18
|
+
constructor (url, auth) {
|
|
19
|
+
this.url = url;
|
|
20
|
+
this.auth = auth;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -25,7 +25,7 @@ export default class DatastoreClient {
|
|
|
25
25
|
*
|
|
26
26
|
* @param {String} workspace The workspace to get DataStores for
|
|
27
27
|
*
|
|
28
|
-
* @returns {Object
|
|
28
|
+
* @returns {Object} An object containing store details
|
|
29
29
|
*/
|
|
30
30
|
async getDataStores (workspace) {
|
|
31
31
|
return this.getStores(workspace, 'datastores');
|
|
@@ -36,7 +36,7 @@ export default class DatastoreClient {
|
|
|
36
36
|
*
|
|
37
37
|
* @param {String} workspace The workspace to get CoverageStores for
|
|
38
38
|
*
|
|
39
|
-
* @returns {Object
|
|
39
|
+
* @returns {Object} An object containing store details
|
|
40
40
|
*/
|
|
41
41
|
async getCoverageStores (workspace) {
|
|
42
42
|
return this.getStores(workspace, 'coveragestores');
|
|
@@ -47,7 +47,7 @@ export default class DatastoreClient {
|
|
|
47
47
|
*
|
|
48
48
|
* @param {String} workspace The workspace to get WmsStores for
|
|
49
49
|
*
|
|
50
|
-
* @returns {Object
|
|
50
|
+
* @returns {Object} An object containing store details
|
|
51
51
|
*/
|
|
52
52
|
async getWmsStores (workspace) {
|
|
53
53
|
return this.getStores(workspace, 'wmsstores');
|
|
@@ -58,7 +58,7 @@ export default class DatastoreClient {
|
|
|
58
58
|
*
|
|
59
59
|
* @param {String} workspace The workspace to get WmtsStores for
|
|
60
60
|
*
|
|
61
|
-
* @returns {Object
|
|
61
|
+
* @returns {Object} An object containing store details
|
|
62
62
|
*/
|
|
63
63
|
async getWmtsStores (workspace) {
|
|
64
64
|
return this.getStores(workspace, 'wmtsstores');
|
|
@@ -68,30 +68,26 @@ export default class DatastoreClient {
|
|
|
68
68
|
* @private
|
|
69
69
|
* Get information about various store types in a workspace.
|
|
70
70
|
*
|
|
71
|
-
* @param {String} workspace
|
|
72
|
-
* @param {String} storeType
|
|
71
|
+
* @param {String} workspace The workspace name
|
|
72
|
+
* @param {String} storeType The type of store
|
|
73
73
|
*
|
|
74
|
-
* @
|
|
74
|
+
* @throws Error if request fails
|
|
75
|
+
*
|
|
76
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
75
77
|
*/
|
|
76
78
|
async getStores (workspace, storeType) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
method: 'GET',
|
|
83
|
-
headers: {
|
|
84
|
-
Authorization: 'Basic ' + auth
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
if (response.status === 200) {
|
|
88
|
-
return await response.json();
|
|
79
|
+
const response = await fetch(this.url + 'workspaces/' + workspace + '/' + storeType + '.json', {
|
|
80
|
+
credentials: 'include',
|
|
81
|
+
method: 'GET',
|
|
82
|
+
headers: {
|
|
83
|
+
Authorization: this.auth
|
|
89
84
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
88
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
94
89
|
}
|
|
90
|
+
return response.json();
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
/**
|
|
@@ -100,7 +96,7 @@ export default class DatastoreClient {
|
|
|
100
96
|
* @param {String} workspace The workspace to search DataStore in
|
|
101
97
|
* @param {String} dataStore DataStore name
|
|
102
98
|
*
|
|
103
|
-
* @returns {Object
|
|
99
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
104
100
|
*/
|
|
105
101
|
async getDataStore (workspace, dataStore) {
|
|
106
102
|
return this.getStore(workspace, dataStore, 'datastores');
|
|
@@ -112,7 +108,7 @@ export default class DatastoreClient {
|
|
|
112
108
|
* @param {String} workspace The workspace to search CoverageStore in
|
|
113
109
|
* @param {String} covStore CoverageStore name
|
|
114
110
|
*
|
|
115
|
-
* @returns {Object
|
|
111
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
116
112
|
*/
|
|
117
113
|
async getCoverageStore (workspace, covStore) {
|
|
118
114
|
return this.getStore(workspace, covStore, 'coveragestores');
|
|
@@ -124,7 +120,8 @@ export default class DatastoreClient {
|
|
|
124
120
|
* @param {String} workspace The workspace to search WmsStore in
|
|
125
121
|
* @param {String} wmsStore WmsStore name
|
|
126
122
|
*
|
|
127
|
-
* @returns {Object
|
|
123
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
124
|
+
*
|
|
128
125
|
*/
|
|
129
126
|
async getWmsStore (workspace, wmsStore) {
|
|
130
127
|
return this.getStore(workspace, wmsStore, 'wmsstores');
|
|
@@ -136,44 +133,46 @@ export default class DatastoreClient {
|
|
|
136
133
|
* @param {String} workspace The workspace to search WmtsStore in
|
|
137
134
|
* @param {String} wmtsStore WmtsStore name
|
|
138
135
|
*
|
|
139
|
-
* @returns {Object
|
|
140
|
-
|
|
136
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
137
|
+
*/
|
|
141
138
|
async getWmtsStore (workspace, wmtsStore) {
|
|
142
139
|
return this.getStore(workspace, wmtsStore, 'wmtsstores');
|
|
143
140
|
}
|
|
144
141
|
|
|
145
142
|
/**
|
|
146
143
|
* @private
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @param {String}
|
|
144
|
+
* Get GeoServer store by type
|
|
145
|
+
*
|
|
146
|
+
* @param {String} workspace The name of the workspace
|
|
147
|
+
* @param {String} storeName The name of the store
|
|
148
|
+
* @param {String} storeType The type of the store
|
|
150
149
|
*
|
|
151
|
-
* @
|
|
150
|
+
* @throws Error if request fails
|
|
151
|
+
*
|
|
152
|
+
* @returns {Object} An object containing store details or undefined if it cannot be found
|
|
152
153
|
*/
|
|
153
154
|
async getStore (workspace, storeName, storeType) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
console.warn('No ' + storeType + ' with name "' + storeName + '" found');
|
|
169
|
-
return false;
|
|
155
|
+
const url = this.url + 'workspaces/' + workspace + '/' + storeType + '/' + storeName + '.json';
|
|
156
|
+
const response = await fetch(url, {
|
|
157
|
+
credentials: 'include',
|
|
158
|
+
method: 'GET',
|
|
159
|
+
headers: {
|
|
160
|
+
Authorization: this.auth
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (!response.ok) {
|
|
165
|
+
const grc = new AboutClient(this.url, this.auth);
|
|
166
|
+
if (await grc.exists()) {
|
|
167
|
+
// GeoServer exists, but requested item does not exist, we return empty
|
|
168
|
+
return;
|
|
170
169
|
} else {
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
// There was a general problem with GeoServer
|
|
171
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
172
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
173
173
|
}
|
|
174
|
-
} catch (error) {
|
|
175
|
-
return false;
|
|
176
174
|
}
|
|
175
|
+
return response.json();
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
/**
|
|
@@ -187,41 +186,36 @@ s */
|
|
|
187
186
|
* @param {String} layerTitle The published title of the new layer
|
|
188
187
|
* @param {String} filePath The path to the GeoTIFF file on the server
|
|
189
188
|
*
|
|
190
|
-
* @
|
|
189
|
+
* @throws Error if request fails
|
|
190
|
+
*
|
|
191
|
+
* @returns {String} The successful response text
|
|
191
192
|
*/
|
|
192
193
|
async createGeotiffFromFile (workspace, coverageStore, layerName, layerTitle, filePath) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const auth =
|
|
200
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
201
|
-
let url = this.url + 'workspaces/' + workspace + '/coveragestores/' +
|
|
194
|
+
const lyrTitle = layerTitle || layerName;
|
|
195
|
+
const stats = fs.statSync(filePath);
|
|
196
|
+
const fileSizeInBytes = stats.size;
|
|
197
|
+
const readStream = fs.createReadStream(filePath);
|
|
198
|
+
|
|
199
|
+
let url = this.url + 'workspaces/' + workspace + '/coveragestores/' +
|
|
202
200
|
coverageStore + '/file.geotiff';
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
url += '?filename=' + lyrTitle + '&coverageName=' + layerName;
|
|
202
|
+
const response = await fetch(url, {
|
|
203
|
+
credentials: 'include',
|
|
204
|
+
method: 'PUT',
|
|
205
|
+
headers: {
|
|
206
|
+
Authorization: this.auth,
|
|
207
|
+
'Content-Type': 'image/tiff',
|
|
208
|
+
'Content-length': fileSizeInBytes
|
|
209
|
+
},
|
|
210
|
+
body: readStream
|
|
211
|
+
});
|
|
214
212
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return responseText;
|
|
219
|
-
} else {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
} catch (error) {
|
|
223
|
-
return false;
|
|
213
|
+
if (!response.ok) {
|
|
214
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
215
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
224
216
|
}
|
|
217
|
+
// TODO: enforce JSON response or parse XML
|
|
218
|
+
return response.text();
|
|
225
219
|
}
|
|
226
220
|
|
|
227
221
|
/**
|
|
@@ -238,7 +232,7 @@ s */
|
|
|
238
232
|
* @param {String} pgDb The PostGIS DB name
|
|
239
233
|
* @param {String} [exposePk] expose primary key, defaults to false
|
|
240
234
|
*
|
|
241
|
-
* @
|
|
235
|
+
* @throws Error if request fails
|
|
242
236
|
*/
|
|
243
237
|
async createPostgisStore (workspace, namespaceUri, dataStore, pgHost, pgPort, pgUser, pgPassword, pgSchema, pgDb, exposePk) {
|
|
244
238
|
const body = {
|
|
@@ -292,24 +286,21 @@ s */
|
|
|
292
286
|
}
|
|
293
287
|
};
|
|
294
288
|
|
|
295
|
-
const auth =
|
|
296
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
297
289
|
const url = this.url + 'workspaces/' + workspace + '/datastores';
|
|
298
290
|
const response = await fetch(url, {
|
|
299
291
|
credentials: 'include',
|
|
300
292
|
method: 'POST',
|
|
301
293
|
headers: {
|
|
302
|
-
Authorization:
|
|
294
|
+
Authorization: this.auth,
|
|
303
295
|
'Content-Type': 'application/json'
|
|
304
296
|
},
|
|
305
297
|
body: JSON.stringify(body)
|
|
306
298
|
});
|
|
307
299
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return false;
|
|
300
|
+
// TODO: not tested yet
|
|
301
|
+
if (!response.ok) {
|
|
302
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
303
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
313
304
|
}
|
|
314
305
|
}
|
|
315
306
|
|
|
@@ -324,35 +315,32 @@ s */
|
|
|
324
315
|
*
|
|
325
316
|
* @param {String} workspace The WS to create the data store in
|
|
326
317
|
* @param {String} dataStore The data store name
|
|
327
|
-
* @param {String} zipArchivePath
|
|
318
|
+
* @param {String} zipArchivePath Absolute path to zip archive with the 3 properties files
|
|
319
|
+
*
|
|
320
|
+
* @throws Error if request fails
|
|
328
321
|
*
|
|
329
|
-
* @returns {String
|
|
322
|
+
* @returns {String} The response text
|
|
330
323
|
*/
|
|
331
324
|
async createImageMosaicStore (workspace, coverageStore, zipArchivePath) {
|
|
332
|
-
|
|
333
|
-
const readStream = fs.createReadStream(zipArchivePath);
|
|
334
|
-
const auth = Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
335
|
-
const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.imagemosaic';
|
|
336
|
-
const response = await fetch(url, {
|
|
337
|
-
credentials: 'include',
|
|
338
|
-
method: 'PUT',
|
|
339
|
-
headers: {
|
|
340
|
-
Authorization: 'Basic ' + auth,
|
|
341
|
-
'Content-Type': 'application/zip'
|
|
342
|
-
},
|
|
343
|
-
body: readStream
|
|
344
|
-
});
|
|
325
|
+
const readStream = fs.createReadStream(zipArchivePath);
|
|
345
326
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
327
|
+
const url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore + '/file.imagemosaic';
|
|
328
|
+
const response = await fetch(url, {
|
|
329
|
+
credentials: 'include',
|
|
330
|
+
method: 'PUT',
|
|
331
|
+
headers: {
|
|
332
|
+
Authorization: this.auth,
|
|
333
|
+
'Content-Type': 'application/zip'
|
|
334
|
+
},
|
|
335
|
+
body: readStream
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
if (!response.ok) {
|
|
339
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
340
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
355
341
|
}
|
|
342
|
+
|
|
343
|
+
return response.text();
|
|
356
344
|
};
|
|
357
345
|
|
|
358
346
|
/**
|
|
@@ -362,7 +350,7 @@ s */
|
|
|
362
350
|
* @param {String} dataStore The data store name
|
|
363
351
|
* @param {String} wmsCapabilitiesUrl Base WMS capabilities URL
|
|
364
352
|
*
|
|
365
|
-
* @
|
|
353
|
+
* @throws Error if request fails
|
|
366
354
|
*/
|
|
367
355
|
async createWmsStore (workspace, dataStore, wmsCapabilitiesUrl) {
|
|
368
356
|
const body = {
|
|
@@ -373,24 +361,55 @@ s */
|
|
|
373
361
|
}
|
|
374
362
|
};
|
|
375
363
|
|
|
376
|
-
const auth =
|
|
377
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
378
364
|
const url = this.url + 'workspaces/' + workspace + '/wmsstores';
|
|
379
365
|
const response = await fetch(url, {
|
|
380
366
|
credentials: 'include',
|
|
381
367
|
method: 'POST',
|
|
382
368
|
headers: {
|
|
383
|
-
Authorization:
|
|
369
|
+
Authorization: this.auth,
|
|
384
370
|
'Content-Type': 'application/json'
|
|
385
371
|
},
|
|
386
372
|
body: JSON.stringify(body)
|
|
387
373
|
});
|
|
388
374
|
|
|
389
|
-
if (response.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
375
|
+
if (!response.ok) {
|
|
376
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
377
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Creates a WMTS based data store.
|
|
383
|
+
*
|
|
384
|
+
* @param {String} workspace The WS to create the data store in
|
|
385
|
+
* @param {String} dataStore The data store name
|
|
386
|
+
* @param {String} wmtsCapabilitiesUrl Base WMTS capabilities URL
|
|
387
|
+
*
|
|
388
|
+
* @throws Error if request fails
|
|
389
|
+
*/
|
|
390
|
+
async createWmtsStore (workspace, dataStore, wmtsCapabilitiesUrl) {
|
|
391
|
+
const body = {
|
|
392
|
+
wmtsStore: {
|
|
393
|
+
name: dataStore,
|
|
394
|
+
type: 'WMTS',
|
|
395
|
+
capabilitiesURL: wmtsCapabilitiesUrl
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const url = this.url + 'workspaces/' + workspace + '/wmtsstores';
|
|
400
|
+
const response = await fetch(url, {
|
|
401
|
+
credentials: 'include',
|
|
402
|
+
method: 'POST',
|
|
403
|
+
headers: {
|
|
404
|
+
Authorization: this.auth,
|
|
405
|
+
'Content-Type': 'application/json'
|
|
406
|
+
},
|
|
407
|
+
body: JSON.stringify(body)
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
if (!response.ok) {
|
|
411
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
412
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
394
413
|
}
|
|
395
414
|
}
|
|
396
415
|
|
|
@@ -403,7 +422,7 @@ s */
|
|
|
403
422
|
* @param {String} namespaceUrl URL of the GeoServer namespace
|
|
404
423
|
* @param {Boolean} [useHttpConnectionPooling=true] use HTTP connection pooling for WFS connection
|
|
405
424
|
*
|
|
406
|
-
* @
|
|
425
|
+
* @throws Error if request fails
|
|
407
426
|
*/
|
|
408
427
|
async createWfsStore (workspace, dataStore, wfsCapabilitiesUrl, namespaceUrl, useHttpConnectionPooling) {
|
|
409
428
|
const body = {
|
|
@@ -429,24 +448,20 @@ s */
|
|
|
429
448
|
}
|
|
430
449
|
};
|
|
431
450
|
|
|
432
|
-
const auth =
|
|
433
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
434
451
|
const url = this.url + 'workspaces/' + workspace + '/datastores';
|
|
435
452
|
const response = await fetch(url, {
|
|
436
453
|
credentials: 'include',
|
|
437
454
|
method: 'POST',
|
|
438
455
|
headers: {
|
|
439
|
-
Authorization:
|
|
456
|
+
Authorization: this.auth,
|
|
440
457
|
'Content-Type': 'application/json'
|
|
441
458
|
},
|
|
442
459
|
body: JSON.stringify(body)
|
|
443
460
|
});
|
|
444
461
|
|
|
445
|
-
if (response.
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
console.warn(await response.text());
|
|
449
|
-
return false;
|
|
462
|
+
if (!response.ok) {
|
|
463
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
464
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
450
465
|
}
|
|
451
466
|
}
|
|
452
467
|
|
|
@@ -457,35 +472,25 @@ s */
|
|
|
457
472
|
* @param {String} coverageStore Name of data store to delete
|
|
458
473
|
* @param {String} recurse Flag to enable recursive deletion
|
|
459
474
|
*
|
|
460
|
-
* @
|
|
475
|
+
* @throws Error if request fails
|
|
461
476
|
*/
|
|
462
477
|
async deleteDataStore (workspace, dataStore, recurse) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
method: 'DELETE',
|
|
472
|
-
headers: {
|
|
473
|
-
Authorization: 'Basic ' + auth
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
if (response.status === 200) {
|
|
478
|
-
return true;
|
|
479
|
-
} else if (response.status === 401) {
|
|
480
|
-
console.warn('Deletion failed. There might be dependant objects to ' +
|
|
481
|
-
'this store. Delete them first or call this with "recurse=false"');
|
|
482
|
-
console.warn(response.text());
|
|
483
|
-
return false;
|
|
484
|
-
} else {
|
|
485
|
-
return false;
|
|
478
|
+
let url = this.url + 'workspaces/' + workspace + '/datastores/' + dataStore;
|
|
479
|
+
url += '?recurse=' + recurse;
|
|
480
|
+
|
|
481
|
+
const response = await fetch(url, {
|
|
482
|
+
credentials: 'include',
|
|
483
|
+
method: 'DELETE',
|
|
484
|
+
headers: {
|
|
485
|
+
Authorization: this.auth
|
|
486
486
|
}
|
|
487
|
-
}
|
|
488
|
-
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
if (!response.ok) {
|
|
490
|
+
// TODO: could not find status codes in the docs or via testing
|
|
491
|
+
// https://docs.geoserver.org/latest/en/api/#1.0.0/datastores.yaml
|
|
492
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
493
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
489
494
|
}
|
|
490
495
|
}
|
|
491
496
|
|
|
@@ -496,35 +501,30 @@ s */
|
|
|
496
501
|
* @param {String} coverageStore Name of CoverageStore to delete
|
|
497
502
|
* @param {String} recurse Flag to enable recursive deletion
|
|
498
503
|
*
|
|
499
|
-
* @
|
|
504
|
+
* @throws Error if request fails
|
|
500
505
|
*/
|
|
501
506
|
async deleteCoverageStore (workspace, coverageStore, recurse) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return false;
|
|
523
|
-
} else {
|
|
524
|
-
return false;
|
|
507
|
+
let url = this.url + 'workspaces/' + workspace + '/coveragestores/' + coverageStore;
|
|
508
|
+
url += '?recurse=' + recurse;
|
|
509
|
+
|
|
510
|
+
const response = await fetch(url, {
|
|
511
|
+
credentials: 'include',
|
|
512
|
+
method: 'DELETE',
|
|
513
|
+
headers: {
|
|
514
|
+
Authorization: this.auth
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// TODO: could not test it
|
|
519
|
+
if (!response.ok) {
|
|
520
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
521
|
+
switch (response.status) {
|
|
522
|
+
case 401:
|
|
523
|
+
throw new GeoServerResponseError('Deletion failed. There might be dependant objects to ' +
|
|
524
|
+
'this store. Delete them first or call this with "recurse=false"', geoServerResponse);
|
|
525
|
+
default:
|
|
526
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
525
527
|
}
|
|
526
|
-
} catch (error) {
|
|
527
|
-
return false;
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
|
|
@@ -535,7 +535,7 @@ s */
|
|
|
535
535
|
* @param {String} dataStore The data store name
|
|
536
536
|
* @param {String} gpkgPath Relative path to GeoPackage file within geoserver_data dir
|
|
537
537
|
*
|
|
538
|
-
* @
|
|
538
|
+
* @throws Error if request fails
|
|
539
539
|
*/
|
|
540
540
|
async createGpkgStore (workspace, dataStore, gpkgPath) {
|
|
541
541
|
const body = {
|
|
@@ -557,24 +557,20 @@ s */
|
|
|
557
557
|
}
|
|
558
558
|
};
|
|
559
559
|
|
|
560
|
-
const auth =
|
|
561
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
562
560
|
const url = this.url + 'workspaces/' + workspace + '/datastores';
|
|
563
561
|
const response = await fetch(url, {
|
|
564
562
|
credentials: 'include',
|
|
565
563
|
method: 'POST',
|
|
566
564
|
headers: {
|
|
567
|
-
Authorization:
|
|
565
|
+
Authorization: this.auth,
|
|
568
566
|
'Content-Type': 'application/json'
|
|
569
567
|
},
|
|
570
568
|
body: JSON.stringify(body)
|
|
571
569
|
});
|
|
572
570
|
|
|
573
|
-
if (response.
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
console.warn(await response.text());
|
|
577
|
-
return false;
|
|
571
|
+
if (!response.ok) {
|
|
572
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
573
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
578
574
|
}
|
|
579
575
|
}
|
|
580
576
|
}
|