Skip to content

Commit

Permalink
Comment out some stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Oct 10, 2023
1 parent 2ab54ef commit 2f968e6
Showing 1 changed file with 54 additions and 52 deletions.
106 changes: 54 additions & 52 deletions stack/cloud_function_ais_analysis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""cloud function to find slick culprits from AIS tracks"""
import os
import time
# import os
# import time

import database
import pulumi
from pulumi_gcp import cloudfunctions, cloudtasks, projects, serviceaccount, storage
from pulumi_gcp import cloudtasks, storage

# from pulumi_gcp import cloudfunctions, cloudtasks, projects, serviceaccount, storage
from utils import construct_name

stack = pulumi.get_stack()
Expand Down Expand Up @@ -50,58 +52,58 @@
# The Cloud Function source code itself needs to be zipped up into an
# archive, which we create using the pulumi.AssetArchive primitive.
PATH_TO_SOURCE_CODE = "../cerulean_cloud/cloud_function_ais_analysis"
assets = {}
for file in os.listdir(PATH_TO_SOURCE_CODE):
location = os.path.join(PATH_TO_SOURCE_CODE, file)
asset = pulumi.FileAsset(path=location)
assets[file] = asset
# assets = {}
# for file in os.listdir(PATH_TO_SOURCE_CODE):
# location = os.path.join(PATH_TO_SOURCE_CODE, file)
# asset = pulumi.FileAsset(path=location)
# assets[file] = asset

archive = pulumi.AssetArchive(assets=assets)
# archive = pulumi.AssetArchive(assets=assets)

# Create the single Cloud Storage object, which contains all of the function's
# source code. ("main.py" and "requirements.txt".)
source_archive_object = storage.BucketObject(
construct_name("source-cloud-function-ais"),
name="handler.py-%f" % time.time(),
bucket=bucket.name,
source=archive,
)
# # Create the single Cloud Storage object, which contains all of the function's
# # source code. ("main.py" and "requirements.txt".)
# source_archive_object = storage.BucketObject(
# construct_name("source-cloud-function-ais"),
# name="handler.py-%f" % time.time(),
# bucket=bucket.name,
# source=archive,
# )

# Assign access to cloud SQL
cloud_function_service_account = serviceaccount.Account(
construct_name("cloud-function-ais"),
account_id=f"{stack}-cloud-function-ais",
display_name="Service Account for cloud function.",
)
cloud_function_service_account_iam = projects.IAMMember(
construct_name("cloud-function-ais-iam"),
project=pulumi.Config("gcp").require("project"),
role="projects/cerulean-338116/roles/cloudfunctionaisanalysisrole",
member=cloud_function_service_account.email.apply(
lambda email: f"serviceAccount:{email}"
),
)
# # Assign access to cloud SQL
# cloud_function_service_account = serviceaccount.Account(
# construct_name("cloud-function-ais"),
# account_id=f"{stack}-cloud-function-ais",
# display_name="Service Account for cloud function.",
# )
# cloud_function_service_account_iam = projects.IAMMember(
# construct_name("cloud-function-ais-iam"),
# project=pulumi.Config("gcp").require("project"),
# role="projects/cerulean-338116/roles/cloudfunctionaisanalysisrole",
# member=cloud_function_service_account.email.apply(
# lambda email: f"serviceAccount:{email}"
# ),
# )

fxn = cloudfunctions.Function(
function_name,
name=function_name,
entry_point="main",
environment_variables=config_values,
region=pulumi.Config("gcp").require("region"),
runtime="python38",
source_archive_bucket=bucket.name,
source_archive_object=source_archive_object.name,
trigger_http=True,
service_account_email=cloud_function_service_account.email,
)
# fxn = cloudfunctions.Function(
# function_name,
# name=function_name,
# entry_point="main",
# environment_variables=config_values,
# region=pulumi.Config("gcp").require("region"),
# runtime="python38",
# source_archive_bucket=bucket.name,
# source_archive_object=source_archive_object.name,
# trigger_http=True,
# service_account_email=cloud_function_service_account.email,
# )

invoker = cloudfunctions.FunctionIamMember(
construct_name("cloud-function-ais-invoker"),
project=fxn.project,
region=fxn.region,
cloud_function=fxn.name,
role="roles/cloudfunctions.invoker",
member="allUsers",
)
# invoker = cloudfunctions.FunctionIamMember(
# construct_name("cloud-function-ais-invoker"),
# project=fxn.project,
# region=fxn.region,
# cloud_function=fxn.name,
# role="roles/cloudfunctions.invoker",
# member="allUsers",
# )

config_values["FUNCTION_URL"] = fxn.https_trigger_url
# config_values["FUNCTION_URL"] = fxn.https_trigger_url

0 comments on commit 2f968e6

Please sign in to comment.