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/namespace.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
3
|
+
import AboutClient from './about.js'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Client for GeoServer namespace
|
|
@@ -10,36 +12,33 @@ export default class NamespaceClient {
|
|
|
10
12
|
* Creates a GeoServer REST NamespaceClient instance.
|
|
11
13
|
*
|
|
12
14
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
13
|
-
* @param {String}
|
|
14
|
-
* @param {String} password The password for the GeoServer REST API
|
|
15
|
+
* @param {String} auth The Basic Authentication string
|
|
15
16
|
*/
|
|
16
|
-
constructor (url,
|
|
17
|
-
this.url = url
|
|
18
|
-
this.
|
|
19
|
-
this.password = password;
|
|
17
|
+
constructor (url, auth) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.auth = auth;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Returns all namespaces.
|
|
24
24
|
*
|
|
25
|
-
* @
|
|
25
|
+
* @throws Error if request fails
|
|
26
|
+
*
|
|
27
|
+
* @returns {Object} An object describing the namespace
|
|
26
28
|
*/
|
|
27
29
|
async getAll () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const json = await response.json();
|
|
39
|
-
return json;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return false;
|
|
30
|
+
const response = await fetch(this.url + 'namespaces.json', {
|
|
31
|
+
credentials: 'include',
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: this.auth
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
39
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
42
40
|
}
|
|
41
|
+
return response.json();
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -48,66 +47,65 @@ export default class NamespaceClient {
|
|
|
48
47
|
* @param {String} prefix Prefix of the new namespace
|
|
49
48
|
* @param {String} uri Uri of the new namespace
|
|
50
49
|
*
|
|
51
|
-
* @
|
|
50
|
+
* @throws Error if request fails
|
|
51
|
+
*
|
|
52
|
+
* @returns {String} The name of the created namespace
|
|
52
53
|
*/
|
|
53
54
|
async create (prefix, uri) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const auth =
|
|
63
|
-
Buffer.from(this.user + ':' + this.password).toString('base64');
|
|
55
|
+
const body = {
|
|
56
|
+
namespace: {
|
|
57
|
+
prefix: prefix,
|
|
58
|
+
uri: uri
|
|
59
|
+
}
|
|
60
|
+
};
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const response = await fetch(this.url + 'namespaces', {
|
|
63
|
+
credentials: 'include',
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
Authorization: this.auth,
|
|
67
|
+
'Content-Type': 'application/json'
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body)
|
|
70
|
+
});
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} else {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
return false;
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
74
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
83
75
|
}
|
|
76
|
+
|
|
77
|
+
return response.text();
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
/**
|
|
87
81
|
* Returns a namespace.
|
|
88
82
|
*
|
|
89
83
|
* @param {String} name Name of the namespace
|
|
90
|
-
*
|
|
84
|
+
*
|
|
85
|
+
* @throws Error if request fails
|
|
86
|
+
*
|
|
87
|
+
* @returns {Object} An object describing the namespace or undefined if it cannot be found
|
|
91
88
|
*/
|
|
92
89
|
async get (name) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return
|
|
90
|
+
const response = await fetch(this.url + 'namespaces/' + name + '.json', {
|
|
91
|
+
credentials: 'include',
|
|
92
|
+
method: 'GET',
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: this.auth
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
const grc = new AboutClient(this.url, this.auth);
|
|
99
|
+
if (await grc.exists()) {
|
|
100
|
+
// GeoServer exists, but requested item does not exist, we return empty
|
|
101
|
+
return;
|
|
105
102
|
} else {
|
|
106
|
-
|
|
103
|
+
// There was a general problem with GeoServer
|
|
104
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
105
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
107
106
|
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
return false;
|
|
110
107
|
}
|
|
108
|
+
return response.json();
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
/**
|
|
@@ -115,28 +113,31 @@ export default class NamespaceClient {
|
|
|
115
113
|
*
|
|
116
114
|
* @param {String} name Name of the namespace to delete
|
|
117
115
|
*
|
|
118
|
-
* @
|
|
116
|
+
* @throws Error if request fails
|
|
119
117
|
*/
|
|
120
118
|
async delete (name) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Authorization: 'Basic ' + auth
|
|
129
|
-
}
|
|
130
|
-
});
|
|
119
|
+
const response = await fetch(this.url + 'namespaces/' + name, {
|
|
120
|
+
credentials: 'include',
|
|
121
|
+
method: 'DELETE',
|
|
122
|
+
headers: {
|
|
123
|
+
Authorization: this.auth
|
|
124
|
+
}
|
|
125
|
+
});
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
129
|
+
switch (response.status) {
|
|
130
|
+
case 403:
|
|
131
|
+
throw new GeoServerResponseError(
|
|
132
|
+
'Namespace or related Workspace is not empty (and recurse not true)',
|
|
133
|
+
geoServerResponse);
|
|
134
|
+
case 404:
|
|
135
|
+
throw new GeoServerResponseError('Namespace doesn\'t exist', geoServerResponse);
|
|
136
|
+
case 405:
|
|
137
|
+
throw new GeoServerResponseError('Can\'t delete default namespace', geoServerResponse);
|
|
138
|
+
default:
|
|
139
|
+
throw new GeoServerResponseError('Response not recognized', geoServerResponse)
|
|
137
140
|
}
|
|
138
|
-
} catch (error) {
|
|
139
|
-
return false;
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { GeoServerResponseError, getGeoServerResponseText } from './util/geoserver.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client for GeoServer "Reset/Reload" to clear internal caches and reload
|
|
6
|
+
* configuration from disk endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @module ResetReloadClient
|
|
9
|
+
*/
|
|
10
|
+
export default class ResetReloadClient {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a GeoServer REST ResetReloadClient instance.
|
|
13
|
+
*
|
|
14
|
+
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
15
|
+
* @param {String} auth The Basic Authentication string
|
|
16
|
+
*/
|
|
17
|
+
constructor (url, auth) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.auth = auth;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resets all store, raster, and schema caches. This operation is used to
|
|
24
|
+
* force GeoServer to drop all caches and store connections and reconnect to
|
|
25
|
+
* each of them the next time they are needed by a request.
|
|
26
|
+
* This is useful in case the stores themselves cache some information about
|
|
27
|
+
* the data structures they manage that may have changed in the meantime.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error if request fails
|
|
30
|
+
*/
|
|
31
|
+
async reset () {
|
|
32
|
+
const url = this.url + 'reset';
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
credentials: 'include',
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: this.auth
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
43
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Reloads the GeoServer catalog and configuration from disk. This operation
|
|
49
|
+
* is used in cases where an external tool has modified the on-disk
|
|
50
|
+
* configuration. This operation will also force GeoServer to drop any
|
|
51
|
+
* internal caches and reconnect to all data stores.
|
|
52
|
+
*
|
|
53
|
+
* @throws Error if request fails
|
|
54
|
+
*/
|
|
55
|
+
async reload () {
|
|
56
|
+
const url = this.url + 'reload';
|
|
57
|
+
const response = await fetch(url, {
|
|
58
|
+
credentials: 'include',
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: this.auth
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
67
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/security.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
+
import { getGeoServerResponseText, GeoServerResponseError } from './util/geoserver.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Client for GeoServer security.
|
|
@@ -10,39 +11,34 @@ export default class SecurityClient {
|
|
|
10
11
|
* Creates a GeoServer REST SecurityClient instance.
|
|
11
12
|
*
|
|
12
13
|
* @param {String} url The URL of the GeoServer REST API endpoint
|
|
13
|
-
* @param {String}
|
|
14
|
-
* @param {String} password The password for the GeoServer REST API
|
|
14
|
+
* @param {String} auth The Basic Authentication string
|
|
15
15
|
*/
|
|
16
|
-
constructor (url,
|
|
17
|
-
this.url = url
|
|
18
|
-
this.
|
|
19
|
-
this.password = password;
|
|
16
|
+
constructor (url, auth) {
|
|
17
|
+
this.url = url;
|
|
18
|
+
this.auth = auth;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
// TODO: I could not get it working, got Code '406'
|
|
23
21
|
/**
|
|
24
22
|
* Returns all users registered in GeoServer.
|
|
23
|
+
*
|
|
24
|
+
* @throws Error if request fails
|
|
25
|
+
*
|
|
26
|
+
* @returns {Object} An object with all users
|
|
25
27
|
*/
|
|
26
28
|
async getAllUsers () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: 'Basic ' + auth
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (response.status === 200) {
|
|
38
|
-
return await response.json();
|
|
39
|
-
} else {
|
|
40
|
-
console.warn(await response.text());
|
|
41
|
-
return false;
|
|
29
|
+
const response = await fetch(this.url + 'security/usergroup/users.json', {
|
|
30
|
+
credentials: 'include',
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: this.auth
|
|
42
34
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
39
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
45
40
|
}
|
|
41
|
+
return response.json();
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
/**
|
|
@@ -51,7 +47,7 @@ export default class SecurityClient {
|
|
|
51
47
|
* @param {String} username The name of the user to be created
|
|
52
48
|
* @param {String} password The password of the user to be created
|
|
53
49
|
*
|
|
54
|
-
* @
|
|
50
|
+
* @throws Error if request fails
|
|
55
51
|
*/
|
|
56
52
|
async createUser (username, password) {
|
|
57
53
|
const body = {
|
|
@@ -62,28 +58,24 @@ export default class SecurityClient {
|
|
|
62
58
|
}
|
|
63
59
|
};
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
body: JSON.stringify(body)
|
|
75
|
-
});
|
|
61
|
+
const response = await fetch(this.url + 'security/usergroup/users.json', {
|
|
62
|
+
credentials: 'include',
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: this.auth,
|
|
66
|
+
'Content-Type': 'application/json'
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body)
|
|
69
|
+
});
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
73
|
+
switch (response.status) {
|
|
74
|
+
case 404:
|
|
75
|
+
throw new GeoServerResponseError(`User ${username} might already exists.`, geoServerResponse);
|
|
76
|
+
default:
|
|
77
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
84
78
|
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
return false;
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
81
|
|
|
@@ -95,7 +87,7 @@ export default class SecurityClient {
|
|
|
95
87
|
* @param {String} password The password of the user to be created
|
|
96
88
|
* @param {Boolean} enabled Enable / disable the user
|
|
97
89
|
*
|
|
98
|
-
* @
|
|
90
|
+
* @throws Error if request fails
|
|
99
91
|
*/
|
|
100
92
|
async updateUser (username, password, enabled) {
|
|
101
93
|
const body = {
|
|
@@ -105,26 +97,19 @@ export default class SecurityClient {
|
|
|
105
97
|
}
|
|
106
98
|
};
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
body: JSON.stringify(body)
|
|
118
|
-
});
|
|
100
|
+
const response = await fetch(this.url + 'security/usergroup/user/' + username, {
|
|
101
|
+
credentials: 'include',
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: this.auth,
|
|
105
|
+
'Content-Type': 'application/json'
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(body)
|
|
108
|
+
});
|
|
119
109
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
console.warn(await response.text());
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
return false;
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
112
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
128
113
|
}
|
|
129
114
|
}
|
|
130
115
|
|
|
@@ -134,28 +119,20 @@ export default class SecurityClient {
|
|
|
134
119
|
* @param {String} username The name of the user to add the role to
|
|
135
120
|
* @param {String} role The role to associate
|
|
136
121
|
*
|
|
137
|
-
* @
|
|
122
|
+
* @throws Error if request fails
|
|
138
123
|
*/
|
|
139
124
|
async associateUserRole (username, role) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
method: 'POST',
|
|
146
|
-
headers: {
|
|
147
|
-
Authorization: 'Basic ' + auth
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
if (response.status === 200) {
|
|
152
|
-
return true;
|
|
153
|
-
} else {
|
|
154
|
-
console.warn(await response.text());
|
|
155
|
-
return false;
|
|
125
|
+
const response = await fetch(`${this.url}security/roles/role/${role}/user/${username}`, {
|
|
126
|
+
credentials: 'include',
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
Authorization: this.auth
|
|
156
130
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
const geoServerResponse = await getGeoServerResponseText(response);
|
|
135
|
+
throw new GeoServerResponseError(null, geoServerResponse);
|
|
159
136
|
}
|
|
160
137
|
}
|
|
161
138
|
}
|