Skip to content
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

Develop #116

Closed
wants to merge 222 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
2ffdaed
added procedure call api
Jun 24, 2021
32de539
added procedure call api
Jun 24, 2021
75886ea
updated upload api
Jul 13, 2021
36b3345
added data summary filter apis
Jul 16, 2021
a5312b8
adding gitignore
charles-p-howe Aug 2, 2021
28a839f
Dockerfile updates to handle adding instantclient
charles-p-howe Aug 2, 2021
c42f014
substitute values
charles-p-howe Aug 3, 2021
2904907
added summary apis
Aug 3, 2021
b9c8e2f
Merge branch 'develop' of https://github.com/USACE/pallid-sturgeon-ap…
Aug 3, 2021
9e30fdd
Merge pull request #4 from USACE/feature/data_summaries
dliang864 Aug 3, 2021
5aa5400
Update APIDOC.md
dliang864 Aug 3, 2021
23d8d40
Update APIDOC.md
dliang864 Aug 3, 2021
d3dd90b
changes made for db conn
charles-p-howe Aug 3, 2021
1e76cae
Merge branch 'develop' of https://github.com/USACE/pallid-sturgeon-ap…
charles-p-howe Aug 3, 2021
057eef0
adding workflow file
charles-p-howe Aug 3, 2021
628ec43
changed how to connect to oracle db and data entry apis
Aug 11, 2021
178a502
Merge branch 'develop' into feature/data_summaries
dliang864 Aug 11, 2021
383c278
Merge pull request #5 from USACE/feature/data_summaries
dliang864 Aug 11, 2021
c24f444
added data entry apis
Aug 12, 2021
06859c5
added data entry apis
Aug 12, 2021
ef15ce5
Merge pull request #6 from USACE/feature/data_entry_apis
dliang864 Aug 12, 2021
5bc7756
added keycloak
Aug 23, 2021
93d8cbe
fixed year and suppId reversed bug
Aug 24, 2021
ce0d6a7
Merge pull request #7 from USACE/feature/data_entry_apis
dliang864 Aug 24, 2021
acf067f
fixed cacuid null bug
Aug 25, 2021
ca9c261
added site data entry apis
Sep 2, 2021
bf87a3b
added edit initial field
Sep 2, 2021
0386092
Merge pull request #8 from USACE/feature/add-data-entry-for-site
dliang864 Sep 2, 2021
0f83582
added summary download apis
Sep 3, 2021
06a2cb7
Merge pull request #9 from USACE/feature/add-data-entry-for-site
dliang864 Sep 3, 2021
aa10217
updated upload apis
Sep 3, 2021
d84c5eb
Merge pull request #10 from USACE/feature/add-data-entry-for-site
dliang864 Sep 3, 2021
ecc8c7c
updated docs
Sep 3, 2021
e9236b3
Merge pull request #11 from USACE/feature/add-data-entry-for-site
dliang864 Sep 3, 2021
e99cc4c
updated download apis and added domain apis
Sep 7, 2021
566a405
Merge pull request #12 from USACE/feature/add-data-entry-for-site
dliang864 Sep 7, 2021
0886f72
delete file after downloading
Sep 7, 2021
1136941
Merge pull request #13 from USACE/feature/add-data-entry-for-site
dliang864 Sep 7, 2021
2743409
added telemetry and procedure apis
Sep 13, 2021
4473a3f
Merge pull request #14 from USACE/feature/add-data-entry-for-site
dliang864 Sep 13, 2021
c8c1334
fixed the summary apis
Sep 13, 2021
e3e03e3
Merge pull request #15 from USACE/feature/add-data-entry-for-site
dliang864 Sep 13, 2021
c66382f
fixed searchSummary count bug
Sep 16, 2021
62ca5b1
Merge pull request #16 from USACE/feature/bug_fixes
dliang864 Sep 16, 2021
17f955c
merged from develp
Sep 20, 2021
05a3ddb
merged from develp
Sep 20, 2021
8839cd4
merged from develp
Sep 20, 2021
7de0e1b
merged from develp
Sep 20, 2021
ba98866
updated port number
Sep 21, 2021
0b03125
Merge pull request #17 from USACE/feature/keycloak2
dliang864 Sep 21, 2021
d3246c4
taking out the auth
Sep 27, 2021
3868def
added api docs
Sep 27, 2021
5999649
added api docs
Sep 27, 2021
47d06f1
Merge pull request #18 from USACE/feature/keycloak2
dliang864 Sep 27, 2021
57f7184
updated float to string
Oct 1, 2021
a4ba051
Merge pull request #19 from USACE/feature/keycloak2
dliang864 Oct 1, 2021
bfdca4b
created fish data entry get all
Oct 4, 2021
1103268
Merge pull request #20 from USACE/feature/keycloak2
dliang864 Oct 4, 2021
55a3327
added mrid to fishdataentry
Oct 4, 2021
97ff2c1
added mrid to fishdataentry
Oct 4, 2021
6998cf4
Merge pull request #21 from USACE/feature/keycloak2
dliang864 Oct 4, 2021
9e38e24
added upload download zip
Oct 5, 2021
9798241
Merge pull request #22 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
729895c
reverted file back
Oct 5, 2021
f8a461c
Merge pull request #23 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
39201e7
reverted file back
Oct 5, 2021
624df26
Merge pull request #24 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
188a8aa
reverted file back
Oct 5, 2021
3216c26
Merge pull request #25 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
116b09c
reverted file back
Oct 5, 2021
68a4cee
Merge pull request #26 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
97a281e
reverted file back
Oct 5, 2021
df0731d
Merge pull request #27 from USACE/feature/keycloak2
dliang864 Oct 5, 2021
3b878cb
added last updated to download info
Oct 6, 2021
2375352
Merge pull request #28 from USACE/feature/keycloak2
dliang864 Oct 6, 2021
6005658
fixed a bug
Oct 8, 2021
bf91859
Merge pull request #29 from USACE/feature/keycloak2
dliang864 Oct 8, 2021
0c48f8c
fixed a bug
Oct 8, 2021
5cdd1bf
Merge pull request #30 from USACE/feature/keycloak2
dliang864 Oct 8, 2021
fb73321
fixed a bug
Nov 2, 2021
4b634ef
Merge pull request #31 from USACE/feature/keycloak2
dliang864 Nov 2, 2021
5fe431f
added authentication back
Nov 8, 2021
d050bd4
Merge pull request #32 from USACE/feature/keycloak3
dliang864 Nov 8, 2021
2af7114
added authentication back
Nov 8, 2021
8e89875
Merge pull request #33 from USACE/feature/keycloak3
dliang864 Nov 8, 2021
a45a707
added authentication back
Nov 8, 2021
f0f12f7
Merge pull request #34 from USACE/feature/keycloak3
dliang864 Nov 8, 2021
32c0a87
Just want to pull
charles-p-howe Nov 9, 2021
2f29b16
Merge branch 'develop' of https://github.com/USACE/pallid-sturgeon-ap…
charles-p-howe Nov 9, 2021
789edce
changed IPPk to a string
Nov 9, 2021
be37ca0
removed variable
Nov 9, 2021
4a0cafe
removed variable
Nov 9, 2021
c1971f6
Merge pull request #35 from USACE/feature/keycloak3
dliang864 Nov 9, 2021
d9a8a32
updated api permission
Nov 12, 2021
5d3bcaf
Merge pull request #36 from USACE/feature/keycloak3
dliang864 Nov 12, 2021
c10363c
Merge branch 'develop' of https://github.com/USACE/pallid-sturgeon-ap…
charles-p-howe Dec 17, 2021
ed62521
just want to force a refresh of the API ECS
charles-p-howe Dec 17, 2021
0ec09fc
just want to force a refresh of the API ECS again
charles-p-howe Dec 17, 2021
91e2300
just want to revert changes to original keycloak
charles-p-howe Dec 17, 2021
2393b27
just want to force a refresh of the API ECS, transitioning to auth-te…
charles-p-howe Dec 20, 2021
8e88941
updated table and column names
Jan 20, 2022
6b87acb
Merge pull request #37 from USACE/feature/table_changes
dliang864 Jan 21, 2022
52c2d1c
updated column name
Jan 21, 2022
81777cf
Merge pull request #38 from USACE/feature/table_changes
dliang864 Jan 21, 2022
9cf0c23
updated column name
Jan 21, 2022
e5b06ed
Merge pull request #39 from USACE/feature/table_changes
dliang864 Jan 21, 2022
b0b7d29
updated column names
Jan 21, 2022
37108b1
updated column names
Jan 21, 2022
c47eafd
updated column names
Jan 21, 2022
78d71d9
Merge pull request #40 from USACE/feature/table_changes
dliang864 Jan 21, 2022
00cc19c
updated column names
Jan 21, 2022
de60e2b
Merge pull request #41 from USACE/feature/table_changes
dliang864 Jan 21, 2022
190f8ff
updated column names
Jan 24, 2022
e5fd264
Merge pull request #42 from USACE/feature/table_changes
dliang864 Jan 24, 2022
6fcd696
updated column names
Jan 24, 2022
9e8424a
Merge pull request #43 from USACE/feature/table_changes
dliang864 Jan 24, 2022
7567ebc
updated column names
Jan 24, 2022
05719e2
Merge pull request #44 from USACE/feature/table_changes
dliang864 Jan 24, 2022
2ea5d49
updated column names
Jan 24, 2022
d0fb993
Merge pull request #45 from USACE/feature/table_changes
dliang864 Jan 24, 2022
9a65653
updated column names
Jan 24, 2022
acae1a0
Merge pull request #46 from USACE/feature/table_changes
dliang864 Jan 24, 2022
c470d40
updated column names
Jan 25, 2022
85ea3cf
Merge pull request #47 from USACE/feature/table_changes
dliang864 Jan 25, 2022
f9ef61c
updated column names
Jan 25, 2022
1672ec4
Merge pull request #48 from USACE/feature/table_changes
dliang864 Jan 25, 2022
9d701ca
updated column names
Jan 31, 2022
50bd5b0
Merge pull request #49 from USACE/feature/table_changes
dliang864 Jan 31, 2022
cabc70e
updated column names
Jan 31, 2022
207830a
Merge pull request #50 from USACE/feature/table_changes
dliang864 Jan 31, 2022
67cfaa8
updating column definitions to match upload file format
charles-p-howe Jul 1, 2022
6a28e71
fix for missing comma
charles-p-howe Jul 1, 2022
f009cdd
Adding handler for blank string times, or unformatted, will need to i…
charles-p-howe Jul 7, 2022
cb44bed
column name changes and model data type changes to account for issues…
charles-p-howe Jul 8, 2022
e9a8573
column naming or typing issues
charles-p-howe Jul 8, 2022
0252153
column naming blood_sample_ind
charles-p-howe Jul 8, 2022
eda7af2
column naming again
charles-p-howe Jul 8, 2022
987153f
checking for issues with the column naming and missing id field, turn…
charles-p-howe Jul 8, 2022
0f7a59c
enhancement/updates-to-data-summaries-and-uploads (#51)
jguevarra Jul 26, 2022
03eca49
updated json field mapping for data upload file formatting (#52)
jguevarra Jul 27, 2022
2defdc9
add project code to data models + added update sql query and handlers…
jguevarra Aug 1, 2022
9048fdb
enhancement/usg-species-unchecked-records (#54)
jguevarra Aug 2, 2022
2f76740
feature/office-error-log (#55)
jguevarra Aug 4, 2022
6ba753e
clean up column names, get site data entry by id, fixed insert into u…
jguevarra Aug 5, 2022
8b00c4d
enhancement/data-summaries-filtering (#57)
jguevarra Aug 9, 2022
0e0c3d0
added endpoints and handlers for unapproved and BAFI datasheets (#58)
jguevarra Aug 9, 2022
49fafdb
bugfix for data upload (#59)
jguevarra Aug 10, 2022
4c8093b
feature/sites-list-datasheets (#60)
jguevarra Aug 30, 2022
fef582a
added get for bendrn and updates Sites model (#61)
jguevarra Sep 1, 2022
b26c6c7
update moriver field names, and added any missing fields to the model…
jguevarra Sep 3, 2022
d68e9fa
added search effort and telemetry get, post, put endpoints (#63)
jguevarra Sep 14, 2022
38dc097
added get endpoints for moriver form select options (#64)
jguevarra Sep 15, 2022
88c427d
enhancement/fish-form-and-table
jguevarra Sep 16, 2022
459e273
updated supplemental queries and data model (#65)
jguevarra Sep 20, 2022
a35c60f
added procedure data entry api (#66)
jguevarra Sep 22, 2022
36fbaf8
updates to site data entries api (#67)
jguevarra Sep 22, 2022
e69555a
test for changing PUT to POST (#68)
jguevarra Sep 23, 2022
1c12c53
update data entry queries and PUTs to POSTs (#69)
jguevarra Sep 27, 2022
8013262
update data mapping for summary tables (#70)
jguevarra Sep 27, 2022
9607e38
revert POSTS to PUTs (#71)
jguevarra Sep 27, 2022
f9875f9
fetch header data and fix some datatypes and null handling (#72)
jguevarra Sep 28, 2022
3ce24fb
updated homepage queries with ZZ and added upload session log query (…
jguevarra Sep 29, 2022
60d5169
enhancement/data-entry-forms (#74)
jguevarra Sep 30, 2022
24e6baa
testing fixes for data entries (#75)
jguevarra Oct 7, 2022
df546a7
bugfix - file upload data has null dates
jguevarra Oct 7, 2022
00da629
add stores and handlers for sites export data (#76)
jguevarra Oct 21, 2022
adba649
bugfix/create-site-form (#77)
jguevarra Nov 1, 2022
4e00345
enhancement/site-form-dropdown-queries (#78)
jguevarra Nov 3, 2022
c2adc26
removed Area of Interest from sample unit type options
jguevarra Nov 4, 2022
63b6010
updated search effort data summaries query (#79)
jguevarra Nov 9, 2022
791be10
set max connections value and closed db connections in necessary quer…
jguevarra Nov 23, 2022
5f27b0d
updated data source strings (#82)
jguevarra Dec 6, 2022
1369cb4
set max idle connections limit to 0 (#83)
jguevarra Dec 8, 2022
cabd125
bugfix/sites-list (#84)
jguevarra Dec 13, 2022
512801e
feature/multi-office-access (#81)
jguevarra Jan 7, 2023
27b6ebd
Revert "feature/multi-office-access (#81)" (#85)
jguevarra Jan 7, 2023
7abef1d
adding a text processing of the time string, might need handling for …
charles-p-howe Jan 11, 2023
ecd66e7
did not save, adding string to string time processing
charles-p-howe Jan 11, 2023
8378f04
changing string types to json.Number in hopes that the number can be …
charles-p-howe Jan 12, 2023
ca1a117
take 2 changing string types to json.Number in hopes that the number …
charles-p-howe Jan 12, 2023
a52007a
adding encoding json to other modules might need the reference to use…
charles-p-howe Jan 12, 2023
888c30a
adding encoding json to other modules might need the reference to use…
charles-p-howe Jan 12, 2023
c94ae31
removed import from incorrect file
charles-p-howe Jan 12, 2023
2889dd6
removed import from incorrect file, added to hopefully correct file
charles-p-howe Jan 12, 2023
296e40a
removing encoding, trying meta tags
charles-p-howe Jan 12, 2023
fdad810
now let's try converting int to string during the upload.
charles-p-howe Jan 12, 2023
12e7bae
cmon man
charles-p-howe Jan 12, 2023
b12a208
resetting code
charles-p-howe Jan 12, 2023
b4ff3c8
mapped fish floy_tag to ftnum (#87)
jguevarra Jan 20, 2023
c4aa848
bugfix/defaults and nulls (#88)
jguevarra Jan 25, 2023
9c11eb3
missing procedure dst start date (#89)
jguevarra Jan 26, 2023
e7a3fc7
ftnum/floytag zeroes
jguevarra Jan 26, 2023
93a9963
ftnum datatype bugfix
jguevarra Jan 26, 2023
3b9f8dd
enhancement/data entry workflow tabs (#90)
jguevarra Feb 8, 2023
800b183
updated data type of dates (#91)
jguevarra Feb 16, 2023
f353df3
enhancement/data summaries (#92)
jguevarra Mar 2, 2023
dae5e06
fixed telemetry count query (#93)
jguevarra Mar 9, 2023
380c38c
enhancement/cleaning-up-columns (#94)
jguevarra Mar 17, 2023
706fb3f
bugfix/procedure-sex-code (#95)
jguevarra Mar 21, 2023
c14c57a
feature/multi-user-access (#96)
jguevarra Apr 17, 2023
4f2d30c
bugfix/multi-office (#97)
jguevarra Apr 18, 2023
621aa32
bugfix/multioffice-data-entry-data (#98)
jguevarra May 1, 2023
cbbdf56
bugfix/data-summaries-nulls (#99)
jguevarra May 12, 2023
68e5b5e
bugfix/data-summary-date-nulls (#100)
jguevarra Jun 28, 2023
3c255d0
launch.json
heather-godbey Jul 13, 2023
830f68c
revert back insert statements, removed sequence id from queries (#101)
jguevarra Aug 4, 2023
0ee0669
Merge branch 'develop' of https://github.com/USACE/pallid-sturgeon-ap…
heather-godbey Aug 25, 2023
ece80b9
update queries
heather-godbey Aug 28, 2023
7c72389
Merge pull request #102 from USACE/bugfix/data-entry-queries
heather-godbey Aug 29, 2023
8a8e663
fix query params for fetching site data entries (#104)
jguevarra Feb 26, 2024
07554c8
Sites-list page feedback fixes (#105)
jguevarra Mar 27, 2024
c0034c5
dataheader bendrivermile bugfix (#106)
jguevarra Apr 23, 2024
6b590e5
Oracle instantclient 23 has changed username/password datatypes, but …
charles-p-howe May 13, 2024
38df411
fix project filter query param (#108)
jhenr098 May 14, 2024
7d06749
sites export data model and query fix (#109)
jguevarra May 24, 2024
4a374be
update exportSites query and datatype mapping
jguevarra Jun 4, 2024
ccebc0f
sites list export bugfix - default site_fid to 0 and correct SampleUn…
jguevarra Jun 5, 2024
594b74b
Data Header Logic Rewrite (#112)
jguevarra Jun 24, 2024
7b46d1d
Jasmin's chagnes for species fields in supp table (#113)
jguevarra Jun 24, 2024
3130c83
query fix for fetching supplemental data (#114)
jguevarra Jun 26, 2024
193a44e
Updates made to handle security vulnerabilities, updating to newer ve…
charles-p-howe Oct 17, 2024
ea84472
Feature/setdate (#115)
jhenr098 Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/api-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build API Develop

on:
push:
branches: [develop]
workflow_dispatch:
jobs:

APIDockerImage:
name: API Image Develop
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Configure AWS credentials
if: ${{ always() }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CWBICI_DEVELOP_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CWBICI_DEVELOP_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.CWBICI_DEVELOP_AWS_REGION }}

- name: Login to Amazon ECR
if: ${{ success() }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR (water-api)
if: ${{ success() }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: pallid-sturgeon-api
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Logout of Amazon ECR
if: ${{ always() }}
run: docker logout ${{ steps.login-ecr.outputs.registry }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# local config files
envvars.list
.vscode/*

*.exe
scan*.txt
scratch
26 changes: 0 additions & 26 deletions .vscode/launch.json

This file was deleted.

58 changes: 41 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
FROM golang:1.15-alpine AS builder
# Install Git
RUN apk update && apk add --no-cache git
# Copy In Source Code
WORKDIR /go/src/app
COPY . .

# Install Dependencies
RUN go get -d -v
# Build
RUN go get -d -v \
&& GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -ldflags="-w -s" -o /go/bin/pallid_sturgeon_api

# SCRATCH IMAGE
FROM scratch
COPY --from=builder /go/bin/pallid_sturgeon_api /go/bin/pallid_sturgeon_api
FROM golang:1.23.2-alpine AS builder
RUN apk add build-base
# Install Git
RUN apk update && apk add --no-cache git

# Copy In Source Code
WORKDIR /go/src/app
COPY . .

# Install Dependencies
RUN go get -d -v
# Build
RUN go get -d -v \
&& GOOS=linux GOARCH=amd64 CGO_ENABLED=1 \
go build -ldflags="-w -s" -o /go/bin/pallid_sturgeon_api

# not SCRATCH IMAGE
# remove curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip -SL && \
FROM alpine:latest
RUN apk add build-base
RUN apk add --no-cache bash
RUN apk --no-cache add libaio libnsl libc6-compat curl && \
cd /tmp && \
curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/2114000/instantclient-basic-linux.x64-21.14.0.0.0dbru.zip -SL && \
unzip instantclient-basiclite.zip && \
mv instantclient*/ /usr/lib/instantclient && \
rm instantclient-basiclite.zip && \
ln -s /usr/lib/instantclient/libclntsh.so.19.1 /usr/lib/libclntsh.so && \
ln -s /usr/lib/instantclient/libocci.so.19.1 /usr/lib/libocci.so && \
ln -s /usr/lib/instantclient/libociicus.so /usr/lib/libociicus.so && \
ln -s /usr/lib/instantclient/libnnz19.so /usr/lib/libnnz19.so && \
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1 && \
ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2 && \
ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2

ENV ORACLE_BASE /usr/lib/instantclient
ENV LD_LIBRARY_PATH /usr/lib/instantclient
ENV TNS_ADMIN /usr/lib/instantclient
ENV ORACLE_HOME /usr/lib/instantclient

COPY --from=builder /go/bin/pallid_sturgeon_api /go/bin/pallid_sturgeon_api
ENTRYPOINT ["/go/bin/pallid_sturgeon_api"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Set the following environment variables and type `go run root/main.go` from the
"DB_PASS": "",
"DB_NAME": "",
"LIB_DIR": "",
"DB_HOST": "localhost",
"DB_HOST": "",
"DB_PORT": "1521",
"IPPK": "${workspaceFolder}/props/local.pem",
"IPPK": "",


Note: When running the API locally, make sure environment variable `LAMBDA` is either **not set** or is set to `LAMBDA=FALSE`.
IPPK is NOT in use currently in AWS Dev.
Use the SIG key when setting IPPK value.
122 changes: 36 additions & 86 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@ package auth
import (
"crypto/rsa"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"path/filepath"
"strings"

"di2e.net/cwbi/pallid_sturgeon_api/server/models"
"di2e.net/cwbi/pallid_sturgeon_api/server/stores"
"github.com/dgrijalva/jwt-go"
"github.com/USACE/pallid_sturgeon_api/server/models"
"github.com/USACE/pallid_sturgeon_api/server/stores"
"github.com/golang-jwt/jwt/v4"
"github.com/labstack/echo/v4"
)

const (
PUBLIC = iota
PM
TM
ADMIN
OFFICEADMIN
OFFICEUSER
READONLY
)

type Auth struct {
Store *stores.AuthStore
VerifyKey *rsa.PublicKey
}

var verifyKeys []*rsa.PublicKey

/*
Authorize Options:
1) Public - All CAC Users
1) Public - All KEYCLOAK Users
2) PM - Project Manager
3) TM - Team Member
*/
Expand All @@ -50,39 +47,37 @@ func (a *Auth) Authorize(handler echo.HandlerFunc, roles ...int) echo.HandlerFun
if err != nil {
return err
}
c.Set("SDUSER", user)
role, err := a.Store.GetUserRoleOffice(user.Email)
if err != nil {
return err
}
c.Set("PSUSER", user)
switch {
case contains(roles, TM):
for _, role := range claims.Roles {
if role == "PM" || role == "TM" {
return handler(c)
}
case contains(roles, PUBLIC):
return handler(c)
case contains(roles, ADMIN):
if role.Role == "ADMINISTRATOR" {
return handler(c)
}
case contains(roles, OFFICEADMIN):
if role.Role == "OFFICE ADMIN" {
return handler(c)
}
case contains(roles, PM):
for _, role := range claims.Roles {
if role == "PM" {
return handler(c)
}
case contains(roles, OFFICEUSER):
if role.Role == "OFFICE USER" {
return handler(c)
}
case contains(roles, READONLY):
if role.Role == "READONLY" {
return handler(c)
}
}
return echo.NewHTTPError(http.StatusUnauthorized, "")
}
}

func loadKeyFile(filePath string) (*rsa.PublicKey, error) {
publicKeyBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
return jwt.ParseRSAPublicKeyFromPEM(publicKeyBytes)
}

func (a *Auth) LoadVerificationKey(filePath string) error {
publicKeyBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
pk, err := jwt.ParseRSAPublicKeyFromPEM(publicKeyBytes)
func (a *Auth) LoadVerificationKey(publicKey string) error {
pk, err := jwt.ParseRSAPublicKeyFromPEM([]byte("-----BEGIN PUBLIC KEY-----\n" + publicKey + "\n-----END PUBLIC KEY-----"))
if err != nil {
return err
}
Expand All @@ -100,56 +95,11 @@ func (a *Auth) marshalJwt(tokenString string) (models.JwtClaim, error) {
}
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
jwtUser := models.JwtClaim{
Sub: claims["sub"].(string),
Name: claims["name"].(string),
Email: claims["email"].(string),
Roles: claims["roles"].([]interface{}),
}
return jwtUser, nil
} else {
return models.JwtClaim{}, errors.New("Invalid Token")
}
}

func LoadVerificationKeys(fieldPath string) error {
files, err := ioutil.ReadDir(fieldPath)
if err != nil {
return err
}
for _, v := range files {
if ext := filepath.Ext(v.Name()); ext == ".pem" {
fmt.Printf("Loading Public Key: %s\n", v.Name())
pk, err := loadKeyFile(fieldPath + "/" + v.Name())
if err != nil {
return err
}
verifyKeys = append(verifyKeys, pk)
}
}
return nil
}

func marshalJwts(tokenString string) (models.JwtClaim, error) {
var token *jwt.Token = nil
var err error
for _, verificationKey := range verifyKeys {
token, err = jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return verificationKey, nil
})
if err == nil {
break
}
}

if token == nil {
return models.JwtClaim{}, errors.New("Invalid Token")
}
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
jwtUser := models.JwtClaim{
Sub: claims["sub"].(string),
Name: claims["name"].(string),
Email: claims["email"].(string),
Roles: claims["roles"].([]interface{}),
//CacUid: claims["cacUID"].(string),
Name: claims["name"].(string),
Email: claims["email"].(string),
FirstName: claims["given_name"].(string),
LastName: claims["family_name"].(string),
}
return jwtUser, nil
} else {
Expand Down
Loading
Loading