Skip to content

Commit

Permalink
update docs and support regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tankilevitch committed Nov 8, 2023
1 parent be7bdc2 commit b13a047
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ Action to send a scorecard report to a Slack channel about the current metrics o

### Usage

| Input | Description | Required | Default |
| ----- |-----------------------------------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| `port_client_secret` | Port Client Secret | true | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Report, pass - `scorecard_report` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |
| Input | Description | Required | Default |
|----------------------|----------------------------------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| `port_client_secret` | Port Client Secret | true | |
| `port_region` | Port Region to use, if not provided will use the default region of the Port | false | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Report, pass - `scorecard_report` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |

```yaml
- uses: port-labs/[email protected]
Expand All @@ -48,15 +49,16 @@ A call to action to remind the team that some of their services didn't reach Gol
### Usage
| Input | Description | Required | Default |
| ----- |-------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| Input | Description | Required | Default |
|----------------------|-------------------------------------------------------------------------------|----------| ------- |
| `port_client_id` | Port Client ID | true | |
| `port_client_secret` | Port Client Secret | true | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Reminder, pass - `scorecard_reminder` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |
| `port_region` | Port Region to use, if not provided will use the default region of the Port | false | |
| `slack_webhook_url` | Slack Webhook URL | true | |
| `blueprint` | Blueprint identifier | true | |
| `scorecard` | Scorecard identifier | true | |
| `message_kind` | Message kind to send, to send Scorecard Reminder, pass - `scorecard_reminder` | true | |
| `filter_rule` | The [rule filter](https://docs.getport.io/search-and-query/#rules) to apply on the data queried from Port | false | |

In this example you can see how we filter for specific team and send a reminder to them.

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
port_client_secret:
description: 'The Port Client Secret to use to authenticate with the API'
required: true
port_region:
description: 'Port Region to use, if not provided will use the default region of the Port'
required: false
slack_webhook_url:
description: 'The URL of the Slack channel webhook to use to send messages'
required: true
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class FilterRule(BaseModel):


class Settings(BaseSettings):
port_api_url: str = "https://api.getport.io"
port_client_id: str
port_client_secret: str
slack_webhook_url: str
port_region: str = "eu"
blueprint: str
scorecard: str
filter_rule: Optional[FilterRule] = Field(default=None)
Expand Down
4 changes: 2 additions & 2 deletions core/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Handler:
@classmethod
def scorecard_reminder(cls):
logger.info("Initializing Port client")
port_client = PortClient(settings.port_api_url, settings.port_client_id, settings.port_client_secret)
port_client = PortClient(settings.port_region, settings.port_client_id, settings.port_client_secret)
logger.info(
f"Fetching entities for query: {settings.filter_rule}, blueprint {settings.blueprint}, scorecard {settings.scorecard}")
search_query = {
Expand Down Expand Up @@ -48,7 +48,7 @@ def scorecard_reminder(cls):
@classmethod
def scorecard_report(cls):
logger.info("Initializing Port client")
port_client = PortClient(settings.port_api_url, settings.port_client_id, settings.port_client_secret)
port_client = PortClient(settings.port_region, settings.port_client_id, settings.port_client_secret)
logger.info(
f"Fetching entities for query: {settings.filter_rule}, blueprint {settings.blueprint}, scorecard {settings.scorecard}")
search_query = {
Expand Down
7 changes: 5 additions & 2 deletions generators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import generators.base
import utils

from config import settings
from port.utils import get_port_url


class SlackMessageGenerator(generators.base.BaseMessageGenerator):

Expand Down Expand Up @@ -140,7 +143,7 @@ def scorecard_report(self, blueprint: str, scorecard: Dict[str, Any], entities:
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Visit the <https://app.getport.io/{blueprint}|Port> for more information."
"text": f"Visit the <{get_port_url(settings.port_region, 'app')}|Port> for more information."
}
}
]
Expand Down Expand Up @@ -273,7 +276,7 @@ def _calculate_top_teams_by_percentage(entities: list,
def _generate_entities_list_with_level_and_link(blueprint: str,
entities_by_level: Dict[str, List[Dict[str, str]]]) -> str:
text = ""
base_entity_url = f"https://app.getport.io/{blueprint}Entity?identifier="
base_entity_url = f"{get_port_url(settings.port_region, 'app')}/{blueprint}Entity?identifier="
for level, entities in entities_by_level.items():
if not entities:
continue
Expand Down
5 changes: 3 additions & 2 deletions port/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import requests

from port.utils import get_port_url

logger = logging.getLogger(__name__)


class PortClient:
def __init__(self, api_url: str, client_id:str, client_secret:str):
self.api_url = api_url
def __init__(self, region: str, client_id:str, client_secret:str):
self.api_url = get_port_url(region, "api")
self.access_token = self.get_token(client_id, client_secret)
self.headers = {
"Authorization": f"Bearer {self.access_token}",
Expand Down
5 changes: 5 additions & 0 deletions port/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

def get_port_url(region: str, kind: str = "app"):
if region != "eu":
return f"https://{kind}.{region}.getport.io"
return f"https://{kind}.getport.io"

0 comments on commit b13a047

Please sign in to comment.