Skip to content

Add basic support for Security App (Domains & Resource Associations)#59

Merged
PaulWinterstein merged 5 commits into
mainfrom
58-add-basic-support-for-security-app-domains-resource-associations
Aug 1, 2025
Merged

Add basic support for Security App (Domains & Resource Associations)#59
PaulWinterstein merged 5 commits into
mainfrom
58-add-basic-support-for-security-app-domains-resource-associations

Conversation

@PaulWinterstein

@PaulWinterstein PaulWinterstein commented Jul 17, 2025

Copy link
Copy Markdown
Collaborator

Resolves #58

Summary

Add initial support for Security App: domain management and resource associations.

This includes:

  • Full CRUD support for security domains
  • Managing domain memberships of resources (currently: devices and profiles)
  • Conversion utilities for domain ID ↔ name mapping

🚧 Limitations

Currently, only the following resource types are supported:

  • device:<id>
  • profile:<id>

The following types are planned but not yet implemented:

  • Panel project
  • Endpoint group
  • Junction
  • Macro
  • Manual service
  • Matrix

Domain Examples

1. Fetch domain by name

domain_studio_a = app.security.domains.get_domain_by_name("Studio A")
print(f"Found domain: {domain_studio_a.name} - {domain_studio_a.description}")
# > Found domain: Studio A - Domain for Studio A

2. Create a new domain

new_domain = app.security.domains.create_domain(
    name="Studio B", description="Domain for production devices in Studio B"
)
print(f"Created domain: {new_domain.name} (ID: {new_domain.id})")
# > Created domain: Studio B (ID: grp:a1122bdf-ee43-46ba-b7e2-30d1b2a1c8f6)

3. Fetch domain by ID

domain_by_id = app.security.domains.get_domain_by_id("grp:a1122bdf-ee43-46ba-b7e2-30d1b2a1c8f6")
print(f"Found domain by ID: {domain_by_id.name} - {domain_by_id.description}")
# > Found domain by ID: Studio B - Domain for production devices in Studio B

4. Update domain description

domain_studio_a.description = "Domain for production devices in Studio A"
updated_domain = app.security.domains.update_domain(domain_studio_a)
print(f"Updated domain description: {updated_domain.description}")
# > Updated domain description: Domain for production devices in Studio A

5. List all domain names

all_domains = app.security.domains.list_domain_names()
print(f"Available domains: {all_domains}")
# > Available domains: ['Studio A', 'Studio B']

6. Remove domain

app.security.domains.remove_domain(new_domain)
print("Domain removed successfully")
# > Domain removed successfully

all_domains_after_removal = app.security.domains.list_domain_names()
print(f"Available domains after removal: {all_domains_after_removal}")
# > Available domains after removal: ['Studio A']

Resources Examples

1. Get Domains of a Device

device_id = "device1"

# Get device memberships
device_memberships = app.security.resources.get_device_memberships(device_id)
print(f"Device {device_id} memberships: {device_memberships}")
# > Device device1 memberships: id='device:device1' vid='device:device1' rev='4-192ee52a-d6ff-4306-aef3-5237ee95ea57' domains=['grp:ffef30a6-9aef-49ee-b00f-aeed0f22c5d2']

# Convert domain IDs to human-readable names
domain_names = app.security.resources.convert_domain_ids_to_names(device_memberships.domains)


print(f"Device {device_id} belongs to domain/s: {domain_names}")
# > Device device1 belongs to domain/s: ['Studio A']

2. Add Domain to a Device

device_id = "device1"
domain_name = "Studio B"

# Get current device memberships
device_memberships = app.security.resources.get_device_memberships(device_id)
print(f"Current domains: {app.security.resources.convert_domain_ids_to_names(device_memberships.domains)}")
# > Current domains: ['Studio A']

# Add domain to membership object
updated_memberships = app.security.resources.add_domain_by_name_to_membership_object(
    domain_name, device_memberships
)

# Apply changes to the server
app.security.resources.update_memberships(updated_memberships)

# Verify the change
final_memberships = app.security.resources.get_device_memberships(device_id)
final_domains = app.security.resources.convert_domain_ids_to_names(final_memberships.domains)
print(f"Device {device_id} now belongs to domains: {final_domains}")
# > Device device1 now belongs to domains: ['Studio A', 'Studio B']

3. Remove Domain from a Device

device_id = "device1"
domain_name = "Studio A"

# Get current device memberships
device_memberships = app.security.resources.get_device_memberships(device_id)
print(f"Current domains: {app.security.resources.convert_domain_ids_to_names(device_memberships.domains)}")
# > Current domains: ['Studio A', 'Studio B']

# Remove domain from membership object
updated_memberships = app.security.resources.remove_domain_by_name_from_membership_object(
    domain_name, device_memberships
)

# Apply changes to the server
result = app.security.resources.update_memberships(updated_memberships)

# Verify the change
if result is None:
    print(f"Device {device_id} was removed from all domains")
    # > Device device1 was removed from all domains
else:
    final_domains = app.security.resources.convert_domain_ids_to_names(result.domains)
    print(f"Device {device_id} now belongs to domains: {final_domains}")
    # > Device device1 now belongs to domains: ['Studio B']

@PaulWinterstein PaulWinterstein changed the title project structure, add model and crud methods for domains (api layer) Add basic support for Security App (Domains & Resource Associations) Jul 24, 2025
@PaulWinterstein PaulWinterstein marked this pull request as ready for review August 1, 2025 18:30

@JonasScholl JonasScholl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@PaulWinterstein PaulWinterstein merged commit b55cf35 into main Aug 1, 2025
7 checks passed
@PaulWinterstein PaulWinterstein deleted the 58-add-basic-support-for-security-app-domains-resource-associations branch August 1, 2025 19:10
@PaulWinterstein PaulWinterstein self-assigned this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add basic support for Security App (Domains & Resource Associations)

2 participants