Skip to content

Commit 36b85de

Browse files
committed
Dont write output if they havent changed. Distinct retry timer on error and success. Re-Read on api write if the target doesnt respond with data. json_query possible on read
1 parent 7e60025 commit 36b85de

File tree

10 files changed

+671
-139
lines changed

10 files changed

+671
-139
lines changed

Cargo.lock

Lines changed: 180 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kuberest"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
authors = ["Sébastien Huss <sebastien.huss@gmail.com>"]
55
edition = "2021"
66
default-run = "controller"
@@ -26,7 +26,7 @@ operator = { cmd=[
2626
]}
2727
precommit = { cmd=[
2828
"cargo update",
29-
"cargo clippy --fix --allow-dirty",
29+
"cargo clippy --fix --allow-dirty --allow-staged",
3030
"cargo cmd generate",
3131
"cargo +nightly fmt"
3232
]}
@@ -81,6 +81,7 @@ base64 = "0.22.1"
8181
rand = "0.8.5"
8282
argon2 = { version = "0.5.3", features = ["std"] }
8383
bcrypt = "0.16.0"
84+
serde_json_path = "0.7.1"
8485

8586
[dev-dependencies]
8687
assert-json-diff = "2.0.2"

charts/kuberest/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: kuberest
33
description: Allow to Control remote REST api endpoints from the confort of your cluster
44
type: application
5-
version: "1.2.0"
6-
appVersion: "1.2.0"
5+
version: "1.3.0"
6+
appVersion: "1.3.0"

deploy/crd/crd.yaml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
description: Describe the specification of a RestEndPoint
3737
properties:
3838
checkFrequency:
39-
description: 'checkFrequency define the pooling interval (in seconds, default: 300)'
39+
description: 'checkFrequency define the pooling interval (in seconds, default: 3600 aka 1h)'
4040
format: uint64
4141
minimum: 0.0
4242
nullable: true
@@ -258,12 +258,20 @@ spec:
258258
items:
259259
description: readGroupItem describe an object to read with the client
260260
properties:
261+
json_query:
262+
description: Get the result from a json-query
263+
nullable: true
264+
type: string
261265
key:
262266
description: configuration of this object
263267
type: string
264268
name:
265269
description: name of the item (used for handlebars renders)
266270
type: string
271+
optional:
272+
description: Allow missing object (default false)
273+
nullable: true
274+
type: boolean
267275
required:
268276
- key
269277
- name
@@ -288,6 +296,12 @@ spec:
288296
type: object
289297
nullable: true
290298
type: array
299+
retryFrequency:
300+
description: 'retryFrequency define the pooling interval if previous try have failed (in seconds, default: 300 aka 5mn)'
301+
format: uint64
302+
minimum: 0.0
303+
nullable: true
304+
type: integer
291305
teardown:
292306
description: A rhai teardown-script for a final cleanup on RestEndPoint deletion
293307
nullable: true
@@ -315,7 +329,7 @@ spec:
315329
description: writeGroup describe a rest endpoint within the client sub-paths,
316330
properties:
317331
createMethod:
318-
description: 'Method to use when creating an object (default: Get)'
332+
description: 'Method to use when creating an object (default: Post)'
319333
enum:
320334
- Post
321335
nullable: true
@@ -334,6 +348,14 @@ spec:
334348
name:
335349
description: 'name of the item (used for handlebars renders: write.<group>.<name>)'
336350
type: string
351+
readJsonQuery:
352+
description: If writes doesnt return values, (only used when readPath is specified too)
353+
nullable: true
354+
type: string
355+
readPath:
356+
description: If writes doesnt return values, use this read query to re-read
357+
nullable: true
358+
type: string
337359
teardown:
338360
description: 'Delete the Object on RestEndPoint deletion (default: true, inability to do so will block RestEndPoint)'
339361
nullable: true
@@ -361,7 +383,7 @@ spec:
361383
description: path appended to the client's baseurl for this group of objects
362384
type: string
363385
readMethod:
364-
description: 'Method to use when reading an object (default: Post)'
386+
description: 'Method to use when reading an object (default: Get)'
365387
enum:
366388
- Get
367389
nullable: true
@@ -378,6 +400,10 @@ spec:
378400
- Post
379401
nullable: true
380402
type: string
403+
updatePath:
404+
description: Path to use to update/delete this write_group
405+
nullable: true
406+
type: string
381407
required:
382408
- items
383409
- name
@@ -422,6 +448,8 @@ spec:
422448
- PostScriptFailed
423449
- TeardownScriptFailed
424450
- ReadFailed
451+
- ReadMissing
452+
- ReReadFailed
425453
- WriteFailed
426454
- WriteDeleteFailed
427455
- WriteAlreadyExist

deploy/operator/deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
labels:
99
app: kuberest
1010
app.kubernetes.io/name: kuberest
11-
app.kubernetes.io/version: "1.2.0"
11+
app.kubernetes.io/version: "1.3.0"
1212
namespace: default
1313
automountServiceAccountToken: true
1414
---
@@ -102,7 +102,7 @@ metadata:
102102
labels:
103103
app: kuberest
104104
app.kubernetes.io/name: kuberest
105-
app.kubernetes.io/version: "1.2.0"
105+
app.kubernetes.io/version: "1.3.0"
106106
spec:
107107
type: ClusterIP
108108
ports:
@@ -122,7 +122,7 @@ metadata:
122122
labels:
123123
app: kuberest
124124
app.kubernetes.io/name: kuberest
125-
app.kubernetes.io/version: "1.2.0"
125+
app.kubernetes.io/version: "1.3.0"
126126
spec:
127127
replicas: 1
128128
selector:
@@ -140,7 +140,7 @@ spec:
140140
{}
141141
containers:
142142
- name: kuberest
143-
image: sebt3/kuberest:1.2.0
143+
image: sebt3/kuberest:1.3.0
144144
imagePullPolicy: IfNotPresent
145145
securityContext:
146146
{}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
apiVersion: kuberest.solidite.fr/v1
2+
kind: RestEndPoint
3+
metadata:
4+
name: gitea-org-images
5+
spec:
6+
inputs:
7+
- name: admin
8+
secretRef:
9+
name: gitea-admin-user
10+
client:
11+
baseurl: https://gitea.your-company.com/api/v1
12+
headers:
13+
Authorization: '{{ header_basic (base64_decode input.admin.data.username) (base64_decode input.admin.data.password) }}'
14+
writes:
15+
- name: orgs
16+
path: orgs
17+
keyName: username
18+
items:
19+
- name: org
20+
values: |
21+
username: images
22+
visibility: public
23+
repo_admin_change_team_access: true
24+
- name: teams
25+
path: orgs/images/teams
26+
updatePath: teams
27+
items:
28+
- name: dev
29+
values: |-
30+
name: dev
31+
includes_all_repositories: true
32+
can_create_org_repo: false
33+
permission: read
34+
units:
35+
- repo.issues
36+
- repo.ext_issues
37+
- repo.releases
38+
- repo.ext_wiki
39+
- repo.projects
40+
- repo.actions
41+
- repo.code
42+
- repo.pulls
43+
- repo.wiki
44+
- repo.packages
45+
units_map:
46+
repo.actions: write
47+
repo.code: write
48+
repo.ext_issues: read
49+
repo.ext_wiki: read
50+
repo.issues: write
51+
repo.packages: write
52+
repo.projects: write
53+
repo.pulls: write
54+
repo.releases: read
55+
repo.wiki: write
56+
- name: qa
57+
values: |-
58+
name: qa
59+
includes_all_repositories: true
60+
can_create_org_repo: false
61+
permission: read
62+
units:
63+
- repo.issues
64+
- repo.ext_issues
65+
- repo.releases
66+
- repo.ext_wiki
67+
- repo.projects
68+
- repo.actions
69+
- repo.code
70+
- repo.pulls
71+
- repo.wiki
72+
- repo.packages
73+
units_map:
74+
repo.actions: read
75+
repo.code: read
76+
repo.ext_issues: read
77+
repo.ext_wiki: read
78+
repo.issues: write
79+
repo.packages: read
80+
repo.projects: write
81+
repo.pulls: read
82+
repo.releases: read
83+
repo.wiki: write
84+
- name: read
85+
values: |-
86+
name: read
87+
includes_all_repositories: true
88+
can_create_org_repo: false
89+
permission: read
90+
units:
91+
- repo.issues
92+
- repo.ext_issues
93+
- repo.releases
94+
- repo.ext_wiki
95+
- repo.projects
96+
- repo.actions
97+
- repo.code
98+
- repo.pulls
99+
- repo.wiki
100+
- repo.packages
101+
units_map:
102+
repo.actions: read
103+
repo.code: read
104+
repo.ext_issues: read
105+
repo.ext_wiki: read
106+
repo.issues: read
107+
repo.packages: read
108+
repo.projects: read
109+
repo.pulls: read
110+
repo.releases: read
111+
repo.wiki: read

examples/harbor/mirror-docker.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: kuberest.solidite.fr/v1
2+
kind: RestEndPoint
3+
metadata:
4+
name: harbor-mirror-docker
5+
spec:
6+
inputs:
7+
- name: admin
8+
secretRef:
9+
name: harbor-basic
10+
client:
11+
baseurl: https://harbor.your-company.com/api/v2.0
12+
headers:
13+
Authorization: '{{ header_basic "admin" (base64_decode input.admin.data.HARBOR_ADMIN_PASSWORD) }}'
14+
writes:
15+
- name: registries
16+
path: registries
17+
updateMethod: Put
18+
items:
19+
- name: mirror
20+
readPath: registries?name=docker
21+
readJsonQuery: $[0]
22+
values: |
23+
name: docker
24+
url: https://hub.docker.com
25+
type: docker-hub
26+
- name: projects
27+
path: projects
28+
updateMethod: Put
29+
keyName: project_id
30+
items:
31+
- name: mirror
32+
readPath: projects?name=docker
33+
readJsonQuery: $[0]
34+
values: |-
35+
project_name: docker
36+
public: true
37+
registry_id: {{ write.registries.mirror.id }}

src/httphandler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ impl RestClient {
106106
}
107107

108108
pub fn add_header_json_accept(&mut self) -> &mut RestClient {
109-
for (key, val) in self.headers.clone() {
109+
/*for (key, val) in self.headers.clone() {
110110
debug!("RestClient.header: {:} {:}", key, val);
111-
}
111+
}*/
112112
if self.headers.clone().into_iter().any(|(c, _)| c == *"Accept") {
113113
self
114114
} else {

0 commit comments

Comments
 (0)