[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-573836-105":3,"detail-sidebar-cat-1-en-105":80,"doc-detail-573836-en":126},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","rego-cheat-sheet","Rego Cheat Sheet","","Rego Cheat Sheet provides a compact reference for writing policy rules using OPA Rego syntax. It explains single-value and multi-value rule patterns, including set and object rule generation, and demonstrates iteration constructs such as comprehensions. The sheet covers control flow with logical AND/OR, validation and testing using with overrides, and debugging with print. It also summarizes common builtins for regex, strings, aggregates, and object extraction/transformation.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/presentations/","Presentations",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/rego-cheat-sheet/573836/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/rego-cheat-sheet/573836.png","ImageObject",442,249,{"name":42,"@type":43},"Elsa","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-19","2026-10-14",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What is the difference between single-value and multi-value rules in Rego?","Question",{"text":62,"@type":63},"Single-value rules assign one value, while multi-value rules generate and assign collections such as sets or objects of keys/values.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do logical AND and OR work in Rego rules?",{"text":67,"@type":63},"Statements join with logical AND inside a rule body. Logical OR is expressed by writing multiple rule variants or using the in keyword with conditions.",{"name":69,"@type":60,"acceptedAnswer":70},"How can you test Rego policy behavior and debug rule execution?",{"text":71,"@type":63},"Use the with keyword to override input/data in tests, and use print inside rules to inspect runtime values during evaluation.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},573836,1792047892,{"code":4,"msg":81,"data":82},"success",[83,87,92,97,102,107,112,117,122],{"id":84,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":85,"slug":86},11,90,"presentations",{"id":88,"doc_module":22,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},12,"Resumes",80,"resumes",{"id":93,"doc_module":22,"doc_module_name":25,"category_name":94,"show_sort_weight":95,"slug":96},14,"Invoices",70,"invoices",{"id":98,"doc_module":22,"doc_module_name":25,"category_name":99,"show_sort_weight":100,"slug":101},15,"Posters",60,"posters",{"id":103,"doc_module":22,"doc_module_name":25,"category_name":104,"show_sort_weight":105,"slug":106},16,"Social Media",50,"social-media",{"id":108,"doc_module":22,"doc_module_name":25,"category_name":109,"show_sort_weight":110,"slug":111},17,"Forms",40,"forms",{"id":113,"doc_module":22,"doc_module_name":25,"category_name":114,"show_sort_weight":115,"slug":116},18,"Letters",30,"letters",{"id":118,"doc_module":22,"doc_module_name":25,"category_name":119,"show_sort_weight":120,"slug":121},21,"Paper Templates",5,"papers-templates",{"id":123,"doc_module":22,"doc_module_name":25,"category_name":124,"show_sort_weight":4,"slug":125},158,"General","general-158",{"code":4,"msg":81,"data":127},{"doc_id":78,"user_id":128,"nickname":42,"user_avatar":129,"doc_module":22,"category_id":84,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":30,"language":135,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":12,"update_tm":139,"read_time":22},137455077381,"https://ap-avatar.wpscdn.com/davatar_994ba38a5ba835b3df7d355c54d3ed8d","Rego Cheat Sheet  \nRules The building blocks of Rego Single-Value Rules  \nSingle-value rules assign a single value. In older documentation, these are sometimes referred to as \"complete rules\". (Try It)  \ndefault allow := false  \nallow if {  \ninput .user .role == \"admin \"input .user .internal  \n}  \ndefault request_quota := 100  \nrequest_quota := 1000 if input .user .internal  \nrequest_quota := 50 if input .user .plan .trial  \nMulti-Value Set Rules  \nMulti-value set rules generate and assign a set of values to a variable. In older documentation these are sometimes referred to as \"partial set rules\".(Try It)  \npaths contains \" /handbook/* \"  \npaths contains path if {  \nsome team in input .user .teams  \npath := sprintf ( \" /teams/%v/ * \" , [team])}  \nOutput  \n{  \n\"paths \" : [ \" /handbook/* \" , \" /teams/owl/* \" , \" /teams/tiger/* \" ]}  \nMulti-Value Object Rules  \nMulti-value object rules generate and assign a set of keys and values to a variable. In older documentation these are sometimes referred to as \"partial object rules\".  \n(Try It)  \n\\# Creates an object with sets as the values .  \npaths_by_prefix[prefix] contains path if {  \nsome path in input .paths parts := split(path, \" / \" )  \nprefix := parts[0]  \n}  \nOutput  \n{  \n\"paths_by_prefix \" : {  \n\"a \" : [ \"a/123 .txt \" , \"a/456 .txt \" ],\"b \" : [ \"b/bar .txt \" , \"b/foo .txt \" ],  \n\"c \" : [ \"c/x .txt \" ]}  \n}  \nIteration Make quick work of collections Some  \nName local query variables. (Try It)  \nall_regions := {  \n\"emea \" : { \"west \" , \"east \" },  \n\"na \" : { \"west \" , \"east \" , \"central \" },\"latam \" : { \"west \" , \"east \" },\"apac \" : { \"north \" , \" south \" },  \n}  \nallowed_regions contains region_id if { some area, regions in all_regions  \nsome region in regions  \nregion_id := sprintf ( \" %s_ %s \" , [area, region])}  \nOutput  \n{  \n\"allowed_regions \" : [  \n\"apac_north \" , \"apac_south \" , \"emea_east \" , . . .]  \n}  \nEvery  \nCheck conditions on many elements. (Try It)  \nallow if {  \nprefix := sprintf ( \" /docs/%s/ \" , [input .userID]) every path in input .paths {  \nstartswith (path, prefix)}  \n}  \nControl Flow Handle diﬀerent conditions Logical AND  \nStatements in rules are joined with logical AND. (Try It)  \nvalid_staff_email if {  \nregex.match(‘^\\S+@\\S+\\.\\S+$‘, [input.email](input.email) ) \\# and endswith([input.email](input.email) , \"[example.com](example.com)\")  \n}  \nLogical OR  \nExpress OR with multiple rules, functions or the in keyword. (Try It)  \n\\# using multiple rules  \nvalid_email if endswith([input.email](input.email) , \"@[example.com](example.com)\")  \nvalid_email if endswith([input.email](input.email) , \"@[example.org](example.org)\")  \nvalid_email if endswith([input.email](input.email) , \"@[example.net](example.net)\")  \n\\# using functions  \nallowed_firstname(name) if { startswith (name, \"a \" )  \ncount(name) > 2}  \nallowed_firstname( \" joe \" ) \\# if name == ’joe’valid_name if allowed_firstname(input .name)  \nvalid_request if {  \ninput .method in { \"GET \" , \"POST \" } \\# using ‘in‘}  \nOutput  \n{  \n\"email\": \"[opa@example.com](opa@example.com)\",\"name \" : \"anna \" ,  \n\"method \" : \"GET \"}  \nTesting Validate your policy’s behavior  \nWith  \nOverride input and data using the with keyword. (Try It)  \nallow if input .admin == true  \ntest_allow_when_admin if {  \nallow with input as { \"admin \" : true}}  \nDebugging Find and ﬁx problems  \nPrint  \nUse print in rules to inspect values at runtime. (Try It)  \nallowed_users := { \"alice \" , \"bob \" }  \nallow if {  \nsome user in allowed_users print (user)  \ninput .user == user}  \nOutput  \n// alice  \n// bob  \nComprehensions Rework and process collections Arrays  \nProduce ordered collections, maintaining duplicates.  \n(Try It)  \ndoubled := [m |  \nsome n in [1, 2, 3, 3] m := n * 2  \n]  \nOutput  \n{ \"doubled \" : [2, 4, 6, 6] }  \nSets  \nProduce unordered collections without duplicates.(Try It)  \nunique_doubled contains m if { some n in [10, 20, 30, 20, 10] m := n * 2  \n}  \nOutput  \n{ \"unique_doubled \" : [20, 40, 60] }  \nObjects  \nProduce key:value dat","cbCaikofoIkFZYFx","https://ap.wps.com/l/cbCaikofoIkFZYFx","pdf",162842,"English","# Rego Rules\n## Single-Value Rules\n## Multi-Value Set Rules\n## Multi-Value Object Rules\n## Iteration and Every\n# Rule Logic and Control Flow\n## Logical AND\n## Logical OR\n# Testing and Debugging\n## With Keyword\n## Print Debugging\n# Data Processing Constructs\n## Comprehensions for Arrays\n## Sets and Objects\n# Builtins Reference\n## Regex and Strings\n## Aggregates\n## Object Data Extraction and Transformation","[{\"question\":\"What is the difference between single-value and multi-value rules in Rego?\",\"answer\":\"Single-value rules assign one value, while multi-value rules generate and assign collections such as sets or objects of keys/values.\"},{\"question\":\"How do logical AND and OR work in Rego rules?\",\"answer\":\"Statements join with logical AND inside a rule body. Logical OR is expressed by writing multiple rule variants or using the in keyword with conditions.\"},{\"question\":\"How can you test Rego policy behavior and debug rule execution?\",\"answer\":\"Use the with keyword to override input/data in tests, and use print inside rules to inspect runtime values during evaluation.\"}]","Rego Cheat Sheet | PDF",1791948129]