@jfvilas/kwirth-common 0.2.1 → 0.2.2

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.
@@ -0,0 +1,19 @@
1
+ declare class AccessKey {
2
+ id: string;
3
+ type: string;
4
+ resource: string;
5
+ }
6
+ declare function accessKeyCreate(type: string, resource: string): AccessKey;
7
+ declare function accessKeyBuild(id: string, type: string, resource: string): AccessKey;
8
+ declare function accessKeySerialize(accessKey: AccessKey): string;
9
+ declare function accessKeyDeserialize(key: string): AccessKey;
10
+ declare function parseResource(key: string): ResourceIdentifier;
11
+ declare function buildResource(scope: string, namespace: string, groupType: string, groupName: string, pod: string, container: string): string;
12
+ interface ResourceIdentifier {
13
+ scope: string;
14
+ namespace: string;
15
+ set: string;
16
+ pod: string;
17
+ container: string;
18
+ }
19
+ export { accessKeyBuild, accessKeyCreate, accessKeyDeserialize, accessKeySerialize, AccessKey, parseResource, ResourceIdentifier, buildResource };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildResource = exports.parseResource = exports.AccessKey = exports.accessKeySerialize = exports.accessKeyDeserialize = exports.accessKeyCreate = exports.accessKeyBuild = void 0;
7
+ const guid_1 = __importDefault(require("guid"));
8
+ /*
9
+ Access key format is:
10
+
11
+ id|type|resource
12
+
13
+ where:
14
+ id: is a GUID
15
+ type: is volatile' or 'permanent' (the second type is persisted when created)
16
+ resource: is a stringified ResourceIdentifier
17
+ */
18
+ class AccessKey {
19
+ constructor() {
20
+ this.id = '';
21
+ this.type = 'volatile';
22
+ this.resource = '';
23
+ }
24
+ }
25
+ exports.AccessKey = AccessKey;
26
+ function accessKeyCreate(type, resource) {
27
+ var accessKey = new AccessKey();
28
+ accessKey.id = guid_1.default.create().toString();
29
+ accessKey.type = type;
30
+ accessKey.resource = resource;
31
+ return accessKey;
32
+ }
33
+ exports.accessKeyCreate = accessKeyCreate;
34
+ function accessKeyBuild(id, type, resource) {
35
+ var accessKey = new AccessKey();
36
+ accessKey.id = id;
37
+ accessKey.type = type;
38
+ accessKey.resource = resource;
39
+ return accessKey;
40
+ }
41
+ exports.accessKeyBuild = accessKeyBuild;
42
+ function accessKeySerialize(accessKey) {
43
+ return `${accessKey.id}|${accessKey.type}|${accessKey.resource}`;
44
+ }
45
+ exports.accessKeySerialize = accessKeySerialize;
46
+ function accessKeyDeserialize(key) {
47
+ var parts = key.split('|');
48
+ return accessKeyBuild(parts[0], parts[1], parts[2]);
49
+ }
50
+ exports.accessKeyDeserialize = accessKeyDeserialize;
51
+ function parseResource(key) {
52
+ var parts = key.split(':');
53
+ return {
54
+ scope: parts[0],
55
+ namespace: parts[1],
56
+ set: parts[2],
57
+ pod: parts[3],
58
+ container: parts[4]
59
+ };
60
+ }
61
+ exports.parseResource = parseResource;
62
+ function buildResource(scope, namespace, groupType, groupName, pod, container) {
63
+ return `${scope}:${namespace}:${groupType}+${groupName}:${pod}:${container}`;
64
+ }
65
+ exports.buildResource = buildResource;
@@ -1,4 +1,7 @@
1
1
  export interface StreamMessage {
2
+ namespace?: string;
3
+ podName?: string;
2
4
  type: string;
3
5
  text: string;
6
+ timestamp?: Date;
4
7
  }
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { StreamMessage } from './Interfaces';
1
+ export * from './StreamMessage';
package/dist/index.js CHANGED
@@ -1,2 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ Copyright 2024 Julio Fernandez
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
31
+ */
32
+ __exportStar(require("./StreamMessage"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jfvilas/kwirth-common",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Common interfaces for integrating applications with Kwirth",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/jfvilas/kwirth-common.git"
12
- },
12
+ },
13
13
  "keywords": [
14
14
  "kwrith",
15
15
  "kubernetes",
@@ -22,5 +22,11 @@
22
22
  "bugs": {
23
23
  "url": "https://github.com/jfvilas/kwirth-common/issues"
24
24
  },
25
- "homepage": "https://github.com/jfvilas/kwirth-common#readme"
25
+ "homepage": "https://github.com/jfvilas/kwirth-common#readme",
26
+ "dependencies": {
27
+ "guid": "^0.0.12"
28
+ },
29
+ "devDependencies": {
30
+ "@types/guid": "^1.0.3"
31
+ }
26
32
  }
@@ -0,0 +1,122 @@
1
+ import Guid from 'guid';
2
+
3
+ /*
4
+ Access key format is:
5
+
6
+ id|type|resource
7
+
8
+ where:
9
+ id: is a GUID
10
+ type: is volatile' or 'permanent' (the second type is persisted when created)
11
+ resource: is a stringified ResourceIdentifier
12
+ */
13
+ class AccessKey {
14
+ public id:string='';
15
+ public type:string='volatile';
16
+ public resource:string='';
17
+ }
18
+
19
+ function accessKeyCreate(type:string, resource:string) : AccessKey {
20
+ var accessKey=new AccessKey();
21
+ accessKey.id=Guid.create().toString();
22
+ accessKey.type=type;
23
+ accessKey.resource=resource;
24
+ return accessKey;
25
+ }
26
+
27
+ function accessKeyBuild(id:string, type:string, resource:string) : AccessKey {
28
+ var accessKey=new AccessKey();
29
+ accessKey.id=id;
30
+ accessKey.type=type;
31
+ accessKey.resource=resource;
32
+ return accessKey;
33
+ }
34
+
35
+ function accessKeySerialize (accessKey:AccessKey) : string {
36
+ return `${accessKey.id}|${accessKey.type}|${accessKey.resource}`;
37
+ }
38
+
39
+ function accessKeyDeserialize (key:string) : AccessKey {
40
+ var parts=key.split('|');
41
+ return accessKeyBuild(parts[0], parts[1], parts[2]);
42
+ }
43
+
44
+ function parseResource (key:string) : ResourceIdentifier {
45
+ var parts=key.split(':');
46
+ return {
47
+ scope:parts[0],
48
+ namespace:parts[1],
49
+ set:parts[2],
50
+ pod:parts[3],
51
+ container:parts[4]
52
+ }
53
+ }
54
+
55
+ function buildResource (scope:string, namespace:string, groupType:string, groupName:string, pod:string, container:string) : string {
56
+ return `${scope}:${namespace}:${groupType}+${groupName}:${pod}:${container}`;
57
+ }
58
+
59
+ /*
60
+ ResourceIdentifier is composed by:
61
+
62
+ scope can a comma-separated list of: cluster, api, view|filter, restart
63
+ cluster is the admin level, can do everything
64
+ api can create api keys
65
+ view or filter, can view logs
66
+ restart, can restart pods or deployments
67
+
68
+ for example, a user that can view and restart would have the scope 'view,restart'
69
+
70
+ NOTE: group is the type and name of a group: 'replica', 'stateful' or 'daemon', a plus sign ('+'), and the name of the group, example: 'replica+rs1', 'stateful+mongo'
71
+
72
+ the rest of fields are names (regex in fact) according to this rules:
73
+ - it can be a direct name, like: 'mynamespace', 'your-replicaset', 'our-pod'...
74
+ - it can be an '', indicating any resource of the scope is valid
75
+ - it can be a comma-separated list of names, like: namespace 'dev,pre', or pod 'my-pod,our-pod,your-pod'
76
+
77
+ full access is created by using cluster scope:
78
+ scope: cluster
79
+ namespace: ''
80
+ set: ''
81
+ pod: ''
82
+ container: ''
83
+
84
+ for example, an accessKey that gives access to view logs of namespaces production and staging would be something like
85
+ scope: view
86
+ namespace: ['production','staging']
87
+ set: ''
88
+ pod: ''
89
+ container: ''
90
+
91
+ access to restart any pod in 'development' namespace is like this:
92
+ scope: restart
93
+ namespace: 'development'
94
+ set: ''
95
+ pod: ''
96
+ container: ''
97
+
98
+ an accessKey that allows viewing logs of pod 'my-pod' in the whole cluster would be something like:
99
+ scope: view
100
+ namespace: ''
101
+ set: ''
102
+ pod: my-pod
103
+ container: ''
104
+
105
+ the names are infact regex, so you, for allowing a requestor to restart any pod of the accounting application in preproduction environment you would use this:
106
+ scope: restart
107
+ namespace: 'preproduction'
108
+ set: ''
109
+ pod: '^account-'
110
+ container: ''
111
+
112
+ */
113
+
114
+ interface ResourceIdentifier {
115
+ scope:string,
116
+ namespace:string,
117
+ set:string,
118
+ pod:string,
119
+ container:string
120
+ }
121
+
122
+ export { accessKeyBuild, accessKeyCreate, accessKeyDeserialize, accessKeySerialize, AccessKey, parseResource, ResourceIdentifier, buildResource };
@@ -0,0 +1,7 @@
1
+ export interface StreamMessage {
2
+ namespace?:string,
3
+ podName?:string,
4
+ type:string,
5
+ text:string,
6
+ timestamp?:Date
7
+ }
package/src/index.ts CHANGED
@@ -13,4 +13,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
- export { StreamMessage} from './Interfaces'
16
+ export * from './StreamMessage'
package/src/Interfaces.ts DELETED
@@ -1,19 +0,0 @@
1
- /*
2
- Copyright 2024 Julio Fernandez
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
- export interface StreamMessage {
17
- type: string;
18
- text: string;
19
- }
File without changes