-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathbuiltins.go
634 lines (395 loc) · 12.8 KB
/
builtins.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
// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package ast
import (
v1 "github.com/open-policy-agent/opa/v1/ast"
)
// Builtins is the registry of built-in functions supported by OPA.
// Call RegisterBuiltin to add a new built-in.
var Builtins = v1.Builtins
// RegisterBuiltin adds a new built-in function to the registry.
func RegisterBuiltin(b *Builtin) {
v1.RegisterBuiltin(b)
}
// DefaultBuiltins is the registry of built-in functions supported in OPA
// by default. When adding a new built-in function to OPA, update this
// list.
var DefaultBuiltins = v1.DefaultBuiltins
// BuiltinMap provides a convenient mapping of built-in names to
// built-in definitions.
var BuiltinMap = v1.BuiltinMap
// Deprecated: Builtins can now be directly annotated with the
// Nondeterministic property, and when set to true, will be ignored
// for partial evaluation.
var IgnoreDuringPartialEval = v1.IgnoreDuringPartialEval
/**
* Unification
*/
// Equality represents the "=" operator.
var Equality = v1.Equality
/**
* Assignment
*/
// Assign represents the assignment (":=") operator.
var Assign = v1.Assign
// Member represents the `in` (infix) operator.
var Member = v1.Member
// MemberWithKey represents the `in` (infix) operator when used
// with two terms on the lhs, i.e., `k, v in obj`.
var MemberWithKey = v1.MemberWithKey
var GreaterThan = v1.GreaterThan
var GreaterThanEq = v1.GreaterThanEq
// LessThan represents the "<" comparison operator.
var LessThan = v1.LessThan
var LessThanEq = v1.LessThanEq
var NotEqual = v1.NotEqual
// Equal represents the "==" comparison operator.
var Equal = v1.Equal
var Plus = v1.Plus
var Minus = v1.Minus
var Multiply = v1.Multiply
var Divide = v1.Divide
var Round = v1.Round
var Ceil = v1.Ceil
var Floor = v1.Floor
var Abs = v1.Abs
var Rem = v1.Rem
/**
* Bitwise
*/
var BitsOr = v1.BitsOr
var BitsAnd = v1.BitsAnd
var BitsNegate = v1.BitsNegate
var BitsXOr = v1.BitsXOr
var BitsShiftLeft = v1.BitsShiftLeft
var BitsShiftRight = v1.BitsShiftRight
/**
* Sets
*/
var And = v1.And
// Or performs a union operation on sets.
var Or = v1.Or
var Intersection = v1.Intersection
var Union = v1.Union
/**
* Aggregates
*/
var Count = v1.Count
var Sum = v1.Sum
var Product = v1.Product
var Max = v1.Max
var Min = v1.Min
/**
* Sorting
*/
var Sort = v1.Sort
/**
* Arrays
*/
var ArrayConcat = v1.ArrayConcat
var ArraySlice = v1.ArraySlice
var ArrayReverse = v1.ArrayReverse
/**
* Conversions
*/
var ToNumber = v1.ToNumber
/**
* Regular Expressions
*/
var RegexMatch = v1.RegexMatch
var RegexIsValid = v1.RegexIsValid
var RegexFindAllStringSubmatch = v1.RegexFindAllStringSubmatch
var RegexTemplateMatch = v1.RegexTemplateMatch
var RegexSplit = v1.RegexSplit
// RegexFind takes two strings and a number, the pattern, the value and number of match values to
// return, -1 means all match values.
var RegexFind = v1.RegexFind
// GlobsMatch takes two strings regexp-style strings and evaluates to true if their
// intersection matches a non-empty set of non-empty strings.
// Examples:
// - "a.a." and ".b.b" -> true.
// - "[a-z]*" and [0-9]+" -> not true.
var GlobsMatch = v1.GlobsMatch
/**
* Strings
*/
var AnyPrefixMatch = v1.AnyPrefixMatch
var AnySuffixMatch = v1.AnySuffixMatch
var Concat = v1.Concat
var FormatInt = v1.FormatInt
var IndexOf = v1.IndexOf
var IndexOfN = v1.IndexOfN
var Substring = v1.Substring
var Contains = v1.Contains
var StringCount = v1.StringCount
var StartsWith = v1.StartsWith
var EndsWith = v1.EndsWith
var Lower = v1.Lower
var Upper = v1.Upper
var Split = v1.Split
var Replace = v1.Replace
var ReplaceN = v1.ReplaceN
var RegexReplace = v1.RegexReplace
var Trim = v1.Trim
var TrimLeft = v1.TrimLeft
var TrimPrefix = v1.TrimPrefix
var TrimRight = v1.TrimRight
var TrimSuffix = v1.TrimSuffix
var TrimSpace = v1.TrimSpace
var Sprintf = v1.Sprintf
var StringReverse = v1.StringReverse
var RenderTemplate = v1.RenderTemplate
/**
* Numbers
*/
// RandIntn returns a random number 0 - n
// Marked non-deterministic because it relies on RNG internally.
var RandIntn = v1.RandIntn
var NumbersRange = v1.NumbersRange
var NumbersRangeStep = v1.NumbersRangeStep
/**
* Units
*/
var UnitsParse = v1.UnitsParse
var UnitsParseBytes = v1.UnitsParseBytes
//
/**
* Type
*/
// UUIDRFC4122 returns a version 4 UUID string.
// Marked non-deterministic because it relies on RNG internally.
var UUIDRFC4122 = v1.UUIDRFC4122
var UUIDParse = v1.UUIDParse
/**
* JSON
*/
var JSONFilter = v1.JSONFilter
var JSONRemove = v1.JSONRemove
var JSONPatch = v1.JSONPatch
var ObjectSubset = v1.ObjectSubset
var ObjectUnion = v1.ObjectUnion
var ObjectUnionN = v1.ObjectUnionN
var ObjectRemove = v1.ObjectRemove
var ObjectFilter = v1.ObjectFilter
var ObjectGet = v1.ObjectGet
var ObjectKeys = v1.ObjectKeys
/*
* Encoding
*/
var JSONMarshal = v1.JSONMarshal
var JSONMarshalWithOptions = v1.JSONMarshalWithOptions
var JSONUnmarshal = v1.JSONUnmarshal
var JSONIsValid = v1.JSONIsValid
var Base64Encode = v1.Base64Encode
var Base64Decode = v1.Base64Decode
var Base64IsValid = v1.Base64IsValid
var Base64UrlEncode = v1.Base64UrlEncode
var Base64UrlEncodeNoPad = v1.Base64UrlEncodeNoPad
var Base64UrlDecode = v1.Base64UrlDecode
var URLQueryDecode = v1.URLQueryDecode
var URLQueryEncode = v1.URLQueryEncode
var URLQueryEncodeObject = v1.URLQueryEncodeObject
var URLQueryDecodeObject = v1.URLQueryDecodeObject
var YAMLMarshal = v1.YAMLMarshal
var YAMLUnmarshal = v1.YAMLUnmarshal
// YAMLIsValid verifies the input string is a valid YAML document.
var YAMLIsValid = v1.YAMLIsValid
var HexEncode = v1.HexEncode
var HexDecode = v1.HexDecode
/**
* Tokens
*/
var JWTDecode = v1.JWTDecode
var JWTVerifyRS256 = v1.JWTVerifyRS256
var JWTVerifyRS384 = v1.JWTVerifyRS384
var JWTVerifyRS512 = v1.JWTVerifyRS512
var JWTVerifyPS256 = v1.JWTVerifyPS256
var JWTVerifyPS384 = v1.JWTVerifyPS384
var JWTVerifyPS512 = v1.JWTVerifyPS512
var JWTVerifyES256 = v1.JWTVerifyES256
var JWTVerifyES384 = v1.JWTVerifyES384
var JWTVerifyES512 = v1.JWTVerifyES512
var JWTVerifyHS256 = v1.JWTVerifyHS256
var JWTVerifyHS384 = v1.JWTVerifyHS384
var JWTVerifyHS512 = v1.JWTVerifyHS512
// Marked non-deterministic because it relies on time internally.
var JWTDecodeVerify = v1.JWTDecodeVerify
// Marked non-deterministic because it relies on RNG internally.
var JWTEncodeSignRaw = v1.JWTEncodeSignRaw
// Marked non-deterministic because it relies on RNG internally.
var JWTEncodeSign = v1.JWTEncodeSign
/**
* Time
*/
// Marked non-deterministic because it relies on time directly.
var NowNanos = v1.NowNanos
var ParseNanos = v1.ParseNanos
var ParseRFC3339Nanos = v1.ParseRFC3339Nanos
var ParseDurationNanos = v1.ParseDurationNanos
var Format = v1.Format
var Date = v1.Date
var Clock = v1.Clock
var Weekday = v1.Weekday
var AddDate = v1.AddDate
var Diff = v1.Diff
/**
* Crypto.
*/
var CryptoX509ParseCertificates = v1.CryptoX509ParseCertificates
var CryptoX509ParseAndVerifyCertificates = v1.CryptoX509ParseAndVerifyCertificates
var CryptoX509ParseAndVerifyCertificatesWithOptions = v1.CryptoX509ParseAndVerifyCertificatesWithOptions
var CryptoX509ParseCertificateRequest = v1.CryptoX509ParseCertificateRequest
var CryptoX509ParseKeyPair = v1.CryptoX509ParseKeyPair
var CryptoX509ParseRSAPrivateKey = v1.CryptoX509ParseRSAPrivateKey
var CryptoParsePrivateKeys = v1.CryptoParsePrivateKeys
var CryptoMd5 = v1.CryptoMd5
var CryptoSha1 = v1.CryptoSha1
var CryptoSha256 = v1.CryptoSha256
var CryptoHmacMd5 = v1.CryptoHmacMd5
var CryptoHmacSha1 = v1.CryptoHmacSha1
var CryptoHmacSha256 = v1.CryptoHmacSha256
var CryptoHmacSha512 = v1.CryptoHmacSha512
var CryptoHmacEqual = v1.CryptoHmacEqual
/**
* Graphs.
*/
var WalkBuiltin = v1.WalkBuiltin
var ReachableBuiltin = v1.ReachableBuiltin
var ReachablePathsBuiltin = v1.ReachablePathsBuiltin
/**
* Type
*/
var IsNumber = v1.IsNumber
var IsString = v1.IsString
var IsBoolean = v1.IsBoolean
var IsArray = v1.IsArray
var IsSet = v1.IsSet
var IsObject = v1.IsObject
var IsNull = v1.IsNull
/**
* Type Name
*/
// TypeNameBuiltin returns the type of the input.
var TypeNameBuiltin = v1.TypeNameBuiltin
/**
* HTTP Request
*/
// Marked non-deterministic because HTTP request results can be non-deterministic.
var HTTPSend = v1.HTTPSend
/**
* GraphQL
*/
// GraphQLParse returns a pair of AST objects from parsing/validation.
var GraphQLParse = v1.GraphQLParse
// GraphQLParseAndVerify returns a boolean and a pair of AST object from parsing/validation.
var GraphQLParseAndVerify = v1.GraphQLParseAndVerify
// GraphQLParseQuery parses the input GraphQL query and returns a JSON
// representation of its AST.
var GraphQLParseQuery = v1.GraphQLParseQuery
// GraphQLParseSchema parses the input GraphQL schema and returns a JSON
// representation of its AST.
var GraphQLParseSchema = v1.GraphQLParseSchema
// GraphQLIsValid returns true if a GraphQL query is valid with a given
// schema, and returns false for all other inputs.
var GraphQLIsValid = v1.GraphQLIsValid
// GraphQLSchemaIsValid returns true if the input is valid GraphQL schema,
// and returns false for all other inputs.
var GraphQLSchemaIsValid = v1.GraphQLSchemaIsValid
/**
* JSON Schema
*/
// JSONSchemaVerify returns empty string if the input is valid JSON schema
// and returns error string for all other inputs.
var JSONSchemaVerify = v1.JSONSchemaVerify
// JSONMatchSchema returns empty array if the document matches the JSON schema,
// and returns non-empty array with error objects otherwise.
var JSONMatchSchema = v1.JSONMatchSchema
/**
* Cloud Provider Helper Functions
*/
var ProvidersAWSSignReqObj = v1.ProvidersAWSSignReqObj
/**
* Rego
*/
var RegoParseModule = v1.RegoParseModule
var RegoMetadataChain = v1.RegoMetadataChain
// RegoMetadataRule returns the metadata for the active rule
var RegoMetadataRule = v1.RegoMetadataRule
/**
* OPA
*/
// Marked non-deterministic because of unpredictable config/environment-dependent results.
var OPARuntime = v1.OPARuntime
/**
* Trace
*/
var Trace = v1.Trace
/**
* Glob
*/
var GlobMatch = v1.GlobMatch
var GlobQuoteMeta = v1.GlobQuoteMeta
/**
* Networking
*/
var NetCIDRIntersects = v1.NetCIDRIntersects
var NetCIDRExpand = v1.NetCIDRExpand
var NetCIDRContains = v1.NetCIDRContains
var NetCIDRContainsMatches = v1.NetCIDRContainsMatches
var NetCIDRMerge = v1.NetCIDRMerge
var NetCIDRIsValid = v1.NetCIDRIsValid
// Marked non-deterministic because DNS resolution results can be non-deterministic.
var NetLookupIPAddr = v1.NetLookupIPAddr
/**
* Semantic Versions
*/
var SemVerIsValid = v1.SemVerIsValid
var SemVerCompare = v1.SemVerCompare
/**
* Printing
*/
// Print is a special built-in function that writes zero or more operands
// to a message buffer. The caller controls how the buffer is displayed. The
// operands may be of any type. Furthermore, unlike other built-in functions,
// undefined operands DO NOT cause the print() function to fail during
// evaluation.
var Print = v1.Print
// InternalPrint represents the internal implementation of the print() function.
// The compiler rewrites print() calls to refer to the internal implementation.
var InternalPrint = v1.InternalPrint
/**
* Deprecated built-ins.
*/
// SetDiff has been replaced by the minus built-in.
var SetDiff = v1.SetDiff
// NetCIDROverlap has been replaced by the `net.cidr_contains` built-in.
var NetCIDROverlap = v1.NetCIDROverlap
// CastArray checks the underlying type of the input. If it is array or set, an array
// containing the values is returned. If it is not an array, an error is thrown.
var CastArray = v1.CastArray
// CastSet checks the underlying type of the input.
// If it is a set, the set is returned.
// If it is an array, the array is returned in set form (all duplicates removed)
// If neither, an error is thrown
var CastSet = v1.CastSet
// CastString returns input if it is a string; if not returns error.
// For formatting variables, see sprintf
var CastString = v1.CastString
// CastBoolean returns input if it is a boolean; if not returns error.
var CastBoolean = v1.CastBoolean
// CastNull returns null if input is null; if not returns error.
var CastNull = v1.CastNull
// CastObject returns the given object if it is null; throws an error otherwise
var CastObject = v1.CastObject
// RegexMatchDeprecated declares `re_match` which has been deprecated. Use `regex.match` instead.
var RegexMatchDeprecated = v1.RegexMatchDeprecated
// All takes a list and returns true if all of the items
// are true. A collection of length 0 returns true.
var All = v1.All
// Any takes a collection and returns true if any of the items
// is true. A collection of length 0 returns false.
var Any = v1.Any
// Builtin represents a built-in function supported by OPA. Every built-in
// function is uniquely identified by a name.
type Builtin = v1.Builtin