Skip to content

Commit 87f6bdb

Browse files
Merge branch 'master' into disable_elementary_logo_print
2 parents d0f03f7 + 823ceed commit 87f6bdb

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

elementary/clients/s3/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ def send_report(
4141
bucket_report_path = remote_bucket_file_path or report_filename
4242
bucket_website_url = None
4343
logger.info(f'Uploading to S3 bucket "{self.config.s3_bucket_name}"')
44+
45+
extra_args = {"ContentType": "text/html"}
46+
if self.config.s3_acl is not None:
47+
extra_args["ACL"] = self.config.s3_acl
4448
self.client.upload_file(
4549
local_html_file_path,
4650
self.config.s3_bucket_name,
4751
bucket_report_path,
48-
ExtraArgs={"ContentType": "text/html"},
52+
ExtraArgs=extra_args,
4953
)
5054
logger.info("Uploaded report to S3.")
5155
if self.config.update_bucket_website:

elementary/config/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
aws_session_token: Optional[str] = None,
6363
s3_endpoint_url: Optional[str] = None,
6464
s3_bucket_name: Optional[str] = None,
65+
s3_acl: Optional[str] = None,
6566
google_project_name: Optional[str] = None,
6667
google_service_account_path: Optional[str] = None,
6768
gcs_bucket_name: Optional[str] = None,
@@ -159,6 +160,7 @@ def __init__(
159160
self.aws_access_key_id = aws_access_key_id
160161
self.aws_secret_access_key = aws_secret_access_key
161162
self.aws_session_token = aws_session_token
163+
self.s3_acl = s3_acl
162164

163165
google_config = config.get(self._GOOGLE, {})
164166
self.google_project_name = self._first_not_none(

elementary/monitor/cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from elementary.monitor.data_monitoring.schema import FiltersSchema
1313
from elementary.monitor.data_monitoring.selector_filter import SelectorFilter
14+
from elementary.monitor.dbt_init import DBTInit
1415
from elementary.monitor.debug import Debug
1516
from elementary.tracking.anonymous_tracking import AnonymousCommandLineTracking
1617
from elementary.utils import bucket_path
@@ -24,6 +25,7 @@ class Command:
2425
REPORT = "monitor-report"
2526
SEND_REPORT = "monitor-send-report"
2627
DEBUG = "debug"
28+
DBT_INIT = "dbt-init"
2729

2830

2931
# Displayed in reverse order in --help.
@@ -526,6 +528,12 @@ def report(
526528
default=None,
527529
help="The name of the S3 bucket to upload the report to.",
528530
)
531+
@click.option(
532+
"--s3-acl",
533+
type=str,
534+
default=None,
535+
help="S3 Canned ACL value used to modify report permissions, for example set to 'public-read' to make the report publicly accessible.",
536+
)
529537
@click.option(
530538
"--google-service-account-path",
531539
type=str,
@@ -638,6 +646,7 @@ def send_report(
638646
aws_session_token,
639647
s3_endpoint_url,
640648
s3_bucket_name,
649+
s3_acl,
641650
azure_connection_string,
642651
azure_container_name,
643652
google_service_account_path,
@@ -686,6 +695,7 @@ def send_report(
686695
azure_container_name=azure_container_name,
687696
s3_endpoint_url=s3_endpoint_url,
688697
s3_bucket_name=s3_bucket_name,
698+
s3_acl=s3_acl,
689699
google_service_account_path=google_service_account_path,
690700
google_project_name=google_project_name,
691701
gcs_bucket_name=gcs_bucket_name,
@@ -766,5 +776,25 @@ def debug(ctx, profiles_dir):
766776
anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name)
767777

768778

779+
@monitor.command()
780+
@click.pass_context
781+
def dbt_init(ctx):
782+
"""
783+
Initializes the Elementary internal dbt project by installing its dbt deps.
784+
Run this command after installing EDR as part of builds or CI/CD pipelines when the target
785+
environment does not have write permissions on disk or does not have internet connection.
786+
This command is not needed in most cases as the dbt deps are installed automatically when running `edr monitor`.
787+
"""
788+
config = Config()
789+
anonymous_tracking = AnonymousCommandLineTracking(config)
790+
anonymous_tracking.track_cli_start(Command.DEBUG, None, ctx.command.name)
791+
dbtinit = DBTInit()
792+
success = dbtinit.setup_internal_dbt_packages()
793+
if not success:
794+
sys.exit(1)
795+
click.echo("Elementary internal dbt project has been initialized successfully. ")
796+
anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name)
797+
798+
769799
if __name__ == "__main__":
770800
monitor()

elementary/monitor/dbt_init.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from elementary.clients.dbt.factory import create_dbt_runner
2+
from elementary.monitor import dbt_project_utils
3+
4+
5+
class DBTInit:
6+
"""
7+
Class to handle the initialization of dbt for the Elementary CLI.
8+
This can contain all dbt static setup to avoid pulling in runtime dependencies or any other information from internet
9+
that is internally used by edr.
10+
"""
11+
12+
def setup_internal_dbt_packages(self):
13+
"""
14+
Run dbt deps to install internal dbt packages if needed.
15+
It intentionally does not use self.config.run_dbt_deps_if_needed parameter in create_dbt_runner to ensure
16+
that dbt deps is always run when setting up the internal dbt packages.
17+
"""
18+
dbt_runner = create_dbt_runner(dbt_project_utils.CLI_DBT_PROJECT_PATH)
19+
return dbt_runner.deps()

0 commit comments

Comments
 (0)