Skip to content

feat: commshub Template and Report Group support [ENG-1180] #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stacklet/client/platform/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from .policycollection import policy_collection
from .repository import repository
from .user import user
from .templates import templates
from .report_groups import report_groups

commands = [
account,
Expand All @@ -16,6 +18,8 @@
graphql,
policy,
policy_collection,
report_groups,
repository,
templates,
user,
]
292 changes: 292 additions & 0 deletions stacklet/client/platform/commands/report_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import json
import click

from stacklet.client.platform.executor import _run_graphql
from stacklet.client.platform.executor import StackletGraphqlExecutor, snippet_options
from stacklet.client.platform.graphql import StackletGraphqlSnippet
from stacklet.client.platform.utils import click_group_entry, default_options


@StackletGraphqlExecutor.registry.register("create-report-group")
class CreateReportGroup(StackletGraphqlSnippet):
name = "create-report-group"
pagination = False
parameter_types = {"input": "ReportGroupInput"}
snippet = """
mutation {
addReportGroup(input: $input) {
reportGroup{
id
name
schedule
groupBy
useMessageSettings
source
bindings
deliverySettings {
... on EmailSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
subject
fromEmail
cc
priority
format
}
... on SlackSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
}
... on JiraSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
summary
project
description
}
}
}
}
}
"""


@StackletGraphqlExecutor.registry.register("get-report-group")
class QueryReportGroup(StackletGraphqlSnippet):
name = "get-report-group"
pagination = False
snippet = """
query {
reportGroup(name: $name) {
id
name
schedule
groupBy
useMessageSettings
source
bindings
deliverySettings {
... on EmailSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
subject
fromEmail
cc
priority
format
}
... on SlackSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
}
... on JiraSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
summary
project
description
}
}
}
}
"""
required = {"name": ""}


@StackletGraphqlExecutor.registry.register("list-report-groups")
class QueryReportGroups(StackletGraphqlSnippet):
name = "list-report-groups"
pagination = True
snippet = """
query {
reportGroups(
binding: $binding
first: $first
last: $last
after: $after
before: $before
) {
edges {
node {
id
name
schedule
groupBy
useMessageSettings
source
bindings
deliverySettings {
... on EmailSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
subject
fromEmail
cc
priority
format
}
... on SlackSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
}
... on JiraSettings {
type
template
recipients {
value
tag
account_owner
resource_owner
}
summary
project
description
}
}
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
"""
optional = {"binding": ""}


@StackletGraphqlExecutor.registry.register("remove-report-group")
class RemoveReportGroup(StackletGraphqlSnippet):
name = "remove-report-group"
pagination = False
snippet = """
mutation {
removeReportGroup(name: "$name")
}
"""
required = {"name": ""}


@click.group(short_help="Run report groups queries/mutations")
@default_options()
@click.pass_context
def report_groups(*args, **kwargs):
"""
Query against and Run mutations against Report Group objects in Stacklet

Define a custom config file with the --config option

Specify a different output format with the --output option

Example:

$ stacklet repository --output json list

"""
click_group_entry(*args, **kwargs)


@report_groups.command()
@click.pass_context
@click.option("--file", help="Json file with Report Group.")
def create(ctx, file):
"""
Create a new or update an existing report-group
"""

with open(file, "rt") as f:
data = json.load(f)

data["emailSettings"] = [
d for d in data.get("deliverySettings", []) if d["type"] == "email"
]
data["slackSettings"] = [
d for d in data.get("deliverySettings", []) if d["type"] == "slack"
]
data["jiraSettings"] = [
d for d in data.get("deliverySettings", []) if d["type"] == "jira"
]
data.pop("deliverySettings", None)
click.echo(
_run_graphql(ctx=ctx, name="create-report-group", variables={"input": data})
)


@report_groups.command()
@snippet_options("list-report-groups")
@click.pass_context
def list(ctx, **kwargs):
"""
Query all report-groups
"""
click.echo(_run_graphql(ctx=ctx, name="list-report-groups", variables=kwargs))


@report_groups.command()
@snippet_options("get-report-group")
@click.pass_context
def get(ctx, **kwargs):
"""
Query a specific report-group
"""
click.echo(_run_graphql(ctx=ctx, name="get-report-group", variables=kwargs))


@report_groups.command()
@snippet_options("remove-report-group")
@click.pass_context
def remove(ctx, **kwargs):
"""
Remove report-group
"""
click.echo(_run_graphql(ctx=ctx, name="remove-report-group", variables=kwargs))
Loading