-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Placeholder pull request for project-wide code review #30
Open
pauline2k
wants to merge
74
commits into
initial
Choose a base branch
from
main
base: initial
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
2e4c603
Updating comments and README.md
gmerritt c24815b
Adding Gregquestion as code to mark questions
gmerritt 27a8962
Ummm...GitHub is slow to index code for search?
gmerritt 5241435
Trivial edit b/c GitHub search one version behind?
gmerritt 48b8eed
Added additional Gregquestion tag
gmerritt d3eefab
Base working version, incl. new Gregquestion ?'s
gmerritt 31e87e4
Functional design diagram added to readme
gmerritt 7a4f929
VUE_... to VITE_... convention update + comments
gmerritt 844f849
Moved app-specific fnctn to /src/api/fetch-url.ts
gmerritt 2a9fc3a
Reworked internal api call from GET to POST
gmerritt 490144d
Page formatting, copy URL button, SI AA accessible
gmerritt 6d24c65
Made dl URL display text field uneditable
gmerritt f6fa332
Broken version that includes Greg CAS attempts
gmerritt 9252092
Fixes to CAS integration, session management
pauline2k 6639d04
Two tiny clean-ups before changes needing help
gmerritt 86289a5
'Gregquestion' comments re: currentUser snafu
gmerritt 7158bf0
user.py fix: from flask import current_app as app
gmerritt a91f0e0
Fetchurl.vue hip to change in post (response.data)
gmerritt c85d44b
Integrated to single .vue w/ tool+authorized_user
gmerritt 3d7864b
Port 5000 api now requires authorized user
gmerritt 3c09e44
Make gs:// url form field required
gmerritt b60a656
Cleaned all 'tox -e lint-py' warnings
gmerritt 906e073
Cleaned all 'tox -e lint-vue' warnings
gmerritt 6e4b776
Added a better input string regex format check
gmerritt 4851cc6
Trivial README change to get GH to prompt for PR
gmerritt 48f3a55
Getting synced with my latest; will use ets authoritative going forward
gmerritt 18ebc9a
Merge pull request #11 from gmerritt/main
johncrossman 2047dab
Preparing for CodeBuild for dev deployment attempts
gmerritt 031e9ab
Merge pull request #1 from ets-berkeley-edu/main
gmerritt 4ab60f2
A quick doodle that proposes to use AWS secrets rather than S3
gmerritt d435184
A quick doodle that proposes to use AWS secrets rather than S3 (clean…
gmerritt e1a7cbe
Quickie downgrade of node from 21 to 20 for Code Buil compatibility
gmerritt 7662aac
undoing fake secrets try (from s3)
gmerritt 3fd75fa
Merge pull request #12 from gmerritt/main
gmerritt b1877e9
Trying to fix fetchurl case
gmerritt 32a335d
Merge pull request #13 from gmerritt/main
gmerritt cf9494a
fixing build script path
gmerritt ddc8c9f
Merge pull request #14 from gmerritt/main
gmerritt 4b76aaa
ami config changes
gmerritt ea5a8f2
ami config changes
gmerritt 74ed106
cloudwatch agent change
gmerritt 4c5814f
Merge pull request #15 from gmerritt/main
gmerritt c8a6579
Merge pull request #2 from ets-berkeley-edu/main
gmerritt 1012008
Merge pull request #16 from gmerritt/main
gmerritt 6b9b2b7
Merge pull request #3 from ets-berkeley-edu/main
gmerritt 6ec3e60
Use AWS Secrets for bot local & deployed; no S3 secrets!
gmerritt eb46fd5
Merge pull request #17 from gmerritt/main
gmerritt 9554b2e
Removing S3-specific config handling
gmerritt fe75465
Merge pull request #4 from ets-berkeley-edu/main
gmerritt 84b77cd
Merge pull request #18 from gmerritt/main
gmerritt b2bf0ba
Merge pull request #5 from ets-berkeley-edu/main
gmerritt ab2c28b
Merge pull request #19 from gmerritt/main
gmerritt d6be48b
Removed reference to deleted ./scripts/*.sh
gmerritt 8a83e3d
Merge pull request #20 from gmerritt/main
gmerritt 1f7d7ed
Paths not jiving in deployment context; "fixing"
gmerritt 1e3090a
Merge pull request #21 from gmerritt/main
gmerritt 50a4585
Getting (too) explicit w/ index.html path to debug deployment
gmerritt d700854
Merge pull request #22 from gmerritt/main
gmerritt b84b149
Trying directory fix at build-vue level
gmerritt e9d0b18
Merge pull request #23 from gmerritt/main
gmerritt 7e50874
temporary code to debug the elastic beanstalk run context
gmerritt 02da69a
Merge pull request #24 from gmerritt/main
gmerritt 5e92102
Helping Elastic Beanstalk get the paths right to find js & css files
gmerritt 6f4a796
Merge pull request #25 from gmerritt/main
gmerritt 0d8401d
Removing "temporary code to debug the elastic beanstalk run context"
gmerritt f43bb48
Merge pull request #26 from gmerritt/main
gmerritt 886aff0
Leading and trailing blank space are now removed from user gs:// url …
gmerritt 627a291
Merge pull request #27 from gmerritt/main
gmerritt a6bb274
Clear contents of input and output fields when clicking back into inp…
gmerritt 7a31a8d
Merge pull request #28 from gmerritt/main
gmerritt 6dd4565
Formatting clean-ups from John C.'s feedback
gmerritt f743050
Merge pull request #31 from gmerritt/main
johncrossman 4f80277
Additional clean-ups from John C.'s feedback
gmerritt 3fe59ed
Merge pull request #32 from gmerritt/main
johncrossman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#### | ||
# Vue.js environment variables and modes: https://cli.vuejs.org/guide/mode-and-env.html | ||
# Only variables that start with 'VUE_APP_' will be statically embedded into the client bundle. | ||
# Only variables that start with 'VITE_APP_' will be statically embedded into the client bundle. | ||
#### | ||
|
||
VUE_APP_API_BASE_URL='' | ||
VUE_APP_DEBUG=false | ||
VITE_APP_API_BASE_URL='' | ||
VITE_APP_DEBUG=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#### | ||
# Vue.js environment variables and modes: https://cli.vuejs.org/guide/mode-and-env.html | ||
# Only variables that start with 'VUE_APP_' will be statically embedded into the client bundle. | ||
# Only variables that start with 'VITE_APP_' will be statically embedded into the client bundle. | ||
#### | ||
|
||
VUE_APP_API_BASE_URL='http://localhost:5000' | ||
VUE_APP_DEBUG=true | ||
VITE_APP_API_BASE_URL='http://localhost:5000' | ||
VITE_APP_DEBUG=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
16.14.0 | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
sudo mv /tmp/hartsfield.conf /etc/httpd/conf.d/hartsfield.conf | ||
sudo mv /tmp/ssl.conf /etc/httpd/conf.d/ssl.conf | ||
sudo /bin/systemctl restart httpd.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 0.2 | ||
|
||
phases: | ||
install: | ||
runtime-versions: | ||
nodejs: 20 | ||
gmerritt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
python: 3.11 | ||
commands: | ||
- node -v | ||
- npm install | ||
pre_build: | ||
commands: | ||
- echo "pre_build phase" | ||
build: | ||
commands: | ||
- npm run build-vue | ||
post_build: | ||
commands: | ||
- ./scripts/codebuild/create-build-summary.sh | ||
artifacts: | ||
files: | ||
- '.ebextensions/**/*' | ||
- 'dist/**/*' | ||
- 'requirements.txt' | ||
- 'hartsfield/**/*' | ||
- 'scripts/**/*' | ||
- 'application.py' | ||
- 'consoler.py' | ||
- 'config/**/*' | ||
- '.platform/**/*' | ||
- 'Procfile' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Copyright ©2022. The Regents of the University of California (Regents). All Rights Reserved. | ||
|
||
Permission to use, copy, modify, and distribute this software and its documentation | ||
for educational, research, and not-for-profit purposes, without fee and without a | ||
signed licensing agreement, is hereby granted, provided that the above copyright | ||
notice, this paragraph and the following two paragraphs appear in all copies, | ||
modifications, and distributions. | ||
|
||
Contact The Office of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, | ||
Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, otl@berkeley.edu, | ||
http://ipira.berkeley.edu/industry-info for commercial licensing opportunities. | ||
|
||
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, | ||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF | ||
THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE | ||
SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED | ||
"AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, | ||
ENHANCEMENTS, OR MODIFICATIONS. | ||
""" | ||
|
||
from functools import wraps | ||
|
||
from flask import current_app as app, request | ||
from flask_login import current_user | ||
from hartsfield.api.errors import UnauthorizedRequestError | ||
from hartsfield.models.user import find_by_uid | ||
|
||
|
||
def auth_required(f): | ||
@wraps(f) | ||
def decorated(*args, **kwargs): | ||
if not current_user.is_authenticated: | ||
auth = request.authorization | ||
if not auth or not valid_worker_credentials(auth.username, auth.password): | ||
raise UnauthorizedRequestError('Invalid credentials.') | ||
return f(*args, **kwargs) | ||
return decorated | ||
|
||
|
||
def authorzied_user_required(f): | ||
@wraps(f) | ||
def decorated(*args, **kwargs): | ||
uid = current_user.uid | ||
user = find_by_uid(uid) | ||
if user is None: | ||
auth = request.authorization | ||
if not auth: | ||
raise UnauthorizedRequestError('Invalid credentials.') | ||
return f(*args, **kwargs) | ||
return decorated | ||
|
||
|
||
def valid_worker_credentials(username, password): | ||
return username == app.config['API_USERNAME'] and password == app.config['API_PASSWORD'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,79 +22,73 @@ | |
"AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, | ||
ENHANCEMENTS, OR MODIFICATIONS. | ||
""" | ||
from collections import OrderedDict | ||
import json | ||
|
||
from flask import current_app as app | ||
from hartsfield import __version__ as version | ||
from hartsfield.configs import load_configs | ||
from hartsfield.api.config_controller import load_json | ||
from hartsfield.lib.http import tolerant_jsonify | ||
from hartsfield.lib.util import get_eb_environment | ||
|
||
import requests | ||
import datetime | ||
import json | ||
import re | ||
|
||
from google.oauth2 import service_account | ||
from flask import current_app as app, request | ||
from google.cloud import storage | ||
from google.oauth2 import service_account | ||
from hartsfield.api.auth_helper import authorzied_user_required | ||
from hartsfield.lib.http import tolerant_jsonify | ||
import hartsfield.api.read_aws_secret | ||
|
||
PUBLIC_CONFIGS = [ | ||
'DEV_AUTH_ENABLED', | ||
'HARTSFIELD_ENV', | ||
'TIMEZONE', | ||
] | ||
|
||
gcp_json_credentials = app.config['GCP_JSON_CREDENTIALS'] | ||
gcp_json_credentials_dict = json.loads(gcp_json_credentials) | ||
AWS_SECRETS_NAME_GCP_JSON_CREDENTIALS = app.config['AWS_SECRETS_NAME_GCP_JSON_CREDENTIALS'] | ||
|
||
|
||
gcp_json_credentials_from_aws = hartsfield.api.read_aws_secret.read_aws_secret(AWS_SECRETS_NAME_GCP_JSON_CREDENTIALS) | ||
gcp_json_credentials_dict = json.loads(gcp_json_credentials_from_aws) | ||
|
||
# TODO: pass in gs url as input value to @app.route('/api/fetch_url_direct') from form user front-end form submission | ||
gs_source_url="gs://ucb-datahub-archived-homedirs/spring-2021/datahub.berkeley.edu/peterphu-2edo.tar.gz" | ||
# This will probably be request.args['gs_source_url'] in the def block...but that whole "request" business needs to be brought in etc. | ||
|
||
@app.route('/api/fetch_url_direct') | ||
@app.route('/api/fetch_url_direct', methods=['POST']) | ||
@authorzied_user_required | ||
def fetch_url_direct(): | ||
|
||
# parse the input gs url to get bucket and blob names | ||
bucket_and_blob_string = gs_source_url.replace("gs://", "") | ||
bucket_and_blob_list = bucket_and_blob_string.split("/") | ||
params = request.get_json() | ||
gs_source_url = params.get('gsSourceUrl') | ||
gs_source_url = gs_source_url.strip() | ||
if not re.match(r'gs://.{3,}/.+', gs_source_url): | ||
error_message = 'The submitted data \"' + gs_source_url + '\" is not a valid gsSourceUrl.' | ||
v = {'response': error_message, 'status': 'error'} | ||
return tolerant_jsonify(v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above looks good. Although I suggest the following for line 58:
This will make for more standard front-end code (eg, checking HTTP status code). |
||
|
||
bucket_and_blob_string = gs_source_url.replace('gs://', '') | ||
bucket_and_blob_list = bucket_and_blob_string.split('/') | ||
bucket_name = bucket_and_blob_list.pop(0) | ||
blob_name = "/".join(bucket_and_blob_list) | ||
blob_name = '/'.join(bucket_and_blob_list) | ||
|
||
# instantiate gcp storage client plus with bucket and blob objects | ||
credentials = service_account.Credentials.from_service_account_info(gcp_json_credentials_dict) | ||
storage_client = storage.Client(project=gcp_json_credentials_dict['project_id'], credentials=credentials) | ||
bucket = storage_client.bucket(bucket_name) | ||
blob = bucket.blob(blob_name) | ||
|
||
# do some checks to confirm that the bucket and blob exist | ||
try: | ||
stats = storage.Blob(bucket=bucket, name=blob_name).exists(storage_client) | ||
except Exception as e: | ||
error_message = "There was a problem trying to get stats on the requested blob \"" + blob_name + "\" in the requested bucket \"" + bucket_name +"\":\n\n " + str(e) | ||
error_message = f"""There was an exception trying to do the GCP storage operation | ||
with the submitted data "{gs_source_url}". | ||
When GCP tried, it told us: "{str(e)}" | ||
""" | ||
v = {'response': error_message, 'status': 'error'} | ||
return tolerant_jsonify(v) | ||
if stats: | ||
# if the bucket and blob exist, generate a signed url for the blob... | ||
# ...and package it as a Hartsfield back-end internal response | ||
gcp_response = blob.generate_signed_url( | ||
version="v4", | ||
version='v4', | ||
expiration=datetime.timedelta(days=7), | ||
method="GET", | ||
method='GET', | ||
) | ||
v = {'response': gcp_response, 'status': 'success'} | ||
else: | ||
gcp_response = "File \"" + blob_name + "\"does not exist in bucket \"" + bucket_name + "\"" | ||
gcp_response = f'GCP tried, but could not locate a file "{blob_name}" in a bucket called "{bucket_name}".' | ||
v = {'response': gcp_response, 'status': 'error'} | ||
|
||
return tolerant_jsonify(v) | ||
|
||
""" | ||
To make/fix/clean: | ||
|
||
- Make the Web request form / wire up web front end portion of app | ||
|
||
- CalNet auth in front of web app | ||
|
||
- All of the other ignorant/non-ideal coding practices I've done...! | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source .env.development
seems unnecessary in both instances above. Vite should pick it up automatically whennpm run serve-vue