Skip to content

Commit

Permalink
Merge pull request #8 from nathanielvarona/improvement/upgrade-runtim…
Browse files Browse the repository at this point in the history
…e-and-pritunl-url-to-secrets

Upgrade the Python Runtime and Put the Pritunl Base URL to Secrets
  • Loading branch information
nathanielvarona authored Apr 27, 2023
2 parents 2bb3558 + 75ef863 commit b31afe1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,3 @@ dmypy.json
.vscode
.envrc
.aws-sam
samconfig.toml
8 changes: 4 additions & 4 deletions pritunl_slack_app/function/pritunl_slack_app/pritunl_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json

from random import choice
from urllib.parse import urlparse

from slack_bolt import App

Expand All @@ -22,6 +21,7 @@
)

pritunl = Pritunl(
url = get_secret(os.environ['PRITUNL_BASE_URL']),
secret = get_secret(os.environ['PRITUNL_API_SECRET']),
token = get_secret(os.environ['PRITUNL_API_TOKEN'])
)
Expand Down Expand Up @@ -84,7 +84,7 @@ def processing_request(respond, body):
'pin' : user_pin,
}

org, user = org_user(pritunl_obj=pritunl, org_name=org_name, user_name=user_name)
org, user = org_user(pritunl=pritunl, org_name=org_name, user_name=user_name)

if user:
respond(f"Your profile already exists! \nUpdating your profile with new PIN.")
Expand All @@ -95,7 +95,7 @@ def processing_request(respond, body):
)

if update:
key_uri_url, key_view_url = profile_key(pritunl_obj=pritunl, org_id=update['organization'], usr_id=update['id'])
key_uri_url, key_view_url = profile_key(pritunl=pritunl, org_id=update['organization'], usr_id=update['id'])

respond_line = [
f"\n",
Expand All @@ -119,7 +119,7 @@ def processing_request(respond, body):

if create_user:
for user in create_user:
key_uri_url, key_view_url = profile_key(pritunl_obj=pritunl, org_id=user['organization'], usr_id=user['id'])
key_uri_url, key_view_url = profile_key(pritunl=pritunl, org_id=user['organization'], usr_id=user['id'])

respond_line = [
f"\n",
Expand Down
33 changes: 33 additions & 0 deletions samconfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# More information about the configuration file can be found here:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html
version = 0.1

[default]
[default.global.parameters]
stack_name = "pritunl-slack-app"

[default.build.parameters]
cached = true
parallel = true

[default.validate.parameters]
lint = true

[default.deploy.parameters]
capabilities = "CAPABILITY_IAM"
confirm_changeset = true
resolve_s3 = true
s3_prefix = "pritunl-slack-app"
region = "us-east-1"

[default.package.parameters]
resolve_s3 = true

[default.sync.parameters]
watch = true

[default.local_start_api.parameters]
warm_containers = "EAGER"

[default.local_start_lambda.parameters]
warm_containers = "EAGER"
12 changes: 10 additions & 2 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Parameters:
PritunlBaseUrl:
Type: String
Description: Pritunl API Base Url
NoEcho: true

PritunlApiSecret:
Type: String
Expand Down Expand Up @@ -72,12 +73,12 @@ Resources:
Properties:
CodeUri: pritunl_slack_app/function
Handler: pritunl_slack_app.function_handler.handler
Runtime: python3.9
Runtime: python3.10
Architectures:
- x86_64
Environment:
Variables:
PRITUNL_BASE_URL: !Ref PritunlBaseUrl
PRITUNL_BASE_URL: !Ref AWSPritunlBaseUrl
PRITUNL_API_SECRET: !Ref AWSSecretPritunlApiSecret
PRITUNL_API_TOKEN: !Ref AWSSecretPritunlApiToken
SLACK_SIGNING_SECRET: !Ref AWSSecretSlackSigningSecret
Expand All @@ -93,6 +94,7 @@ Resources:
Action:
- "secretsmanager:GetSecretValue"
Resource:
- !Ref AWSPritunlBaseUrl
- !Ref AWSSecretPritunlApiSecret
- !Ref AWSSecretPritunlApiToken
- !Ref AWSSecretSlackSigningSecret
Expand Down Expand Up @@ -123,6 +125,12 @@ Resources:
TargetFunctionArn: !Ref PritunlSlackFunction
AuthType: NONE

AWSPritunlBaseUrl:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: PritunlBaseUrl
SecretString: !Ref PritunlBaseUrl

AWSSecretPritunlApiSecret:
Type: "AWS::SecretsManager::Secret"
Properties:
Expand Down

0 comments on commit b31afe1

Please sign in to comment.