def email_service_alarm_test(event, context):
    env_name = utils.get_environment_name()
    if env_name == 'prod':
        client = EmailsApiClient(correlation_id=event['correlation_id'])
        response = client.send_email(email_dict={'brew_coffee': True})
        assert response['statusCode'] == HTTPStatus.METHOD_NOT_ALLOWED, f'Email {ERROR_MESSAGE} {response}'
        return response
 def check_project_task_exists(self):
     env_name = utils.get_environment_name()
     if env_name == "prod":
         core_api_url = "https://api.thiscovery.org/"
     else:
         core_api_url = f"https://{env_name}-api.thiscovery.org/"
     result = utils.aws_get(
         endpoint_url="v1/project",
         base_url=core_api_url,
     )
     assert (result["statusCode"] == HTTPStatus.OK
             ), f"Call to core API returned error: {result}"
     projects = json.loads(result["body"])
     project_task_ids = list()
     for p in projects:
         tasks = p["tasks"]
         for t in tasks:
             project_task_ids.append(t["id"])
     if self.project_task_id not in project_task_ids:
         raise utils.ObjectDoesNotExistError(
             f"Project tasks id {self.project_task_id} not found in Thiscovery database",
             details={
                 "project_task_ids": project_task_ids,
                 "correlation_id": self.correlation_id,
             },
         )
     return True
Beispiel #3
0
    def setUpClass(cls):
        super().setUpClass()

        # test appointments - no notifications default to have links and not require notifications
        cls.at3 = app.AppointmentType(
            ddb_client=cls.aa1._ddb_client,
            acuity_client=cls.aa1._acuity_client,
            logger=cls.logger,
        )
        cls.at3.from_dict({
            "type_id":
            cls.test_data["test_appointment_no_notif_id"],
            "has_link":
            True,
            "send_notifications":
            False,
            "project_task_id":
            cls.test_data["project_task_id"],
        })
        cls.at3.ddb_dump(update_allowed=True)

        # create test appointments
        cls.aa1.ddb_dump()
        cls.aa1._ddb_client.update_item(
            table_name=app.APPOINTMENTS_TABLE,
            key=cls.aa1.appointment_id,
            name_value_pairs={
                "participant_email":
                TESTER_EMAIL_MAP[utils.get_environment_name(
                )]  # so that participant notification go to tester
            },
        )

        cls.aa2 = app.AcuityAppointment(
            appointment_id=cls.test_data["test_appointment_no_notif_id"],
            logger=cls.logger,
        )
        cls.aa2.ddb_dump()
        cls.aa2._ddb_client.update_item(
            table_name=app.APPOINTMENTS_TABLE,
            key=cls.aa2.appointment_id,
            name_value_pairs={
                "participant_email":
                TESTER_EMAIL_MAP[utils.get_environment_name(
                )]  # so that participant notification go to tester
            },
        )
def main(webhook_ids):
    logger = utils.get_logger()
    ac = AcuityClient()
    webhooks = ac.get_webhooks()
    env_name = utils.get_environment_name()
    for wh in webhooks:
        if wh["id"] in webhook_ids:
            print("Acuity webhook details:")
            pprint(wh)
            confirmation = input(
                "Are you sure you want to delete the webhook above? (y/n)")
            if confirmation.lower() == "y":
                ac.delete_webhooks(wh["id"])
                logger.info("Deleted Acuity webhook", extra={"webhook": wh})
            print("")
Beispiel #5
0
    def post_webhooks(self, appointment_event, target=None):
        if target is None:
            env_name = utils.get_environment_name()
            if env_name == "prod":
                api_base_url = f"https://interviews-api.thiscovery.org"
            else:
                api_base_url = f"https://{env_name}-interviews-api.thiscovery.org"
            target = f"{api_base_url}/v1/interview-appointment"

        body_params = {
            "event": appointment_event,
            "target": target,
        }
        body_json = json.dumps(body_params)
        return self.session.post(f"{self.base_url}webhooks", data=body_json)
Beispiel #6
0
 def populate_calendars_table(cls):
     calendar1 = {
         "block_monday_morning":
         True,
         "details": {
             "description": "",
             "email": "",
             "id": 4038206,
             "image": False,
             "location": "",
             "name": "André",
             "thumbnail": False,
             "timezone": "Europe/London",
         },
         "emails_to_notify": [
             TESTER_EMAIL_MAP[utils.get_environment_name()],
             "*****@*****.**",
         ],
         "id":
         "4038206",
         "label":
         "André",
     }
     calendar2 = copy.deepcopy(calendar1)
     calendar2["id"] = "3887437"
     calendar2["details"]["id"] = 3887437
     for calendar in [calendar1, calendar2]:
         calendar_details = calendar["details"]
         del calendar["details"]
         try:
             cls.aa1._ddb_client.put_item(
                 table_name=app.AppointmentNotifier.calendar_table,
                 key=calendar["id"],
                 item_type="acuity-calendar",
                 item_details=calendar_details,
                 item=calendar,
             )
         except utils.DetailedValueError:
             pass
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   A copy of the GNU Affero General Public License is available in the
#   docs folder of this project.  It is also available www.gnu.org/licenses/
#
import api.local.dev_config  # env variables
import api.local.secrets  # env variables
import psycopg2

import thiscovery_lib.utilities as utils
from api.endpoints.common.pg_utilities import run_sql_script_file, execute_non_query

VIEW_SQL_FOLDER = "./"
ENVIRONMENT_NAME = utils.get_environment_name()


def emph(string):
    return f"\033[92m\033[1m{string}\033[0m"


def create_all_views():
    def execute_sql_script(script_file, view_name):
        run_sql_script_file(VIEW_SQL_FOLDER + script_file, None)
        print(
            f"Successfully created or updated database view {emph(view_name)} on environment {emph(ENVIRONMENT_NAME)}"
        )

    files_and_views = [
        ("view_project_group_users_create.sql", "project_group_users"),
Beispiel #8
0
def non_prod_env_url_param(target_env="prod"):
    if get_environment_name() == target_env:
        return ""
    else:
        return "&env=" + get_environment_name()
Beispiel #9
0
#
"""
This script creates or updates CloudWatch alarms that monitor more than one resource and
that trigger an SNS notification if state is not OK
"""
import thiscovery_lib.utilities as utils
from api.endpoints.common.cloudwatch_utilities import CloudWatch
from api.local.secrets import ACCOUNT_MAP


def get_db_instance_identifier():
    host = utils.get_secret("database-connection")["host"]
    return host.split(".")[0]


env_name = utils.get_environment_name()
account_number = ACCOUNT_MAP.get(env_name)

base_template = {
    "ActionsEnabled": True,
    "AlarmActions": [f"arn:aws:sns:eu-west-1:{account_number}:AWS-Alerts"],
    "InsufficientDataActions": [],
    "OKActions": [],
}

api_template = {
    **base_template,
    "ComparisonOperator":
    "GreaterThanOrEqualToThreshold",
    "Dimensions": [
        {