Skip to content

Commit

Permalink
Merge pull request #103 from stat-kwon/master
Browse files Browse the repository at this point in the history
Add NotFound Exception when not using GCS in cloud functions
  • Loading branch information
stat-kwon authored Sep 14, 2023
2 parents 762d1eb + 150028c commit f920401
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from datetime import datetime, timedelta
import google.oauth2.service_account
from google.cloud import storage
from google.api_core.exceptions import NotFound
from zipfile import ZipFile
from zipfile import is_zipfile
import io

from spaceone.inventory.libs.manager import GoogleCloudManager
from spaceone.inventory.libs.schema.base import ReferenceModel
from spaceone.inventory.connector.cloud_functions.function_gen1 import FunctionGen1Connector
from spaceone.inventory.connector.cloud_functions.eventarc import EventarcConnector
from spaceone.inventory.model.cloud_functions.function_gen1.cloud_service_type import CLOUD_SERVICE_TYPES, cst_function
from spaceone.inventory.model.cloud_functions.function_gen1.cloud_service import FunctionResource, FunctionResponse
from spaceone.inventory.model.cloud_functions.function_gen1.data import FunctionGen1
Expand Down Expand Up @@ -89,12 +89,21 @@ def collect_cloud_service(self, params):

if function.get('sourceUploadUrl'):
bucket = self._make_bucket_from_build_name(function.get('buildName'))
source_location, source_code = self._get_source_location_and_code(bucket, function_id, secret_data)

display.update({
'source_location': source_location,
'source_code': source_code
})
try:
source_location, source_code = self._get_source_location_and_code(
bucket, function_id, secret_data
)

display.update({
'source_location': source_location,
'source_code': source_code
})
except NotFound:
_LOGGER.debug(
f'[collect_cloud_service] => {bucket} not found in bucket of GCS (function_id: {function_id})'
)
pass

if runtime_environment_variables := function.get('environmentVariables'):
display.update({
Expand All @@ -115,7 +124,6 @@ def collect_cloud_service(self, params):
'CloudFunctions', 'Function', project_id, function_id
)
})
print(function)

function_data = FunctionGen1(function, strict=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta
import google.oauth2.service_account
from google.cloud import storage
from google.api_core.exceptions import NotFound
from zipfile import ZipFile
from zipfile import is_zipfile
import io
Expand Down Expand Up @@ -96,10 +97,17 @@ def collect_cloud_service(self, params):
bucket = storage_source['bucket']
storage_object = storage_source['object']
source_location = self._make_source_location(bucket, storage_object)
display.update({
'source_location': source_location,
'source_code': self._make_source_code(bucket, storage_object, secret_data),
})

try:
display.update({
'source_location': source_location,
'source_code': self._make_source_code(bucket, storage_object, secret_data),
})
except NotFound:
_LOGGER.debug(
f'[collect_cloud_service] => {bucket} not found in bucket of GCS (function_id: {function_id})'
)
pass

if trigger_data := function.get('eventTrigger'):
trigger = self._get_event_provider_from_trigger_map(trigger_data.get('eventType'),
Expand Down Expand Up @@ -139,7 +147,6 @@ def collect_cloud_service(self, params):
'CloudFunctions', 'Function', project_id, function_id
)
})
print(function)

function_data = FunctionGen2(function, strict=False)

Expand Down

0 comments on commit f920401

Please sign in to comment.