Compare commits
28
Commits
6eff1d29c4
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3e2bcb260 | ||
|
|
d602cbb897 | ||
|
|
6baf0f12ab | ||
|
|
43fe0869c2 | ||
|
|
5f7f496620 | ||
|
|
f5b26d75bc | ||
|
|
5d3fd7fb35 | ||
|
|
c897b1d7f9 | ||
|
|
4cd4b2a3e4 | ||
|
|
2034353958 | ||
|
|
6fad3cfe76 | ||
|
|
a6bd04a302 | ||
|
|
0b5334b097 | ||
|
|
c3224a7ed7 | ||
|
|
b7f54b8873 | ||
|
|
71c78fc7fe | ||
|
|
472b7d9df7 | ||
|
|
9ed4fbb7ef | ||
|
|
fd7809e017 | ||
|
|
f29073e3af | ||
|
|
d7f2d048b3 | ||
|
|
e722565199 | ||
|
|
f01f45ada2 | ||
|
|
4b5487fb23 | ||
|
|
89ebeef1ee | ||
|
|
af9e576fc5 | ||
|
|
f93584a97d | ||
|
|
a5e902a434 |
+4
-3
@@ -10,6 +10,7 @@ wheels/
|
||||
.venv
|
||||
|
||||
# Project specific
|
||||
*.json
|
||||
*.psm1
|
||||
*.xml
|
||||
*.bak
|
||||
src/output/*
|
||||
originals/*
|
||||
.vscode
|
||||
@@ -0,0 +1,26 @@
|
||||
# JSON/XML Parser Application
|
||||
|
||||
## Overview
|
||||
Configuration management utility for One Identity Manager (OIM) PowerShell connectors. Transforms JSON database exports into validated XML configuration files, ensuring consistent deployment of connection specifications.
|
||||
|
||||
## Installation
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
```bash
|
||||
python src/main.py \
|
||||
--json <input.json> \
|
||||
--xml <output.xml> \
|
||||
--name "Connection Name" \
|
||||
--description "Connection Description" \
|
||||
[--pretty]
|
||||
```
|
||||
|
||||
**Options**:
|
||||
- `--json/-j`: Path to input JSON file (required)
|
||||
- `--xml/-x`: Output XML file path (required)
|
||||
- `--name/-n`: Connection name (required)
|
||||
- `--description/-d`: Connection description (required)
|
||||
- `--pretty/-p`: Enable formatted XML output (flag)
|
||||
|
||||
@@ -6,6 +6,8 @@ readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"click>=8.1.8",
|
||||
"httpx>=0.28.1",
|
||||
"loguru>=0.7.3",
|
||||
"lxml>=5.3.1",
|
||||
"pydantic>=2.10.6",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv pip compile pyproject.toml -o requirements.txt
|
||||
click==8.1.8
|
||||
# via int (pyproject.toml)
|
||||
loguru==0.7.3
|
||||
# via int (pyproject.toml)
|
||||
lxml==5.3.1
|
||||
# via int (pyproject.toml)
|
||||
@@ -1,37 +0,0 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import click
|
||||
|
||||
def _get_fields(json_data: dict) -> list[str]:
|
||||
"""
|
||||
Extract field names from a JSON data structure.
|
||||
|
||||
Args:
|
||||
json_data (dict): The JSON data from which to extract field names.
|
||||
|
||||
Returns:
|
||||
list[str]: A list of field names extracted from the JSON data.
|
||||
"""
|
||||
attributes = json_data["conceptCodes"][0]["attributes"]
|
||||
namelist = [attribute["attributeName"] for attribute in attributes]
|
||||
return namelist
|
||||
|
||||
def parse_json(json_file: Path) -> list[str]:
|
||||
"""
|
||||
Parse a JSON file and extract field names.
|
||||
|
||||
Args:
|
||||
json_file (Path): The path to the JSON file to parse.
|
||||
|
||||
Returns:
|
||||
list[str]: A list of field names extracted from the JSON file.
|
||||
|
||||
Raises:
|
||||
click.FileError: If the file is not a valid JSON file.
|
||||
"""
|
||||
try:
|
||||
with open(json_file, "r") as f:
|
||||
json_data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
raise click.FileError(json_file, "Not a valid JSON file.")
|
||||
return _get_fields(json_data)
|
||||
@@ -0,0 +1,9 @@
|
||||
def sanitize_name(name: str) -> str:
|
||||
"""
|
||||
Sanitize a name by removing all non-letter characters except hyphens and Scandinavian letters.
|
||||
"""
|
||||
# Replace Scandinavian letters
|
||||
name = name.replace('ä', 'a').replace('ö', 'o')
|
||||
name = name.replace('Ä', 'A').replace('Ö', 'O')
|
||||
# Remove all non-letter characters except hyphens
|
||||
return ''.join(c for c in name if c.isalpha() or c == '-')
|
||||
+114
-13
@@ -1,21 +1,122 @@
|
||||
import click
|
||||
from pathlib import Path
|
||||
import json
|
||||
from datetime import datetime
|
||||
from pydantic import HttpUrl
|
||||
import httpx
|
||||
from urllib.parse import urlparse, urlencode
|
||||
|
||||
from json_parser import parse_json
|
||||
from xml_parser import get_xml_data, add_connection, write_xml_data
|
||||
from models.savefile import SaveFile, CodeItem
|
||||
from psm_parser import write_psm
|
||||
from xml_parser import write_xml_data
|
||||
|
||||
def _strip_params(url: HttpUrl) -> str:
|
||||
parsed_url = urlparse(str(url))
|
||||
return f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}"
|
||||
|
||||
@click.command
|
||||
@click.option('-j', '--json', type=Path, required=True)
|
||||
@click.option('-x', '--xml', type=Path, required=True)
|
||||
@click.option('-n', '--name', type=str, required=True)
|
||||
@click.option('-d', '--description', type=str, required=True)
|
||||
@click.option('-p', '--pretty', is_flag=True, default=False, help='Enable pretty output')
|
||||
def main(json: Path, xml: Path, name: str, description: str, pretty: bool):
|
||||
xml_data = get_xml_data(xml)
|
||||
field_names = parse_json(json)
|
||||
root = add_connection(xml_data, name, field_names, description=description)
|
||||
write_xml_data(root, xml, pretty=pretty)
|
||||
def get_attributes(url: str) -> list[str]:
|
||||
"""
|
||||
Get attributes from a URL.
|
||||
|
||||
Args:
|
||||
url (str): The URL to get attributes from.
|
||||
|
||||
Returns:
|
||||
list[str]: A list of attributes.
|
||||
"""
|
||||
query_params = {"pageSize": 500}
|
||||
|
||||
new_url = f"{url}?{urlencode(query_params, doseq=True)}"
|
||||
|
||||
response = httpx.get(new_url)
|
||||
if response.status_code != 200:
|
||||
click.echo(f"Failed to get attributes from {url}")
|
||||
return []
|
||||
|
||||
conseptCodes = response.json()["conceptCodes"]
|
||||
retval = []
|
||||
for attr in conseptCodes:
|
||||
for name in attr["attributes"]:
|
||||
if name["attributeName"] not in retval:
|
||||
retval.append(name["attributeName"])
|
||||
|
||||
return retval
|
||||
|
||||
def write_json(json_file: Path, data: SaveFile):
|
||||
with open(json_file, "w") as f:
|
||||
f.write(data.model_dump_json())
|
||||
|
||||
@click.group
|
||||
def main():
|
||||
click.echo("Varha CodeServer Connector")
|
||||
pass
|
||||
|
||||
@main.command
|
||||
@click.argument('json_file', type=Path, required=True)
|
||||
@click.option('--url', '-u', type=str, required=True, help="URL of the connection")
|
||||
@click.option('--name', '-n', type=str, required=True, help="Name of the connection")
|
||||
def add(json_file: Path, url: str, name: str):
|
||||
"""
|
||||
Add a new connection to the JSON file.
|
||||
|
||||
Args:
|
||||
json_file (Path): The path to the JSON file.
|
||||
url (str): The URL of the connection.
|
||||
name (str): The name of the connection.
|
||||
"""
|
||||
server_data = SaveFile()
|
||||
if json_file.exists():
|
||||
with open(json_file, "r") as f:
|
||||
server_data = SaveFile(**json.load(f))
|
||||
|
||||
# Check if name already exists
|
||||
existing_names = [code.name for code in server_data.conceptCodes]
|
||||
if name in existing_names:
|
||||
click.echo(f"Name {name} already exists.")
|
||||
return
|
||||
|
||||
# Get attributes from the URL
|
||||
attributes = get_attributes(_strip_params(url))
|
||||
server_data.conceptCodes.append(CodeItem(name=name, url=_strip_params(url), attributes=attributes))
|
||||
server_data.updated_at = datetime.now()
|
||||
write_json(json_file, server_data)
|
||||
|
||||
@main.command
|
||||
@click.argument('json_file', type=Path, required=True)
|
||||
def listUrls(json_file: Path):
|
||||
#TODO: Format the output
|
||||
if not json_file.exists():
|
||||
click.echo(f"File {json_file} does not exist.")
|
||||
return
|
||||
with open(json_file, "r") as f:
|
||||
server_data = SaveFile(**json.load(f))
|
||||
click.echo(server_data.model_dump_json(indent=4))
|
||||
|
||||
@main.command
|
||||
@click.argument('json_file', type=Path, required=True)
|
||||
@click.option('--name', '-n', type=str, required=True, help="Name of the connection")
|
||||
def remove(json_file: Path, name: str):
|
||||
if not json_file.exists():
|
||||
click.echo(f"File {json_file} does not exist.")
|
||||
return
|
||||
with open(json_file, "r") as f:
|
||||
server_data = SaveFile(**json.load(f))
|
||||
server_data.conceptCodes = [code for code in server_data.conceptCodes if code.name != name]
|
||||
server_data.updated_at = datetime.now()
|
||||
write_json(json_file, server_data)
|
||||
|
||||
@main.command
|
||||
@click.argument('json_file', type=Path, required=True)
|
||||
def write_output(json_file: Path):
|
||||
if not json_file.exists():
|
||||
click.echo(f"File {json_file} does not exist.")
|
||||
return
|
||||
server_data = None
|
||||
with open(json_file, "r") as f:
|
||||
server_data = SaveFile(**json.load(f))
|
||||
|
||||
write_psm(server_data)
|
||||
write_xml_data(server_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import date, datetime
|
||||
|
||||
from pydantic_core import Url
|
||||
|
||||
class AttributeData(BaseModel):
|
||||
attributeName: str
|
||||
attributeValue: list[str]
|
||||
|
||||
class LinkData(BaseModel):
|
||||
href: Url
|
||||
rel: str
|
||||
type: str
|
||||
|
||||
class ConceptCodeData(BaseModel):
|
||||
attributes: list[AttributeData]
|
||||
beginDate: date = Field(...)
|
||||
classificationId: str
|
||||
classificationName: str
|
||||
conceptCodeId: str
|
||||
createDate: datetime
|
||||
expirationDate: date
|
||||
lastModifiedBy: str
|
||||
lastModifiedDate: datetime
|
||||
links: list[LinkData]
|
||||
status: str
|
||||
versionId: str
|
||||
versionName: str
|
||||
|
||||
class Data(BaseModel):
|
||||
conceptCodes: list[ConceptCodeData]
|
||||
links: list[LinkData]
|
||||
page: int
|
||||
pageSize: int
|
||||
totalItems: int
|
||||
totalPages: int
|
||||
@@ -0,0 +1,33 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, HttpUrl
|
||||
from enum import Enum
|
||||
|
||||
class LinkType(Enum):
|
||||
get = "GET"
|
||||
post = "POST"
|
||||
put = "PUT"
|
||||
delete = "DELETE"
|
||||
|
||||
class Attributes(BaseModel):
|
||||
attributeName: str
|
||||
attributeValue: list[str]
|
||||
|
||||
class Links(BaseModel):
|
||||
href: HttpUrl
|
||||
rel: str
|
||||
type: LinkType
|
||||
|
||||
class CodeServerItem(BaseModel):
|
||||
attributes: list[Attributes]
|
||||
beginDate: datetime
|
||||
classificationId: str
|
||||
classificationName: str
|
||||
conceptCodeId: str
|
||||
createDate: datetime
|
||||
expirationDate: datetime
|
||||
lastModifiedBy: str
|
||||
lastModifiedDate: datetime
|
||||
links: list[Links]
|
||||
status: str
|
||||
versionId: str
|
||||
versionName: str
|
||||
@@ -0,0 +1,12 @@
|
||||
from pydantic import BaseModel, HttpUrl, Field
|
||||
from datetime import datetime
|
||||
|
||||
class DataLocation(BaseModel):
|
||||
href: HttpUrl
|
||||
name: str
|
||||
description: str = "Default description"
|
||||
|
||||
class LocationList(BaseModel):
|
||||
location: DataLocation
|
||||
created_at: datetime = Field(default_factory=datetime.now)
|
||||
updated_at: datetime = Field(default_factory=datetime.now)
|
||||
@@ -0,0 +1,14 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import datetime
|
||||
|
||||
class CodeItem(BaseModel):
|
||||
name: str
|
||||
url: str
|
||||
attributes: list[str]
|
||||
checked_at: datetime = Field(default_factory=datetime.now)
|
||||
|
||||
class SaveFile(BaseModel):
|
||||
version: int = 1
|
||||
conceptCodes: list[CodeItem] = Field(default_factory=list)
|
||||
created_at: datetime = Field(default_factory=datetime.now)
|
||||
updated_at: datetime = Field(default_factory=datetime.now)
|
||||
@@ -0,0 +1,162 @@
|
||||
from pathlib import Path
|
||||
|
||||
from lib import sanitize_name
|
||||
from models.savefile import SaveFile
|
||||
|
||||
get_all_code = """
|
||||
function Get-AllCodeServerPages!NAME! {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Resource,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$RootProperty,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$CacheKeyProperty = "conceptCodeId",
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ScriptBlock]$Converter = ${function:ConvertFrom-CodeServerObject!NAME!},
|
||||
[Parameter(Mandatory=$false)]
|
||||
[int]$PageSize = 500
|
||||
)
|
||||
|
||||
begin {
|
||||
if ($null -eq $Global:cache) {
|
||||
$Global:cache = @{}
|
||||
}
|
||||
$cacheKey = $Resource.GetHashCode()
|
||||
$cache[$cacheKey] = @{}
|
||||
}
|
||||
process {
|
||||
$currentPage = 0;
|
||||
$Global:debugOut = @()
|
||||
while ($null -eq $data.totalPages -or $currentPage -lt $data.totalPages) {
|
||||
$uri = "{0}?pageSize={1}&page={2}" -f $Resource, $PageSize, ++$currentPage
|
||||
$data = Invoke-RestMethod -Uri $uri
|
||||
|
||||
write-debug $uri
|
||||
if ($null -eq $data.totalPages) {
|
||||
throw "Did not get totalPages, abort!"
|
||||
} else {
|
||||
$Global:debugOut += $data.conceptCodes
|
||||
if ($null -ne $Converter) {
|
||||
foreach ($codeObject in $data.$RootProperty) {
|
||||
$convertedObject = Invoke-Command -ScriptBlock $Converter -ArgumentList (,$codeObject)
|
||||
$Global:cache[$cacheKey].Add($convertedObject.$CacheKeyProperty, $convertedObject)
|
||||
}
|
||||
} else {
|
||||
foreach ($codeObject in $data.$RootProperty) {
|
||||
$key = ($objAttributes | Where-Object {$_.attributeName -eq $CacheKeyProperty}).attributeValue
|
||||
$Global:cache[$cacheKey].Add($key, $codeObject.attributes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
write-output $cache[$cacheKey].Values
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
get_code = """
|
||||
function Get-CodeServerObject!NAME! {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$conceptCodeId,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Resource,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$RootProperty,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$CacheKeyProperty = "conceptCodeId"
|
||||
)
|
||||
|
||||
begin {
|
||||
if ($null -eq $Global:cache) {
|
||||
$params = @{
|
||||
Resource = $Resource;
|
||||
RootProperty = $RootProperty;
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey("CacheKeyProperty")) {
|
||||
$params.Add("CacheKeyProperty", $CacheKeyProperty)
|
||||
}
|
||||
[void](Get-AllCodeServerPages!NAME! @params)
|
||||
}
|
||||
$cacheKey = $Resource.GetHashCode()
|
||||
}
|
||||
|
||||
process {
|
||||
Write-Debug $cacheKey
|
||||
Write-Output $cache[$cacheKey][$conceptCodeId]
|
||||
}
|
||||
end {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
convert_from = """
|
||||
Function ConvertFrom-CodeServerObject!NAME!([PSCustomObject[]]$codeServerObject!NAME!) {
|
||||
$map = @{
|
||||
"conceptCodeId" = "conceptCodeId";
|
||||
!MAPS!
|
||||
}
|
||||
|
||||
if ($null -eq $codeServerObject!NAME!) {
|
||||
return
|
||||
}
|
||||
|
||||
$obj = New-Object CodeServer!NAME! -ArgumentList $codeServerObject!NAME!
|
||||
$Global:meDebug = $codeServerObject!NAME!
|
||||
|
||||
write-output $obj
|
||||
}
|
||||
"""
|
||||
|
||||
class_definition = """
|
||||
class CodeServer!NAME! {
|
||||
CodeServer!NAME!() {}
|
||||
|
||||
CodeServer!NAME!([psobject]$source) {
|
||||
$dic = @{}
|
||||
$source.attributes | foreach-object {$dic.Add($_.attributeName, $_.attributevalue)}
|
||||
|
||||
$this.{conceptCodeId} = $source.conceptCodeId
|
||||
!VARIABLES!
|
||||
|
||||
}
|
||||
[string]${conceptCodeId}
|
||||
!STRINGS!
|
||||
|
||||
}
|
||||
|
||||
Export-ModuleMember ConvertFrom-CodeServerObject!NAME!, Get-AllCodeServerPages!NAME!,Get-CodeServerObject!NAME!
|
||||
"""
|
||||
|
||||
def define_maps(items: list[str]) -> str:
|
||||
return "\n".join([f"\t\"{sanitize_name(item)}\" = \"{item}\";" for item in items])
|
||||
|
||||
def define_variables(items: list[str]) -> str:
|
||||
return "\n".join([f"\t$this.{{{sanitize_name(item)}}} = $dic[\"{item}\"]" for item in items])
|
||||
|
||||
def define_strings(items: list[str]) -> str:
|
||||
return "\n".join(["\t" + "[string]$" + "{" + sanitize_name(item) + "}" for item in items])
|
||||
|
||||
|
||||
def write_psm(savefile: SaveFile) -> None:
|
||||
|
||||
filename = Path("output/CodeServerConnector.psm1")
|
||||
if not filename.parent.exists():
|
||||
filename.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open(filename, "w", encoding="utf-8-sig") as f:
|
||||
f.write("# ------- BEGIN CODE BLOCK -------\n")
|
||||
for code in savefile.conceptCodes:
|
||||
f.write(get_all_code.replace("!NAME!", code.name))
|
||||
f.write(get_code.replace("!NAME!", code.name))
|
||||
f.write(convert_from.replace("!NAME!", code.name).replace("!MAPS!", define_maps(code.attributes)))
|
||||
f.write(class_definition.replace("!NAME!", code.name).replace("!VARIABLES!", define_variables(code.attributes)).replace("!STRINGS!", define_strings(code.attributes)))
|
||||
f.write("# ------- END CODE BLOCK -------\n")
|
||||
|
||||
return
|
||||
+26
-50
@@ -1,27 +1,21 @@
|
||||
import lxml.etree as ET
|
||||
from pathlib import Path
|
||||
import click
|
||||
|
||||
def write_xml_data(root: ET.Element, file_path: Path, pretty: bool = True) -> None:
|
||||
if file_path.exists():
|
||||
file_path.rename(file_path.with_suffix(".bak"))
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty)
|
||||
if pretty:
|
||||
# Parse the XML string to ensure proper indentation
|
||||
parser = ET.XMLParser(remove_blank_text=True, strip_cdata=False)
|
||||
root = ET.fromstring(xml_str, parser=parser)
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty)
|
||||
file_path.write_bytes(xml_str)
|
||||
from models.savefile import SaveFile
|
||||
from lib import sanitize_name
|
||||
|
||||
def _sanitize_name(name: str) -> str:
|
||||
"""
|
||||
Sanitize a name by removing all non-letter characters except hyphens and Scandinavian letters.
|
||||
"""
|
||||
# Replace Scandinavian letters
|
||||
name = name.replace('ä', 'a').replace('ö', 'o')
|
||||
name = name.replace('Ä', 'A').replace('Ö', 'O')
|
||||
# Remove all non-letter characters except hyphens
|
||||
return ''.join(c for c in name if c.isalpha() or c == '-')
|
||||
def write_xml_data(savefile: SaveFile) -> None:
|
||||
filename = Path("output/CodeServerConnector.xml")
|
||||
if not filename.parent.exists():
|
||||
filename.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
root = _generate_xml_root()
|
||||
for code in savefile.conceptCodes:
|
||||
root = add_connection(root, code.name, code.attributes)
|
||||
|
||||
xml_str = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=True).decode("utf-8-sig")
|
||||
with open(filename, "w", encoding="utf-8-sig") as f:
|
||||
f.write(xml_str)
|
||||
|
||||
def add_connection(root: ET.Element, name: str, attr_list: list[str], description: str = "Default description") -> ET.Element:
|
||||
"""
|
||||
@@ -30,6 +24,7 @@ def add_connection(root: ET.Element, name: str, attr_list: list[str], descriptio
|
||||
Args:
|
||||
root (ET.Element): The root element of the XML configuration.
|
||||
name (str): The name of the connection parameter.
|
||||
attr_list (list[str]): List of attributes for the connection parameter.
|
||||
description (str, optional): The description of the connection parameter. Defaults to "Default description".
|
||||
|
||||
Returns:
|
||||
@@ -45,8 +40,8 @@ def add_connection(root: ET.Element, name: str, attr_list: list[str], descriptio
|
||||
predefined_commands = initialization.find("PredefinedCommands")
|
||||
if predefined_commands is None:
|
||||
predefined_commands = ET.SubElement(initialization, "PredefinedCommands")
|
||||
ET.SubElement(predefined_commands, "Command", Name=f"Get-AllCodeServerPages{name}", Description=f"Get all pages for {name}")
|
||||
ET.SubElement(predefined_commands, "Command", Name=f"Get-CodeServerPage{name}", Description=f"Get a specific page for {name}")
|
||||
ET.SubElement(predefined_commands, "Command", Name=f"Get-AllCodeServerPages{name}")
|
||||
ET.SubElement(predefined_commands, "Command", Name=f"Get-CodeServerObject{name}")
|
||||
|
||||
schema = root.find("Schema")
|
||||
if schema is not None:
|
||||
@@ -54,29 +49,29 @@ def add_connection(root: ET.Element, name: str, attr_list: list[str], descriptio
|
||||
new_class = ET.SubElement(schema, "Class", Name=f"CodeServerObject{name}")
|
||||
properties = ET.SubElement(new_class, "Properties")
|
||||
property = ET.SubElement(properties, "Property", Name="conceptCodeId", DataType="String", IsMultivalue="false", IsAutoFill="false", IsUniqueKey="true")
|
||||
return_binding = ET.SubElement(property, "ReturnBinding")
|
||||
return_binding = ET.SubElement(property, "ReturnBindings")
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-AllCodeServerPages{name}", Path="conceptCodeId")
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-CodeServerPage{name}", Path="conceptCodeId")
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-CodeServerObject{name}", Path="conceptCodeId")
|
||||
mapping = ET.SubElement(property, "CommandMappings")
|
||||
ET.SubElement(mapping, "Map", ToCommand=f"Get-CodeServerPages{name}", Parameter="conceptCodeId")
|
||||
ET.SubElement(mapping, "Map", ToCommand=f"Get-CodeServerObject{name}", Parameter="conceptCodeId")
|
||||
|
||||
for attr in attr_list:
|
||||
property = ET.SubElement(properties, "Property", Name=_sanitize_name(attr), DataType="String", IsMultivalue="false", IsAutoFill="false")
|
||||
return_binding = ET.SubElement(property, "ReturnBinding")
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-AllCodeServerPages{name}", Path=_sanitize_name(attr))
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-CodeServerPage{name}", Path=_sanitize_name(attr))
|
||||
property = ET.SubElement(properties, "Property", Name=sanitize_name(attr), DataType="String", IsMultivalue="false", IsAutoFill="false")
|
||||
return_binding = ET.SubElement(property, "ReturnBindings")
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-AllCodeServerPages{name}", Path=sanitize_name(attr))
|
||||
ET.SubElement(return_binding, "Bind", CommandResultOf=f"Get-CodeServerObject{name}", Path=sanitize_name(attr))
|
||||
|
||||
read_configuration = ET.SubElement(new_class, "ReadConfiguration")
|
||||
listing_command = ET.SubElement(read_configuration, "ListingCommand", Command=f"Get-AllCodeServerPages{name}")
|
||||
ET.SubElement(listing_command, "SetParameter", Param="Resource", Source="ConnectionParameter", Value=f"VarhaUrl{name}")
|
||||
ET.SubElement(listing_command, "SetParameter", Param="RootProperty", Source="FixedValue", Value="conceptCodes")
|
||||
cmd_squence = ET.SubElement(read_configuration, "CommandSequence")
|
||||
item = ET.SubElement(cmd_squence, "Item", Command=f"Get-CodeServerPage{name}", Order="1")
|
||||
item = ET.SubElement(cmd_squence, "Item", Command=f"Get-CodeServerObject{name}", Order="1")
|
||||
ET.SubElement(item, "SetParameter", Param="Resource", Source="ConnectionParameter", Value=f"VarhaUrl{name}")
|
||||
ET.SubElement(item, "SetParameter", Param="RootProperty", Source="FixedValue", Value="conceptCodes")
|
||||
return root
|
||||
|
||||
def _generate_xml_configuration() -> ET.Element:
|
||||
def _generate_xml_root() -> ET.Element:
|
||||
"""
|
||||
Generate a default XML configuration for a PowerShell connector.
|
||||
|
||||
@@ -100,22 +95,3 @@ def _generate_xml_configuration() -> ET.Element:
|
||||
ET.SubElement(environment_initialization, "Disconnect")
|
||||
ET.SubElement(root, "Schema")
|
||||
return root
|
||||
|
||||
def get_xml_data(xml_file: Path) -> ET.Element:
|
||||
"""
|
||||
Get XML data from a file. If the file does not exist, generate a default configuration.
|
||||
|
||||
Args:
|
||||
xml_file (Path): The path to the XML file.
|
||||
|
||||
Returns:
|
||||
ET.Element: The root element of the XML configuration.
|
||||
"""
|
||||
if not xml_file.exists():
|
||||
return _generate_xml_configuration()
|
||||
try:
|
||||
parser = ET.XMLParser(strip_cdata=False)
|
||||
tree = ET.parse(xml_file, parser=parser)
|
||||
return tree
|
||||
except ET.XMLSyntaxError as e:
|
||||
raise click.FileError(xml_file, f"Not a valid XML file. {e}")
|
||||
@@ -11,6 +11,29 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyio"
|
||||
version = "4.9.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "idna" },
|
||||
{ name = "sniffio" },
|
||||
{ name = "typing-extensions", marker = "python_full_version < '3.13'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/95/7d/4c1bd541d4dffa1b52bd83fb8527089e097a106fc90b467a7313b105f840/anyio-4.9.0.tar.gz", hash = "sha256:673c0c244e15788651a4ff38710fea9675823028a6f08a5eda409e0c9840a028", size = 190949 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a1/ee/48ca1a7c89ffec8b6a0c5d02b89c305671d5ffd8d3c94acf8b8c408575bb/anyio-4.9.0-py3-none-any.whl", hash = "sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c", size = 100916 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.1.31"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/1c/ab/c9f1e32b7b1bf505bf26f0ef697775960db7932abeb7b516de930ba2705f/certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651", size = 167577 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/38/fc/bce832fd4fd99766c04d1ee0eead6b0ec6486fb100ae5e74c1d91292b982/certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe", size = 166393 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.8"
|
||||
@@ -32,12 +55,60 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.14.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/f5/38/3af3d3633a34a3316095b39c8e8fb4853a28a536e55d347bd8d8e9a14b03/h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d", size = 100418 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/95/04/ff642e65ad6b90db43e668d70ffb6736436c7ce41fcc549f4e9472234127/h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761", size = 58259 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httpcore"
|
||||
version = "1.0.7"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "certifi" },
|
||||
{ name = "h11" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/6a/41/d7d0a89eb493922c37d343b607bc1b5da7f5be7e383740b4753ad8943e90/httpcore-1.0.7.tar.gz", hash = "sha256:8551cb62a169ec7162ac7be8d4817d561f60e08eaa485234898414bb5a8a0b4c", size = 85196 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/87/f5/72347bc88306acb359581ac4d52f23c0ef445b57157adedb9aee0cd689d2/httpcore-1.0.7-py3-none-any.whl", hash = "sha256:a3fff8f43dc260d5bd363d9f9cf1830fa3a458b332856f34282de498ed420edd", size = 78551 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httpx"
|
||||
version = "0.28.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "anyio" },
|
||||
{ name = "certifi" },
|
||||
{ name = "httpcore" },
|
||||
{ name = "idna" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.10"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int"
|
||||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "click" },
|
||||
{ name = "httpx" },
|
||||
{ name = "loguru" },
|
||||
{ name = "lxml" },
|
||||
{ name = "pydantic" },
|
||||
]
|
||||
@@ -50,6 +121,8 @@ dev = [
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "click", specifier = ">=8.1.8" },
|
||||
{ name = "httpx", specifier = ">=0.28.1" },
|
||||
{ name = "loguru", specifier = ">=0.7.3" },
|
||||
{ name = "lxml", specifier = ">=5.3.1" },
|
||||
{ name = "pydantic", specifier = ">=2.10.6" },
|
||||
]
|
||||
@@ -57,6 +130,19 @@ requires-dist = [
|
||||
[package.metadata.requires-dev]
|
||||
dev = [{ name = "rich", specifier = ">=13.9.4" }]
|
||||
|
||||
[[package]]
|
||||
name = "loguru"
|
||||
version = "0.7.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "win32-setctime", marker = "sys_platform == 'win32'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/3a/05/a1dae3dffd1116099471c643b8924f5aa6524411dc6c63fdae648c4f1aca/loguru-0.7.3.tar.gz", hash = "sha256:19480589e77d47b8d85b2c827ad95d49bf31b0dcde16593892eb51dd18706eb6", size = 63559 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/0c/29/0348de65b8cc732daa3e33e67806420b2ae89bdce2b04af740289c5c6c8c/loguru-0.7.3-py3-none-any.whl", hash = "sha256:31a33c10c8e1e10422bfd431aeb5d351c7cf7fa671e3c4df004162264b28220c", size = 61595 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lxml"
|
||||
version = "5.3.1"
|
||||
@@ -195,6 +281,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/19/71/39c7c0d87f8d4e6c020a393182060eaefeeae6c01dab6a84ec346f2567df/rich-13.9.4-py3-none-any.whl", hash = "sha256:6049d5e6ec054bf2779ab3358186963bac2ea89175919d699e378b99738c2a90", size = 242424 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sniffio"
|
||||
version = "1.3.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.12.2"
|
||||
@@ -203,3 +298,12 @@ sdist = { url = "https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec3
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", size = 37438 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "win32-setctime"
|
||||
version = "1.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b3/8f/705086c9d734d3b663af0e9bb3d4de6578d08f46b1b101c2442fd9aecaa2/win32_setctime-1.2.0.tar.gz", hash = "sha256:ae1fdf948f5640aae05c511ade119313fb6a30d7eabe25fef9764dca5873c4c0", size = 4867 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e1/07/c6fe3ad3e685340704d314d765b7912993bcb8dc198f0e7a89382d37974b/win32_setctime-1.2.0-py3-none-any.whl", hash = "sha256:95d644c4e708aba81dc3704a116d8cbc974d70b3bdb8be1d150e36be6e9d1390", size = 4083 },
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user