/
data.go
793 lines (729 loc) · 17.1 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
// Copyright 2018 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package data
import (
"io/ioutil"
"strings"
)
// ServiceConfig is a standard service config.
var ServiceConfig = `
apiVersion: "config.istio.io/v1alpha2"
kind: attributemanifest
metadata:
name: istio-proxy
namespace: default
spec:
attributes:
source.name:
value_type: STRING
destination.name:
value_type: STRING
response.count:
value_type: INT64
attr.bool:
value_type: BOOL
attr.string:
value_type: STRING
attr.double:
value_type: DOUBLE
attr.int64:
value_type: INT64
---
`
// InstanceCheck1 is a standard testing instance for template tcheck.
var InstanceCheck1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tcheck
metadata:
name: icheck1
namespace: istio-system
spec:
`
// FqnI1 is the fully qualified name for I1.
var FqnI1 = "icheck1.tcheck.istio-system"
// InstanceCheck2 is another instance.
var InstanceCheck2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tcheck
metadata:
name: icheck2
namespace: istio-system
spec:
`
// InstanceCheck3 is another instance.
var InstanceCheck3 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tcheck
metadata:
name: icheck3
namespace: istio-system
spec:
`
// InstanceCheck4NS2 is in the ns2 namespace
var InstanceCheck4NS2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tcheck
metadata:
name: icheck4
namespace: ns2
spec:
`
// InstanceCheck1WithSpec has a spec with expressions
var InstanceCheck1WithSpec = `
apiVersion: "config.istio.io/v1alpha2"
kind: tcheck
metadata:
name: icheck1
namespace: istio-system
spec:
foo: attr.string
`
// InstanceCheckOutput1 is a standard testing instance for template tcheckoutput
var InstanceCheckOutput1 = `
apiVersion: config.istio.io/v1alpha2
kind: tcheckoutput
metadata:
name: icheckoutput1
namespace: istio-system
`
// InstanceHalt1 is a standard testing instance.
var InstanceHalt1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: thalt
metadata:
name: ihalt1
namespace: istio-system
spec:
`
// InstanceReport1 is a standard testing instance for template treport.
var InstanceReport1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: treport
metadata:
name: ireport1
namespace: istio-system
spec:
`
// InstanceReport1WithSpec has a spec with expressions
var InstanceReport1WithSpec = `
apiVersion: "config.istio.io/v1alpha2"
kind: treport
metadata:
name: ireport1
namespace: istio-system
spec:
foo: attr.string
`
// InstanceReport2 is a standard testing instance for template treport.
var InstanceReport2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: treport
metadata:
name: ireport2
namespace: istio-system
spec:
`
// InstanceQuota1 is a standard testing instance for template tquota.
var InstanceQuota1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tquota
metadata:
name: iquota1
namespace: istio-system
spec:
`
// InstanceQuota2 is a copy of InstanceQuota1 with a different name.
var InstanceQuota2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tquota
metadata:
name: iquota2
namespace: istio-system
spec:
`
// InstanceQuota1WithSpec has a spec with expressions
var InstanceQuota1WithSpec = `
apiVersion: "config.istio.io/v1alpha2"
kind: tquota
metadata:
name: iquota1
namespace: istio-system
spec:
foo: attr.string
`
// InstanceAPA1 is an APA instance
var InstanceAPA1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: tapa
metadata:
name: iapa1
namespace: istio-system
spec:
`
// InstanceAPA1WithSpec has a spec with expressions
var InstanceAPA1WithSpec = `
apiVersion: "config.istio.io/v1alpha2"
kind: tapa
metadata:
name: iapa1
namespace: istio-system
spec:
foo: attr.string
attribute_bindings:
source.name: $out.generated.string | ""
`
// HandlerACheck1 is a handler of type acheck with name hcheck1.
var HandlerACheck1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: acheck
metadata:
name: hcheck1
namespace: istio-system
spec:
`
// FqnACheck1 is the fully qualified name of HandlerH1.
var FqnACheck1 = "hcheck1.acheck.istio-system"
// HandlerACheck2 is a handler of type acheck with name hcheck2.
var HandlerACheck2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: acheck
metadata:
name: hcheck2
namespace: istio-system
spec:
`
// HandlerACheck3NS2 is a handler in namespace NS2.
var HandlerACheck3NS2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: acheck
metadata:
name: hcheck3
namespace: ns2
spec:
`
// HandlerACheckOutput1 is a standard handler for type acheckoutput
var HandlerACheckOutput1 = `
apiVersion: config.istio.io/v1alpha2
kind: acheckoutput
metadata:
name: hcheckoutput1
namespace: istio-system
`
// HandlerAReport1 is a handler of type acheck with name hreport1.
var HandlerAReport1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: areport
metadata:
name: hreport1
namespace: istio-system
spec:
`
// FqnAReport1 is the fully qualified name of HandlerAReport1.
var FqnAReport1 = "hreport1.areport.istio-system"
// HandlerAQuota1 is a handler of type aquota with name hquota1.
var HandlerAQuota1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: aquota
metadata:
name: hquota1
namespace: istio-system
spec:
`
// FqnAQuota1 is the fully qualified name of HandlerAReport1.
var FqnAQuota1 = "hquota1.aquota.istio-system"
// HandlerAPA1 is an APA handler.
var HandlerAPA1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: apa
metadata:
name: hapa1
namespace: istio-system
spec:
`
// RuleCheck1 is a standard testing instance config with name R1. It references I1 and H1.
var RuleCheck1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck1TrueCondition is a standard testing instance config with name R1. It references I1 and H1.
var RuleCheck1TrueCondition = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
selector: 'true'
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck1WithBadCondition has a parseable but not compilable condition
var RuleCheck1WithBadCondition = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
selector: needmorecheese
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck1WithInstance1And2 has instances icheck1 & icheck2.
var RuleCheck1WithInstance1And2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
- icheck2.tcheck.istio-system
`
// RuleCheck1WithInstance1And2Operation has instances icheck1 & icheck2 and a header operation
var RuleCheck1WithInstance1And2Operation = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
- icheck2.tcheck.istio-system
requestHeaderOperations:
- name: a-header
values:
- '"test"'
responseHeaderOperations:
- name: b-header
values:
- '"test"'
`
// RuleCheck1WithMatchClause is Rule Check1 with a conditional.
var RuleCheck1WithMatchClause = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
match: match(destination.name, "foo*")
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck1WithInstance1And2WithMatchClause is Rule Check1 with a conditional.
var RuleCheck1WithInstance1And2WithMatchClause = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
match: match(destination.name, "foo*")
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
- icheck2.tcheck.istio-system
`
// RuleCheck1WithBadHandler is a standard testing rule config with a bad handler name.
var RuleCheck1WithBadHandler = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
actions:
- handler: hcheck1.inspector-gadget
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck1WithNonBooleanCondition has a non-boolean condition.
var RuleCheck1WithNonBooleanCondition = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: istio-system
spec:
selector: destination.name
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck2WithInstance1AndHandler is Rule Check1 with a different name.
var RuleCheck2WithInstance1AndHandler = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck2
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
`
// RuleCheck2WithInstance2And3 references instances icheck2 and icheck2.
var RuleCheck2WithInstance2And3 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck2
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck2.tcheck.istio-system
- icheck3.tcheck.istio-system
`
// RuleCheck2WithInstance2And3WithMatchClause is RuleCheck2WithInstance2And3 with a conditional.
var RuleCheck2WithInstance2And3WithMatchClause = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck2
namespace: istio-system
spec:
match: destination.name.startsWith("foo")
actions:
- handler: hcheck1.acheck
instances:
- icheck2.tcheck.istio-system
- icheck3.tcheck.istio-system
`
// RuleCheck2WithHandler2AndInstance2 references hcheck2 and icheck2.
var RuleCheck2WithHandler2AndInstance2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck2
namespace: istio-system
spec:
actions:
- handler: hcheck2.acheck
instances:
- icheck2.tcheck.istio-system
`
// RuleCheck3NS2 is check rule in namespace NS2
var RuleCheck3NS2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheck1
namespace: ns2
spec:
actions:
- handler: hcheck3.acheck
instances:
- icheck4.tcheck.ns2
`
// Rule4CheckAndHalt has two instances that goes to the same adapter, but have different templates.
var Rule4CheckAndHalt = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rcheckandhalt4
namespace: istio-system
spec:
actions:
- handler: hcheck1.acheck
instances:
- icheck1.tcheck.istio-system
- ihalt1.thalt.istio-system
`
// RuleCheckOutput1 is a standard testing rule for check output template
var RuleCheckOutput1 = `
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: rcheckoutput1
namespace: istio-system
spec:
actions:
- handler: hcheckoutput1.acheckoutput
instances:
- icheckoutput1.tcheckoutput.istio-system
name: sample
requestHeaderOperations:
- name: user
values:
- sample.output.value
- name: empty-header
values:
- '""'
`
// RuleCheckOutput2 is a testing rule for check output template with multiple outputs
var RuleCheckOutput2 = `
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: rcheckoutput2
namespace: istio-system
spec:
actions:
- handler: hcheckoutput1.acheckoutput
instances:
- icheckoutput1.tcheckoutput.istio-system
name: a
- handler: hcheckoutput1.acheckoutput
instances:
- icheckoutput1.tcheckoutput.istio-system
name: b
requestHeaderOperations:
- name: a-header
values:
- a.output.value
operation: REPLACE
- name: user
operation: REMOVE
responseHeaderOperations:
- name: b-header
values:
- b.output.value
- prefix.generated.string
operation: APPEND
`
// RuleCheckNoActionsOrHeaderOps has no actions and no responseHeaderOperations. Should be elided.
var RuleCheckNoActionsOrHeaderOps = `
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: noactions
namespace: istio-system
spec:
actions: []
responseHeaderOperations: []
`
// RuleCheckHeaderOpWithNoActions has a responseHeaderOperation, but no actions. Should not be elided.
var RuleCheckHeaderOpWithNoActions = `
apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: noactions
namespace: istio-system
spec:
actions: []
responseHeaderOperations:
- name: b-header
values:
- '"test"'
operation: APPEND
`
// RuleReport1 is a standard testing instance config with name rreport1. It references I1 and H1.
var RuleReport1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rreport1
namespace: istio-system
spec:
actions:
- handler: hreport1.areport
instances:
- ireport1.treport.istio-system
`
// RuleReport1And2 is a standard testing instance config with name rreport1.
var RuleReport1And2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rreport1
namespace: istio-system
spec:
actions:
- handler: hreport1.areport
instances:
- ireport1.treport.istio-system
- ireport2.treport.istio-system
`
// RuleQuota1 is a standard testing instance config with name rquota1. It references I1 and H1.
var RuleQuota1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rquota1
namespace: istio-system
spec:
actions:
- handler: hquota1.aquota
instances:
- iquota1.tquota.istio-system
`
// RuleQuota1Conditional conditionally selects iquota1
var RuleQuota1Conditional = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rquota1
namespace: istio-system
spec:
match: attr.string == "select"
actions:
- handler: hquota1.aquota
instances:
- iquota1.tquota.istio-system
`
// RuleQuota2 references iquota1 and hquota1.
var RuleQuota2 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rquota2
namespace: istio-system
spec:
actions:
- handler: hquota1.aquota
instances:
- iquota2.tquota.istio-system
`
// RuleApa1 is a rule that target APA.
var RuleApa1 = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rapa1
namespace: istio-system
spec:
actions:
- handler: hapa1.apa
instances:
- iapa1.tapa.istio-system
`
// ListHandler1 is a dynamic handler of listentry template named as hdynlist1
var ListHandler1 = `
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: hdynlist1
namespace: istio-system
spec:
adapter: listbackend-nosession
connection:
address: 127.0.0.1:8080
params:
provider_url: google.com
overrides:
- a
- b
caching_interval: 5s
`
// ListHandler2 is a dynamic handler of listentry template named as hdynlist2
var ListHandler2 = `
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: hdynlist2
namespace: istio-system
spec:
adapter: listbackend-nosession
connection:
address: 127.0.0.1:8080
params:
refresh_interval: 5s
caching_use_count: 50
`
// ListHandler3 is a dynamic handler of listentry template named as hdynlist3
var ListHandler3 = `
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: hdynlist3
namespace: istio-system
spec:
adapter: listbackend-nosession
connection:
address: 127.0.0.1:8080
params:
blacklist: true
`
// ListHandler3Addr is a dynamic handler that is same as ListHandler3 but has different backend address
var ListHandler3Addr = `
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: hdynlist3
namespace: istio-system
spec:
adapter: listbackend-nosession
connection:
address: 127.0.0.1:8081
params:
blacklist: true
`
// FqdnListHandler3 is fqdn of ListHandler3
var FqdnListHandler3 = "hdynlist3.handler.istio-system"
// InstanceDynamic is the instance of the template listentry
var InstanceDynamic = `
apiVersion: "config.istio.io/v1alpha2"
kind: instance
metadata:
name: idynlistentry1
namespace: istio-system
spec:
template: listentry
params:
`
// RuleDynamic is a testing rule of dynamic instance idynlistentry1 and dynamic handler hdynlist3
var RuleDynamic = `
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: rdynlist1
namespace: istio-system
spec:
actions:
- handler: hdynlist3.handler
instances:
- idynlistentry1.istio-system
`
// JoinConfigs is a utility for joining various pieces of config for consumption by store code.
func JoinConfigs(configs ...string) string {
return strings.Join(configs, "\n---\n")
}
// ReadConfigs reads config from the given path list and returns them as a string.
func ReadConfigs(paths ...string) (string, error) {
cfg := ""
for _, p := range paths {
fc, err := ioutil.ReadFile(p)
if err != nil {
return "", err
}
cfg = JoinConfigs(cfg, string(fc))
}
return cfg, nil
}