Server
eunomia.server.EunomiaServer
Core logic of the Eunomia Server.
This class provides an interface to the Open Policy Agent (OPA) engine for making access control decisions and managing resources and principals.
Source code in src/eunomia/server.py
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 |
|
check_access(request, db)
async
Check if a principal has access to a specific resource.
This method first get resource and principals attributes and then queries the OPA server to determine if the specified principal is allowed to access the specified resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
AccessRequest
|
The access request to check, containing the principal requesting access and the resource being accessed. Both entities can be specified either by their registered identifier, by their attributes or by both. |
required |
db
|
Session
|
The SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if access is granted, False otherwise. |
Raises:
Type | Description |
---|---|
HTTPError
|
If communication with the OPA server fails. |
ValueError
|
If there is a discrepancy between the provided attributes and the registered attributes. |
Source code in src/eunomia/server.py
create_policy(policy, filename)
Create a new policy and save it to the local file system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy
|
Policy
|
The policy to create, containing a list of access rules. Rules are evaluated with OR logic (access is granted if ANY rule matches). Within each rule, attributes for both principal and resource are evaluated with AND logic (all specified attributes must match). |
required |
filename
|
str
|
The filename of the policy to create. |
required |
Returns:
Type | Description |
---|---|
str
|
The path to the created policy. |
Raises:
Type | Description |
---|---|
ValueError
|
If the policy file already exists. |
Source code in src/eunomia/server.py
delete_entity(uri, db)
Delete an entity from the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The uri of the entity to delete. |
required |
db
|
Session
|
The SQLAlchemy database session. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the entity is not registered. |
Source code in src/eunomia/server.py
register_entity(entity, db)
Register a new entity in the system.
Creates a new entity with the provided attributes, generating a unique identifier for future reference, if not provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
EntityCreate
|
Pydantic model containing attributes about the entity. |
required |
db
|
Session
|
The SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
EntityInDb
|
The generated entity as a Pydantic model. |
Raises:
Type | Description |
---|---|
ValueError
|
If the entity is already registered. |
Source code in src/eunomia/server.py
update_entity(entity, override, db)
Update the attributes of an existing entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
EntityUpdate
|
The entity to update, with its identifier and the attributes to update. |
required |
override
|
bool
|
If True, the existing attributes are deleted and the new attributes are added. If False, the existing attributes are maintaned or updated in case of overlap, and the additional new attributes are added. |
required |
db
|
Session
|
The SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
EntityInDb
|
The updated entity as a Pydantic model. |
Raises:
Type | Description |
---|---|
ValueError
|
If the entity is not registered. |