Skip to content

Commit

Permalink
fix: code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanclaudio committed Apr 29, 2024
1 parent c18ed34 commit b1d8fc0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

node_modules/

secrets.json
.pdm-python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 0 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def home(request):


def google_calendar_init_view(request):
print(settings.ENVIRONMENT)
config = get_secret(f"{settings.ENVIRONMENT}/google/calendar")
creds = CredentialsService.init_for(request.user, scopes=SCOPES)
if not creds or not creds.valid:
Expand Down
33 changes: 16 additions & 17 deletions webapp/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@


def get_secret(secret_name, region_name="sa-east-1"):
if "dev" in secret_name:
try:
with open(os.path.join(os.getcwd(), 'webapp/secrets.json'), 'r') as f:
secrets = json.load(f)
return secrets[secret_name]
except Exception as e_:
raise e_ from e
else:
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)

try:
session = boto3.session.Session()
try:
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
except Exception as e:
print(e)
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)

with open(os.path.join(os.getcwd(), 'webapp/secrets.json'), 'r') as f:
secrets = json.load(f)
except ClientError as e:
# For a list of exceptions thrown, see
# https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
raise e

return json.loads(json.loads(get_secret_value_response['SecretString'])['credentials'])
raise e
except Exception as e:
raise e from e

return secrets[secret_name], json.loads(json.loads(get_secret_value_response['SecretString'])['credentials'])

0 comments on commit b1d8fc0

Please sign in to comment.