Skip to content

Commit a1f0b30

Browse files
committed
Freezing -- need to add more comments and cleanup code.
1 parent 5a46450 commit a1f0b30

12 files changed

+1082
-61
lines changed

.env.example

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ EUREKA_TENANT =
1212
EUREKA_USER =
1313
EUREKA_PASSWORD =
1414

15+
# Reference OKAPI Env
16+
REF_OKAPI_URL =
17+
REF_OKAPI_TENANT =
18+
REF_OKAPI_USER =
19+
REF_OKAPI_PASSWORD =
20+
1521
# Reference server - Production or test server with real permission data in it.
22+
BASE_DIR =
1623

1724
FILE_OKAPI_PERMISSIONS =
25+
FILE_REF_OKAPI_PERMISSIONS =
1826
FILE_EUREKA_CAPABILITY_SETS =
1927
FILE_EUREKA_CAPABILITIES =
28+
FILE_EUREKA_CAPABILITY_SETS_EXPANDED =
2029
FILE_COMPARED_SETS_TO_PERMISSIONS =
21-
FILE_COMPARED_SETS_TO_PERMISSIONS_CSV =
30+
FILE_COMPARED_CURRENT_TO_CAPABILITIES =
31+
FILE_FIND_MY_CAPABILITIES =
32+
FILE_NEW_ROLES =
33+
FILE_WORKING_WEB_PAGE =

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175-
.vscode/
175+
.vscode/
176+
dataSets/
177+
.DS_Store

README.md

+80-15
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
11
# Overview
22

3-
This is a set of Python tools for helping with the migration from FOLIO OKAPI platform to FOLIO Eureka platform.
3+
This is a set of Python tools for helping with the migration from FOLIO OKAPI platform to FOLIO Eureka platform. A lot of the scripts need to be ran in the order presented below as they build upon each other. I purposely did not combine them into a single function as to allow for the review of data at each step.
44

5-
## Installation
5+
# Installation
66

77
```bash
88
source .venv/bin/activate
99
pip install -r requirements.txt
1010
```
1111

12-
## Scripts
13-
### Get OKAPI Permissions
12+
# Scripts
13+
14+
## Get OKAPI Permissions
15+
1416
!!! Run First !!!
1517
This script needs to be ran first to pull all the permission sets from an OKAPI instance of FOLIO. By Default Ramsons BugFest has been added to the .env file.
1618

17-
#### Running the script:
19+
### Running the script:
1820

1921
```bash
2022
python ./pullOkapiPermissions.py
2123
```
2224

23-
### Get Eureka Permissions
24-
**_Not Functional_**
25+
## Get Eureka Permissions
26+
27+
!!! Run First !!!
2528

2629
This script pulls the Capabilities and Capability Sets from the Eureka platform and saves them in JSON format to be used later.
2730

2831
- _At this time i can not log in via the API, so the JSON was pulled via the web interface and saved into a JSON file._
2932

30-
#### Running the script:
33+
### Running the script:
3134

3235
```bash
33-
python ./pullEurekaCapabilities.py
36+
python ./pullOkapiPermissions.py
3437
```
35-
### Compare
38+
39+
## Get Production Permission Sets
40+
41+
This script pulls the current permission sets form your reference system and saves them in JSON format.
42+
43+
### Running the script:
44+
45+
```bash
46+
python ./pullReferenceData.py
47+
```
48+
49+
## Compare OKAPI to Eureka
3650

3751
This script pulls the Capability Sets and uses the published names to match them to a OKAPI permission set. It expands on the included capabilities and permissions to show the names and UUIDS. Two files are generated:
3852
`FILE_COMPARED_SETS_TO_PERMISSIONS`: JSON file with all the collected data
@@ -46,25 +60,76 @@ This script pulls the Capability Sets and uses the published names to match them
4660

4761
**OKAPI sub permissions (if a Matching permission set is found)**: _okapiSubPermissions.name okapiSubPermissions.description okapiSubPermissions.permissionName_
4862

49-
#### Running the script:
63+
### Running the script:
64+
65+
```bash
66+
python ./compareOkapiToEureka.py
67+
```
68+
69+
## Expanded Capability Sets
70+
71+
This scripts takes the Capability set data and expands out the linked capabilities.
72+
73+
### Files generated:
74+
75+
- `FILE_EUREKA_CAPABILITY_SETS_EXPANDED`: JSON file listing all the capability sets and the capabilities assigned to that set
76+
- `FILE_EUREKA_CAPABILITY_SETS_EXPANDED_CSV`: CSV file of the same data set.
77+
- `FILE_EUREKA_CAPABILITY_SETS_EXPANDED_HTML`: HTML Table view that can be opened directly in the browser or saved to Confluence.
78+
79+
### Running the script:
5080

5181
```bash
52-
python ./compare.py
82+
python ./expandCapabilitySets.py
5383
```
5484

55-
## Contributing
85+
## Compare Current Permissions to Capability Sets
86+
87+
This script takes current permission sets in the reference environment (visible, and mutable) expands the sub permissions. During this process it adds the supervision name, and description if they are included. it also looks to see if there is a matching capability, and lists that data.
88+
This should allow a user to re-create a permission set using just capabilities.
89+
90+
### Files generated:
91+
92+
- `FILE_COMPARED_CURRENT_TO_CAPABILITIES`: JSON version of the expanded data
93+
- `FILE_COMPARED_CURRENT_TO_CAPABILITIES_CSV`: CSV version of the same data set
94+
95+
96+
97+
### Running the script:
98+
99+
```bash
100+
python ./compareCurrentToCapabilities.py
101+
```
102+
103+
## Find possible compatibility sets
104+
105+
This script will look that the JSON generated from `compareCurrentToCapabilities.py` and compare the assigned Compatibility sets and rank what set may bes fit in a new role that will match the Permission Set. It does this by looking at the capability Sets individual capabilitys and then matches thos to the ones in the permission set. The fallowing data will be added:
106+
107+
**Total** - Total number of capabilities in the set
108+
109+
**Matching** - Number of matching Capabilities to the permission set
110+
111+
**Ranking** - based on the percentage of total number of capabilities that match
112+
113+
Items with a rank of 0 or lower then X will be ignored.
114+
115+
### Files generated:
116+
117+
- `FILE_COMPARED_CURRENT_TO_CAPABILITIES`: JSON version of the expanded data
118+
- `FILE_COMPARED_CURRENT_TO_CAPABILITIES_CSV`: CSV version of the same data set
119+
120+
# Contributing
56121

57122
Pull requests are welcome. For major changes, please open an issue first
58123
to discuss what you would like to change.
59124

60125
Please also fork as needed.
61126

62-
## .env File
127+
# .env File
63128
FILE_OKAPI_PERMISSIONS: Location of the OKAPI permissions JSON file. This will be used fro reading and writing depending on the script ran.
64129
FILE_EUREKA_CAPABILITY_SETS = Location of the Eureka Capability Sets JSON file. This will be used fro reading and writing depending on the script ran.
65130
FILE_EUREKA_CAPABILITIES = Location of the Eureka Capabilities JSON file. This will be used fro reading and writing depending on the script ran.
66131
FILE_COMPARED_SETS_TO_PERMISSIONS = Location of the OKAPI to Eureka Capability Set comparisons JSON file. This will be used fro reading and writing depending on the script ran.
67132

68-
## License
133+
# License
69134

70135
[MIT](https://choosealicense.com/licenses/mit/)

compareCurrentToCapabilities.py

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python3
2+
import json
3+
import os
4+
from dotenv import load_dotenv
5+
load_dotenv()
6+
import csv
7+
8+
okapiPath_JSON = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_OKAPI_PERMISSIONS")}.json"
9+
okapiRefPath_JSON = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_REF_OKAPI_PERMISSIONS")}.json"
10+
eurekaCapSetsPath_JSON = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_EUREKA_CAPABILITY_SETS")}.json"
11+
eurekaCapPath_JSON = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_EUREKA_CAPABILITIES")}.json"
12+
output_JSON = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_COMPARED_CURRENT_TO_CAPABILITIES")}.json"
13+
output_CSV = f"{os.getenv("BASE_DIR")}{os.getenv("FILE_COMPARED_CURRENT_TO_CAPABILITIES")}.csv"
14+
15+
def compare_current_permissions():
16+
print(okapiPath_JSON)
17+
# Pull the JSON file containing the Eureka Capability Sets and ingest it as JSON.
18+
if os.path.isfile(okapiPath_JSON): # Check if the file exists
19+
with open(okapiPath_JSON, 'r') as f:
20+
okapi = json.load(f)
21+
print(f'Reference file loaded: {okapiPath_JSON}')
22+
else:
23+
print(f'Error: JSON file not found. {okapiPath_JSON}')
24+
25+
# Pull the JSON file containing the Eureka Capability Sets and ingest it as JSON.
26+
if os.path.isfile(okapiRefPath_JSON): # Check if the file exists
27+
with open(okapiRefPath_JSON, 'r') as f:
28+
refSets = json.load(f)
29+
print(f'Reference file loaded: {okapiRefPath_JSON}')
30+
else:
31+
print(f'Error: JSON file not found. {okapiRefPath_JSON}')
32+
33+
# Pull the JSON file containing the Eureka Capabilities and ingest it as JSON.
34+
if os.path.isfile(eurekaCapPath_JSON): # Check if the file exists
35+
with open(eurekaCapPath_JSON, 'r') as f:
36+
eurekaCap = json.load(f)
37+
print(f'Reference file loaded: {eurekaCapPath_JSON}')
38+
else:
39+
print(f'Error: JSON file not found. {eurekaCapPath_JSON}')
40+
41+
def _get_capability_data(sub):
42+
# this function thats the provided sub-permission (OKAPI) and matches it to a Eureka Capability
43+
rtnData = {"id":'', "name":"","description":"","type":"","action":"","resource":""}
44+
for p in eurekaCap['capabilities']:
45+
if p['permission'] == sub:
46+
rtnData = p
47+
return rtnData
48+
49+
def _get_permission_data(sub):
50+
# this function takes the provided sub permission and retries its details
51+
rtnData = {"displayName":"","description":""}
52+
for p in okapi['permissions']:
53+
if p['permissionName'] == sub:
54+
rtnData = p
55+
return rtnData
56+
57+
def _build_sub_permissions(subData):
58+
rtnData = []
59+
total = 0
60+
missing = 0
61+
allEurekaPermissions = []
62+
for sub in subData:
63+
r = _get_capability_data(sub)
64+
c = _get_permission_data(sub)
65+
total += 1
66+
missing = missing + 1 if r["id"] == "" else missing
67+
rtnData.append({
68+
"subPermission": sub,
69+
"subPermissionDisplayName": c['displayName'] if 'displayName' in c else '',
70+
"subPermissionDescription": c['description'] if 'description' in c else '',
71+
"eurekaId": r["id"],
72+
"eurekaName": r["name"],
73+
"eurekaDescription": r['description'] if 'description' in r else '',
74+
"eurekaType": r["type"],
75+
"eurekaAction": r["action"],
76+
"eurekaResource": r["resource"]
77+
})
78+
if r["id"] != "":
79+
allEurekaPermissions.append(r["id"])
80+
return {"subPermissions": rtnData, "total": total, "missing": missing, "allEurekaPermissions": allEurekaPermissions}
81+
82+
83+
finalData = []
84+
print("------ Starting Comparison -----")
85+
for i in refSets:
86+
x = False
87+
subData = _build_sub_permissions(i['allSubPermissions'])
88+
finalData.append({
89+
"displayName": i['displayName'],
90+
"id": i['id'],
91+
"total": subData['total'],
92+
"missing": subData['missing'],
93+
"subPermissions": subData['subPermissions'],
94+
"allEurekaPermissions": subData['allEurekaPermissions']
95+
})
96+
97+
98+
with open(output_JSON, 'w') as f:
99+
json.dump(finalData, f, indent=4) # Save with indentation for readability
100+
print(f"Saved Comparison JSON file {output_JSON}")
101+
102+
flattened_data = []
103+
test = ''
104+
for m in finalData:
105+
x = False
106+
for f in m['subPermissions']:
107+
if x == False:
108+
insertName = m['displayName']
109+
insertTotal = m['total']
110+
insertMissing = m['missing']
111+
x = True
112+
else:
113+
insertName = ''
114+
insertTotal = ''
115+
insertMissing = ''
116+
117+
flattened_data.append([
118+
insertName, insertTotal, insertMissing,
119+
f['subPermission'], f['subPermissionDisplayName'], f['subPermissionDescription'],
120+
f['eurekaId'], f['eurekaName'], f['eurekaDescription'], f['eurekaType'], f['eurekaAction'], f['eurekaResource']
121+
])
122+
123+
# Write to CSV
124+
with open(output_CSV, 'w', newline='') as file:
125+
writer = csv.writer(file)
126+
writer.writerow([
127+
'displayName', 'total', 'missing',
128+
'subPermission', 'subPermissionDisplayName', 'subPermissionDescription',
129+
'eurekaId', 'eurekaName', 'eurekaDescription', 'eurekaType', 'eurekaAction', 'eurekaResource'
130+
])
131+
writer.writerows(flattened_data)
132+
print(f"Saved Comparison CSV file {output_CSV}")
133+
134+
compare_current_permissions()
135+
print("------ Complete -----")

0 commit comments

Comments
 (0)