Skip to content

Add comprehensive dashboard management methods to Python API client #52

@egallis31

Description

@egallis31

Add comprehensive dashboard management methods to Python API client

Description

The JupiterOne Python API client lacks built-in methods for dashboard operations, forcing users to write direct GraphQL mutations for basic dashboard management tasks. While the GraphQL API supports comprehensive dashboard operations, the Python client does not expose these capabilities through convenient methods.

Current Behavior

The Python API client currently has no built-in dashboard management methods. Users must implement all dashboard operations using direct GraphQL mutations.

Current workaround:

def delete_dashboard(dashboard_id: str) -> None:
    """
    Helper function to delete a dashboard.
    """
    delete_dashboard_mutation = """
    mutation DeleteDashboard($dashboardId: String!) {
        deleteDashboard(dashboardId: $dashboardId) {
            success
            __typename
        }
    }
    """
    
    delete_variables = {"dashboardId": dashboard_id}
    delete_result = make_graphql_request(delete_dashboard_mutation, delete_variables, "DeleteDashboard")
    
    assert delete_result['data']['deleteDashboard']['success'], "Dashboard deletion failed."

Users must also manually implement create, update, and list operations using similar patterns.

Expected Behavior

The Python API client should provide comprehensive dashboard management methods that match the capabilities of the underlying GraphQL API.

Missing Methods

The following methods should be added to the JupiterOneClient class:

1. create_dashboard(name, type, resource_group_id=None)

dashboard = j1_client.create_dashboard(
    name="Security Dashboard",
    type="User",
    resource_group_id="resource-group-id"  # Optional
)

2. update_dashboard(dashboard_id, name=None, type=None, resource_group_id=None)

updated_dashboard = j1_client.update_dashboard(
    dashboard_id="dashboard-123",
    name="Updated Security Dashboard",
    resource_group_id="new-resource-group-id"
)

3. delete_dashboard(dashboard_id)

success = j1_client.delete_dashboard(dashboard_id="dashboard-123")

4. list_dashboards(resource_group_id=None)

# List all dashboards
all_dashboards = j1_client.list_dashboards()

# List dashboards in specific resource group
rg_dashboards = j1_client.list_dashboards(resource_group_id="resource-group-id")

5. get_dashboard_details(dashboard_id)

dashboard_details = j1_client.get_dashboard_details(dashboard_id="dashboard-123")

Code Example

Current state (manual GraphQL required):

# Users must write direct GraphQL mutations
create_dashboard_mutation = """
mutation CreateDashboard($input: CreateInsightsDashboardInput!) {
    createDashboard(input: $input) {
        id
        name
        type
        __typename
    }
}
"""

variables = {
    "input": {
        "name": "My Dashboard",
        "type": "User"
    }
}

# Manual GraphQL request handling
result = make_graphql_request(create_dashboard_mutation, variables, "CreateDashboard")
dashboard_id = result['data']['createDashboard']['id']

Desired API experience:

# What we want to be able to do
dashboard = j1_client.create_dashboard(
    name="My Dashboard",
    type="User",
    resource_group_id="rg-id"
)

# List and manage dashboards easily
dashboards = j1_client.list_dashboards()
dashboard_details = j1_client.get_dashboard_details(dashboard['id'])

# Update and delete 
j1_client.update_dashboard(dashboard['id'], name="Updated Dashboard")
j1_client.delete_dashboard(dashboard['id'])

Consistency with Other Methods

Other resource management operations in the client follow consistent patterns:

# Alert rules have comprehensive management
alerts = j1_client.list_alert_rules()
alert = j1_client.create_alert_rule(name="Alert", ...)
j1_client.update_alert_rule(rule_id="123", ...)
j1_client.delete_alert_rule(rule_id="123")

# Integration instances have partial management
instances = j1_client.fetch_integration_instances()
integration = j1_client.create_integration_instance(...)
# Missing: update, delete, list with filters

# Dashboards have NO management methods (this issue)

Impact

This limitation affects:

  • Developer Experience: Users must write and maintain custom GraphQL code
  • Code Maintainability: Direct GraphQL mutations are harder to maintain than client methods
  • API Consistency: Dashboard operations don't follow the same patterns as other resources
  • Resource Group Integration: No built-in support for resource group assignment/filtering
  • Error Handling: Users must implement their own error handling for GraphQL responses

Proposed Solution

Add comprehensive dashboard management methods to the JupiterOneClient class following the established patterns from other resource methods.

Environment

  • JupiterOne Python API Client: v1.5.0
  • Python: 3.8+

Additional Context

This issue was identified during automated testing where dashboard lifecycle management is required. The current approach of writing custom GraphQL mutations creates maintenance overhead and inconsistency with other API client methods.

The dashboard operations are commonly used in:

  • Automated dashboard provisioning
  • CI/CD pipeline dashboard management
  • Resource group organization workflows
  • Dashboard template deployment

Related Issues

  • Integration instance lifecycle management methods (similar pattern needed)
  • Question/insight management methods (similar pattern needed)
  • Resource group parameter support across all creation methods

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions