Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
432 commits
Select commit Hold shift + click to select a range
e783dce
added StringArray
Nov 1, 2022
192419e
Allow email verification without protection
Nov 1, 2022
131b42c
remove base / in /user/
Nov 1, 2022
38d4528
Merge pull request #18 from String-xyz/task/sean/str-94
auroter Nov 1, 2022
f5be2bc
update email URL with unprotected endpoint
Nov 2, 2022
e03c391
Merge pull request #19 from String-xyz/hotfix/email-url
auroter Nov 2, 2022
4950730
move out repos into own struct
ocasta181 Nov 2, 2022
3c1982b
fix quote typo
ocasta181 Nov 2, 2022
e6be36e
remove todo comment from entity model
ocasta181 Nov 2, 2022
2e16357
resolve merge conflicts
ocasta181 Nov 2, 2022
3b201c9
GetId to GetById
ocasta181 Nov 2, 2022
fc8af93
USE CORS!
Nov 2, 2022
e4e0807
Merge pull request #20 from String-xyz/hotfix/CORS
auroter Nov 2, 2022
638243e
ensure verification endpoint is properly routed
ocasta181 Nov 2, 2022
beb2d7c
Merge pull request #14 from String-xyz/task/andrin/str-154
Nov 4, 2022
0bb3708
have transaction and instrument tests working better; initial work on…
ocasta181 Nov 5, 2022
3ffb77c
more progress, stuck on entity create
ocasta181 Nov 5, 2022
e7f0b25
add location_test, remove some old TODOs
ocasta181 Nov 5, 2022
a009048
pass userId to transact and handle
ocasta181 Nov 5, 2022
898f8e1
Get last 4 and unique card instrument ID for TX legs
Nov 5, 2022
70adfe8
updated login/register
Nov 7, 2022
45449a2
Made email verification/login use GET instead of POST since they are …
Nov 7, 2022
5d22e48
fixed a bug where Checkout Instrument ID (str_3940293403) was passed …
Nov 7, 2022
a43d80d
STR-182 (#17)
saito-sv Nov 8, 2022
60adb06
fixed makefile (#22)
saito-sv Nov 8, 2022
aab56f5
Use checkout instrument fingerprint because it's unique
Nov 8, 2022
dac5dd0
alb should be on private subnet (#23)
saito-sv Nov 8, 2022
17ad663
Make sure base64 login codes are html safe
Nov 8, 2022
3a7cb3e
verify userId is valid before attempting to transact
Nov 8, 2022
4221e9b
get unit21 transaction data connected to execute tx, also getting log…
ocasta181 Nov 9, 2022
25edcd7
separate create new account from email authentication
Nov 9, 2022
1ca4d09
have transaction and instrument tests working better; initial work on…
ocasta181 Nov 5, 2022
e9f3d8b
more progress, stuck on entity create
ocasta181 Nov 5, 2022
4869b1c
add location_test, remove some old TODOs
ocasta181 Nov 5, 2022
ddfbb12
pass userId to transact and handle
ocasta181 Nov 5, 2022
7ec6e71
Get last 4 and unique card instrument ID for TX legs
Nov 5, 2022
d6f8a4b
updated login/register
Nov 7, 2022
59557fc
Made email verification/login use GET instead of POST since they are …
Nov 7, 2022
92f5a5e
fixed a bug where Checkout Instrument ID (str_3940293403) was passed …
Nov 7, 2022
0d919c4
Use checkout instrument fingerprint because it's unique
Nov 8, 2022
62c3f4c
Make sure base64 login codes are html safe
Nov 8, 2022
8200c3c
verify userId is valid before attempting to transact
Nov 8, 2022
9700ce8
get unit21 transaction data connected to execute tx, also getting log…
ocasta181 Nov 9, 2022
3c49713
separate create new account from email authentication
Nov 9, 2022
6aad9ae
rebase
ocasta181 Nov 10, 2022
177b625
.... not sure what I did wrong
ocasta181 Nov 10, 2022
51bdf0c
remove duplicative function in auth.go
ocasta181 Nov 10, 2022
57a4c26
rename res and checkout fingerprint
ocasta181 Nov 10, 2022
cbea73b
handle u21 entities in user.go
ocasta181 Nov 10, 2022
b525675
move instrument create into goroutine
ocasta181 Nov 10, 2022
e47d43a
added BASE_URL to ENV
Nov 10, 2022
e33dbc8
testing updates for wallet signature
ocasta181 Nov 11, 2022
d89d3c1
Merge branch 'task/andrin/str-141' of github.com:String-xyz/string-ap…
ocasta181 Nov 11, 2022
2c6d69a
Merge pull request #21 from String-xyz/task/andrin/str-141
Nov 11, 2022
21eb369
refactor base and create the Unit21 Evaluate function and unit tests
ocasta181 Nov 12, 2022
06f919a
fix some errors and refactor to use interfaces
ocasta181 Nov 14, 2022
d43466e
Prettier debug stacktrace in terminal
Nov 14, 2022
56bf54e
remove commented out code
Nov 14, 2022
585e3a0
remove PK from test
Nov 14, 2022
2d4df32
repo base should always return errors; mocks are in a queue, remove u…
ocasta181 Nov 14, 2022
f9dd29a
Dockerize Api for Local Development + Live Reload (#24)
alcalawil Nov 15, 2022
f7a511b
Merge branch 'develop' into task/andrin/str-187
Nov 15, 2022
0cd6940
beginning to integrate unit21 evaluate into transaction service. will…
ocasta181 Nov 15, 2022
d8f6fcf
small comment change
ocasta181 Nov 15, 2022
5685317
comment out broken portions until unblocked
ocasta181 Nov 15, 2022
ab7f054
clean up entity type checks
ocasta181 Nov 15, 2022
5c7f65b
remove unused query mocks
ocasta181 Nov 15, 2022
0652834
add mocks goose file to ease testing
ocasta181 Nov 15, 2022
999e6f0
add goose down note
ocasta181 Nov 15, 2022
dbf71f8
Merge pull request #28 from String-xyz/task/andrin/str-188
Nov 16, 2022
af75d4a
Merge branch 'develop' of github.com:String-xyz/string-api into task/…
ocasta181 Nov 16, 2022
5c490dd
re-diverging endpoint naming convention for unit21 as per their instr…
ocasta181 Nov 16, 2022
417c16d
added more insomina automation; added insomnia file to project; remov…
ocasta181 Nov 16, 2022
ef78067
added more insomina automation; added insomnia file to project; remov…
ocasta181 Nov 16, 2022
607ae55
Merge pull request #26 from String-xyz/task/sean/str-193
auroter Nov 17, 2022
5542480
remove logs from unit21 unit tests
ocasta181 Nov 18, 2022
e16d38f
capitalize 'TODO'
ocasta181 Nov 18, 2022
abc6a75
Added Cache service for Owlracle and Coingecko
Nov 18, 2022
7e29039
Merge pull request #30 from String-xyz/task/andrin/str-189
Nov 18, 2022
1687af4
entity is broken, working on a fix
ocasta181 Nov 18, 2022
e6f2e0f
print instead of panic; check for error in big boolean expression
ocasta181 Nov 18, 2022
3cf4fca
Added safeguard against errors which do not implement stacktrace (ext…
Nov 18, 2022
17c9506
moved PutObjectInGache and GetObjectFromCache to store package
Nov 18, 2022
b4ae519
Update pkg/service/cost.go
auroter Nov 21, 2022
cd02277
addressing suggestions and comments
Nov 21, 2022
021402e
fix mocking error
ocasta181 Nov 21, 2022
6a3a99d
check error cause in quote endpoint to catch 'evm execution will reve…
Nov 21, 2022
8500197
make transaction handler return 500 on error
Nov 21, 2022
b6aab94
Fixed a bug where JSON responses were falsely flagged as bad when the…
Nov 21, 2022
7c23940
fix add instrument endpoint and test
ocasta181 Nov 22, 2022
13e6aff
STR-85 :: Geofencing Task (#29)
alcalawil Nov 22, 2022
75a8c4a
Fixed math bug in rate limit function
Nov 22, 2022
f2eb71d
Merge pull request #32 from String-xyz/task/sean/str-208
auroter Nov 22, 2022
25110d2
unix time is in seconds!
Nov 22, 2022
13d6d2c
String API Prod(STR-184) (#27)
saito-sv Nov 22, 2022
f76500e
Merge pull request #25 from String-xyz/task/andrin/str-187
Nov 22, 2022
d29a13e
Merge branch 'develop' into task/sean/str-195
auroter Nov 22, 2022
d26579b
Merge pull request #31 from String-xyz/task/sean/str-195
auroter Nov 22, 2022
7dc3e1c
cleanup constructors (#34)
alcalawil Nov 23, 2022
9ddd576
Email Verification Request endpoint waits up to 15 mins for email lin…
Nov 23, 2022
d34fe51
Fix env.example file (#33)
alcalawil Nov 24, 2022
b12146a
Merge branch 'develop' into task/sean/str-218
Nov 28, 2022
957395e
Datadog feature flag
frostbournesb Nov 28, 2022
09290f5
throttle email request repo polling to 3s intervals
Nov 28, 2022
6a22ec8
Using X-Forwarded-For [ip] in insomnia for geofencing before we conve…
Nov 28, 2022
caa6b0f
remove debugging prints
Nov 28, 2022
0b193e8
Merge pull request #35 from String-xyz/task/sean/str-218
auroter Nov 29, 2022
e99e0b3
Use ENV flag instead of separate flag
frostbournesb Nov 29, 2022
16f5536
Merge pull request #38 from String-xyz/task/dante/str-234
frostbournesb Nov 29, 2022
694bb9e
wallet login!
Nov 29, 2022
997851e
Change GET /login to POST /login
Nov 29, 2022
6b96181
body validator(STR-225) (#36)
saito-sv Nov 29, 2022
86b7e82
new insomnia.json file to update login input
ocasta181 Nov 29, 2022
34e4c70
Merge pull request #39 from String-xyz/task/sean/str-220
auroter Nov 29, 2022
4072c5f
Create User requires wallet verification payload, same as Login
Nov 29, 2022
0f93e4e
add trailing new lines for clarity
ocasta181 Nov 29, 2022
3111fc4
update Insomnia
Nov 30, 2022
069dfe6
Merge branch 'task/sean/str-219' of https://github.com/String-xyz/str…
Nov 30, 2022
262e01e
be sure to return on error
ocasta181 Nov 30, 2022
4206379
unix time is in seconds, not ms
Nov 30, 2022
2a7efe6
Merge pull request #40 from String-xyz/task/sean/str-219
auroter Nov 30, 2022
b8466ab
STR-217 :: JWT in Cookie (#37)
alcalawil Dec 1, 2022
ae02278
Added basic email receipts!
Dec 1, 2022
2342763
Merge branch 'develop' into task/sean/str-235
auroter Dec 1, 2022
d38a7ad
typo
Dec 1, 2022
6c86a7a
Merge branch 'task/sean/str-235' of https://github.com/String-xyz/str…
Dec 1, 2022
33349be
Added block explorer hyperlinks for Transact endpoint return, Email r…
Dec 2, 2022
2f72466
Transaction returns raw TXID + URL
Dec 2, 2022
e6df434
Update insomnia json
Dec 2, 2022
a2a4a8c
update insomnia.json to not use bearer
Dec 2, 2022
8707bb0
if user has not updated their name, address them in email as 'User'
Dec 2, 2022
89274a9
reset test defaults for TestSignandValidateStruct
Dec 2, 2022
bf1640d
STR-198 :: Make endpoint responses and errors JSON encoded (#41)
alcalawil Dec 6, 2022
892a6ce
Merge pull request #42 from String-xyz/task/sean/str-235
Dec 6, 2022
41a5a0d
rebased
saito-sv Dec 6, 2022
9d9f1a3
removed login type and fixed email verificaion link
saito-sv Dec 6, 2022
c3dba54
rebased with latest of develop and removed loginType
saito-sv Dec 6, 2022
fc10254
rebased
saito-sv Dec 7, 2022
5bcd56e
some simple test on handlers
saito-sv Dec 7, 2022
61419c7
fixed conflicts and added message
saito-sv Dec 7, 2022
64f77a6
added validators and test are now passing
saito-sv Dec 8, 2022
ae48a2c
send user back on login and creation
saito-sv Dec 8, 2022
33f12ac
fixed error failing due to middleware not being passed in on test
saito-sv Dec 8, 2022
9ffe555
Fix timestamp validation in wallet auth payload
Dec 8, 2022
1f62507
removed wallet from user get status
saito-sv Dec 9, 2022
081dc0f
returning user when updating
saito-sv Dec 9, 2022
cf0fad0
added verification endpoint
saito-sv Dec 9, 2022
2a9c71a
removed /
saito-sv Dec 9, 2022
319ce5d
added &
saito-sv Dec 9, 2022
2e3b9cf
quote endpoint
saito-sv Dec 9, 2022
5ab79a1
renamed error
saito-sv Dec 9, 2022
71125a2
update insomnia
Dec 9, 2022
986c80a
added cookie and JSON response in some missing endpoints
saito-sv Dec 12, 2022
a55e544
Change Nonce Payload to return a string. Change Login and Create to …
Dec 12, 2022
c965158
removed deprecated variable from sign_test
Dec 12, 2022
ba65596
edit comments in sign_test.go
Dec 12, 2022
71c0c96
STR-224 RESTful API endpoints (#43)
saito-sv Dec 12, 2022
7a56d5d
Merge branch 'develop' into task/sean/str-263
auroter Dec 12, 2022
59d47dc
update insomnia.json
ocasta181 Dec 12, 2022
8f89766
STR-266 :: Refactor :: Repos and Service Initialization (#45)
alcalawil Dec 12, 2022
e89416e
Update api/handler/login.go
auroter Dec 13, 2022
24c71ea
undo suggestion
Dec 13, 2022
6002b8b
Merge pull request #46 from String-xyz/task/sean/str-263
auroter Dec 13, 2022
d5445f6
fixed handler test cases and login strucuted json (#48)
saito-sv Dec 14, 2022
612a9cd
Data seeding!
Dec 15, 2022
5495e80
remove unused platform, device
Dec 15, 2022
4a3e931
Oops we need the device
Dec 15, 2022
4bfd744
renamed some values for production data
Dec 15, 2022
7bd430b
update bank instrument details, add command line args for data seeding
Dec 15, 2022
a1dc823
set default to production, allow for omitted environment param
ocasta181 Dec 15, 2022
a26572b
whitespace fixes
ocasta181 Dec 15, 2022
576eb4c
more whitespace
ocasta181 Dec 15, 2022
16698bf
auto-populate Internal UUIDS
Dec 16, 2022
7cb2787
Merge pull request #49 from String-xyz/task/sean/str-196
auroter Dec 16, 2022
6a7ba2e
Merge branch 'develop' into task/sean/str-206
Dec 16, 2022
d576aab
fixed shadowed errs in repo, renamed uuids to ids when storing as string
Dec 16, 2022
2c859fc
Update entrypoint.sh to include new data seeding
Dec 16, 2022
2872408
fixed GetBankByUserId, added GetByApyKey to Platform repo, added plat…
Dec 16, 2022
3ab2410
LIMIT 1 for repo.user.getbytype
Dec 16, 2022
bfe2adc
Add user ID when creating new instrument
Dec 16, 2022
92a7915
Merge pull request #51 from String-xyz/task/sean/str-206
auroter Dec 17, 2022
acdf0a5
STR-275(Fingerprint integration) (#50)
saito-sv Dec 20, 2022
76a81f1
store user device in cookie in JWT claims, insert user device ID in T…
Dec 20, 2022
dca7421
Remove placeholding String Device from data seeding
Dec 20, 2022
a611b3c
fixed syntax error in sql query
ocasta181 Dec 20, 2022
50351d4
Update scripts/data_seeding.go
auroter Dec 20, 2022
1b37d45
Merge pull request #52 from String-xyz/task/sean/str-287
auroter Dec 20, 2022
113ba65
add deactivated_at to migrations and models
ocasta181 Dec 21, 2022
fcdf4b6
STR-217(device verification) (#54)
saito-sv Dec 21, 2022
72d759e
Merge pull request #56 from String-xyz/task/andrin/str-292
Dec 21, 2022
8beb084
Use eip131 for API signing and validating both API and external signa…
Dec 21, 2022
878464c
fixed typo in sign_test
Dec 21, 2022
f9fa974
Made EVM signatures compatible with EIP131, non EIP-155
Dec 23, 2022
77c1d54
...
Dec 23, 2022
58877e2
Merge pull request #57 from String-xyz/task/sean/str-290
auroter Dec 23, 2022
2c6739e
Set String User ID using ENV var
Dec 23, 2022
406defb
Move all internal IDs to ENV
Dec 26, 2022
0af77a3
make \login endpoints require api-key
ocasta181 Dec 26, 2022
4867b1b
Add insomnia.json file
ocasta181 Dec 26, 2022
712721c
Merge pull request #65 from String-xyz/task/andrin/api-key-login
Dec 26, 2022
1ea0c14
Improve Docker Logs (#62)
alcalawil Dec 27, 2022
37cfadb
Adding KMS encrypt/decrypt
Dec 27, 2022
6b43f4b
Added SSM Put
Dec 27, 2022
e5a7a52
Update scripts/data_seeding.go
auroter Dec 27, 2022
6b5d426
Merge pull request #60 from String-xyz/task/sean/str-286
auroter Dec 28, 2022
9ac50a0
changed script structure to support multiple scripts, fixed SSM get/p…
Dec 28, 2022
96c4d8b
STR-278 :: Login Flow :: User Create Endpoint respond 409 if user exi…
alcalawil Dec 28, 2022
1de812e
Made SSM work, maintain wallet addr in SSM, print old private key whe…
Dec 29, 2022
10d0687
don't overwrite if wallet is already on SSM
Dec 30, 2022
56d7a62
moving away from storing private key in env, added wallet_test.go to …
Dec 30, 2022
18f4a3d
remove wallet generation logic / ssm access from API logic, place it …
Dec 30, 2022
43c2d9b
get AWS region from env
Dec 30, 2022
aba96c8
fixed typo
Dec 30, 2022
c9d39f4
Merge pull request #66 from String-xyz/task/sean/str-294
auroter Dec 30, 2022
ebc7da9
STR-293(perms and env vars to deploy to dev env) (#58)
saito-sv Jan 4, 2023
3a11d9f
abstract redis for ease of use locally (#67)
saito-sv Jan 4, 2023
edd839d
Decrypt SK with KMS
Jan 5, 2023
24d317a
STR-288 :: Refresh Token endpoint (#64)
alcalawil Jan 5, 2023
28f797f
Merge pull request #69 from String-xyz/task/sean/str-320
auroter Jan 5, 2023
9803cd3
Ensure all env vars (STR-280) (#68)
saito-sv Jan 5, 2023
b8f9a9d
Updated data_seeding script to include abitrum nova.
Jan 6, 2023
ab99ef1
Fixed a bug where Execute Transaction failed because Credit Card auth…
Jan 6, 2023
ada3b70
Added insomnia endpoint for Arbitrum Nova Quote
Jan 6, 2023
4387744
scrub PI from insomnia.json
ocasta181 Jan 6, 2023
ed7d285
Merge pull request #71 from String-xyz/task/sean/str-317
auroter Jan 6, 2023
ec251ae
add arbitrum nova mainnet to data_seeding
Jan 6, 2023
00f0711
update avalanche and fuji network ID to be 1
Jan 6, 2023
404de4f
Rename Arbitrum Nova Testnet to Nitro Goerli Rollup Testnet
Jan 6, 2023
9a9ef35
Merge pull request #73 from String-xyz/fix/sean/arbitrum_nova
auroter Jan 6, 2023
1957c0c
prod deployment prep(STR-238) (#72)
saito-sv Jan 7, 2023
4279952
make IsLocalEnv public and base AuthAPIKey internal bool on it
ocasta181 Jan 9, 2023
8e638ad
handle STR-323 Put all environment checks behind the new IsLocal() fu…
ocasta181 Jan 9, 2023
8167976
stashing
Jan 9, 2023
32d5ea9
Merge pull request #74 from String-xyz/task/andrin/str-330
Jan 9, 2023
6afbe28
Added message to beginning of WalletAuthenticationPayload, then dealt…
Jan 9, 2023
1018e8b
re-enable API key protection
Jan 9, 2023
63c81b7
shorten logic
Jan 9, 2023
65ccdec
added a space between message and nonce
Jan 9, 2023
324ed6a
respond 409 when user email is already validated (#75)
alcalawil Jan 9, 2023
f938dbe
now with newlines!
Jan 9, 2023
68e3447
stop throwing stringerror if fingerprint doesn't provide a subdivisio…
Jan 9, 2023
db764f1
Merge pull request #77 from String-xyz/task/sean/fixFingerprint
auroter Jan 9, 2023
d683f81
Update service fee floor to $0.30
Jan 10, 2023
d9f0b7f
change string fee to 3%
Jan 10, 2023
d06738d
small changes to fee + more comments
ocasta181 Jan 10, 2023
8bae94a
Merge pull request #78 from String-xyz/task/sean/priceFloor
auroter Jan 10, 2023
68f7b06
punctuation
Jan 10, 2023
2d43900
Merge pull request #76 from String-xyz/task/sean/str-249
auroter Jan 10, 2023
d7d1f51
admin api infra (#79)
saito-sv Jan 10, 2023
9c7ecc1
fixed versioning (#80)
saito-sv Jan 10, 2023
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
8 changes: 4 additions & 4 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
root = "."
testdata_dir = "testdata"
testdata_dir = "pkg/test"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./src/cmd/app/main.go"
cmd = "go build -o ./tmp/main ./cmd/app/main.go"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_dir = ["assets", "tmp", "vendor", "testdata", "test"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_ext = ["go", "tpl", "tmpl", "html", "env"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
Expand Down
31 changes: 28 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
BASE_URL=https://localhost:5555/
ENV=local
PORT=5555
COINGECKO_API_URL=https://api.coingecko.com/api/v3/
OWLRACLE_API_URL=https://owlracle.info/
OWLRACLE_API_URL=https://api.owlracle.info/v3/
OWLRACLE_API_KEY=
OWLRACLE_API_SECRET=
AWS_REGION=us-west-2
AWS_ACCT=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_KMS_KEY_ID=
CHECKOUT_PUBLIC_KEY=
CHECKOUT_SECRET_KEY=
EVM_PRIVATE_KEY=
DB_NAME=
DB_USER=
DB_NAME=string_db
DB_USERNAME=string_db
DB_PASSWORD=string_password
DB_HOST=db
DB_PORT=5432
REDIS_PASSWORD=eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
REDIS_HOST=redis
REDIS_PORT=6379
JWT_SECRET_KEY=hskdhfjfkdhsgafgwterurorhfh
UNIT21_API_KEY=
UNIT21_ENV=sandbox2-api
UNIT21_ORG_NAME=string
TWILIO_ACCOUNT_SID=AC034879a536d54325687e48544403cb4d
TWILIO_AUTH_TOKEN=
TWILIO_SMS_SID=MG367a4f51ea6f67a28db4d126eefc734f
DEV_PHONE_NUMBERS=+14088675309,+14155555555
STRING_ENCRYPTION_KEY=secret_encryption_key_0123456789
SENDGRID_API_KEY=
IPSTACK_API_KEY=
FINGERPRINT_API_KEY=
FINGERPRINT_API_URL=https://api.fpjs.io/
STRING_INTERNAL_ID=00000000-0000-0000-0000-000000000000
STRING_WALLET_ID=00000000-0000-0000-0000-000000000001
STRING_BANK_ID=00000000-0000-0000-0000-000000000002
STRING_PLACEHOLDER_PLATFORM_ID=00000000-0000-0000-0000-000000000003
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
on:
pull_request:
branches:
- develop

name: run tests
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.3
- name: Run golangci-lint
run: golangci-lint run --version --verbose --out-format=github-actions

test:
strategy:
matrix:
go-version: [1.19]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: go test ./pkg/... -v -covermode=count

coverage:
runs-on: ubuntu-latest
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Checkout code
uses: actions/checkout@v2
- name: Calc coverage
run: |
go test ./pkg/... -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage.out to coverage.lcov
uses: jandelgado/gcov2lcov-action@v1
- name: Coveralls
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
tmp/
.env
.env
.env.deploy
.vscode/
.terraform/
bin/

41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
include .env.deploy

export
AWS_DEFAULT_PROFILE=${env}-string
API=string-api
ECS_CLUSTER=string-core
SERVICE_TAG=${tag}
ECR=${${env}_AWS_ACCT}.dkr.ecr.us-west-2.amazonaws.com
ECS_API_REPO=${ECR}/${API}
INTERNAL_REPO=${ECR}/admin

all: build push deploy
all-internal: build-internal push-internal deploy-internal

test-envvars:
@[ "${env}" ] || ( echo "env var is not set"; exit 1 )
@[ "${tag}" ] || ( echo "env tag is not set"; exit 1 )

build: test-envvars
GOOS=linux GOARCH=amd64 go build -o ./cmd/app/main ./cmd/app/main.go
docker build --platform linux/amd64 -t $(ECS_API_REPO):${SERVICE_TAG} cmd/app/
rm cmd/app/main

push: test-envvars
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(ECR)
docker push $(ECS_API_REPO):${SERVICE_TAG}

deploy: test-envvars
aws ecs --region $(AWS_REGION) update-service --cluster $(ECS_CLUSTER) --service ${API} --force-new-deployment

build-internal:test-envvars
GOOS=linux GOARCH=amd64 go build -o ./cmd/internal/main ./cmd/internal/main.go
docker build --platform linux/amd64 -t $(INTERNAL_REPO):${SERVICE_TAG} cmd/internal/
rm cmd/internal/main

push-internal:test-envvars
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(INTERNAL_REPO)
docker push $(INTERNAL_REPO):${SERVICE_TAG}

deploy-internal: test-envvars
aws ecs --region $(AWS_REGION) update-service --cluster admin --service admin --force-new-deployment
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
For Live Reloading:
### For Live Reloading: ###
1. install [Air|https://github.com/cosmtrek/air]: `go install github.com/cosmtrek/air@latest`
2. run `air`
3. if you get `zsh: command not found: air` you need to add to PATH: `PATH=$PATH:$(go env GOPATH)/bin`

For migrations:
### For migrations: ###
1. install [Goose|https://pressly.github.io/] `brew install goose`
2. Note, this binary is separate from the go package.
3. `goose postgres "host=localhost dbname=string_db user=string_db password=string_password sslmode=disable" down-to 0`

### Postgres & Redis - Docker Compose: ***local dev only*** ###
1. To build and start the docker containers for the first time: `docker-compose up --build`
2. To shutdown the docker containers press `ctl + c`

### Docker Issues?
1. If docker is giving you an error when you try to `docker-compose up --build` try the following commands in order:
2. `docker-compose down`
3. `docker system prune` (/y)
4. `docker volume prune` (/y)
5. `docker compose up --build`

### For local development: ###
`cd api`
run `go install` to get dependencies installed

### For local testing: ###
run `go test`

### Unit21: ###
This is a 3rd party service that offers the ability to evaluate risk at a transaction level and identify fraud. A client file exists to connect to their API. Documentation is here: https://docs.unit21.ai/reference/entities-api
You can create a test API key on the Unit21 dashboard. You will need to be setup as an Admin. Here are the instructions: https://docs.unit21.ai/reference/generate-api-keys
When setting up the production env variables, their URL will be: https://api.unit21.com/v1
117 changes: 85 additions & 32 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,111 @@
package api

import (
"errors"
"net/http"

"github.com/String-xyz/string-api/api/handler"
"github.com/String-xyz/string-api/pkg/repository"
"github.com/String-xyz/string-api/api/middleware"
"github.com/String-xyz/string-api/api/validator"
"github.com/String-xyz/string-api/pkg/service"
"github.com/String-xyz/string-api/pkg/store"
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog"
)

type APIConfig struct {
DB any
Port string
// redis
DB *sqlx.DB
Redis store.RedisStore
Logger *zerolog.Logger
Port string
}

func Start(config APIConfig) error {
func heartbeat(c echo.Context) error {
return c.JSON(http.StatusOK, "alive")
}

func Start(config APIConfig) {
e := echo.New()
e.Validator = validator.New()
baseMiddleware(config.Logger, e)

// Allow all CORS
// not internal middlewares
geofencingService := service.NewGeofencing(config.Redis)
e.Use(middleware.Georestrict(geofencingService))

// Todo: Add Logger
e.GET("/heartbeat", heartbeat)

// TODO: Create middleware for jwt
// initialize route dependencies
repos := NewRepos(config)
services := NewServices(config, repos)

////////////////////////
// REPOSITORIES
////////////////////////
transactRepo := repository.NewTransaction(config.DB)
// initialize routes - A route group only needs access to the services layer. It should'n access the repos layer directly
AuthAPIKey(services, e, handler.IsLocalEnv())
transactRoute(services, e)
quoteRoute(services, e)
userRoute(services, e)
loginRoute(services, e)
verificationRoute(services, e)

////////////////////////
// SERVICES
////////////////////////
transactService := service.NewTransaction(transactRepo)
e.Logger.Fatal(e.Start(":" + config.Port))
}

////////////////////////
// HANDLERS
////////////////////////
transactHandler := handler.NewTransaction(e, transactService)
func StartInternal(config APIConfig) {
e := echo.New()
e.Validator = validator.New()
baseMiddleware(config.Logger, e)
e.GET("/heartbeat", heartbeat)

////////////////////////
// MIDDLEWARE
////////////////////////
// cors := middleware.StringMiddleware(middleware.MiddlewareConfig{any: 0})
// initialize route dependencies
repos := NewRepos(config)
services := NewServices(config, repos)

var transactMiddleware []echo.MiddlewareFunc
// initialize routes - A route group only needs access to the services layer. It doesn't need access to the repos layer
platformRoute(services, e)
AuthAPIKey(services, e, true)
e.Logger.Fatal(e.Start(":" + config.Port))
}

////////////////////////
// REGISTER ROUTES
////////////////////////
transactHandler.RegisterRoutes(e.Group("/transact"), transactMiddleware...)
func baseMiddleware(logger *zerolog.Logger, e *echo.Echo) {
e.Use(middleware.Tracer())
e.Use(middleware.CORS())
e.Use(middleware.RequestID())
e.Use(middleware.Recover())
e.Use(middleware.Logger(logger))
e.Use(middleware.LogRequest())
}

e.Logger.Fatal(e.Start(":" + config.Port))
func platformRoute(services service.Services, e *echo.Echo) {
handler := handler.NewPlatform(services.Platform)
handler.RegisterRoutes(e.Group("/platforms"), middleware.BearerAuth())
}

return errors.New("error")
func AuthAPIKey(services service.Services, e *echo.Echo, internal bool) {
handler := handler.NewAuthAPIKey(services.ApiKey, internal)
handler.RegisterRoutes(e.Group("/apikeys"))
}

func transactRoute(services service.Services, e *echo.Echo) {
handler := handler.NewTransaction(e, services.Transaction)
handler.RegisterRoutes(e.Group("/transactions"), middleware.APIKeyAuth(services.Auth), middleware.BearerAuth())
}

func userRoute(services service.Services, e *echo.Echo) {
handler := handler.NewUser(e, services.User, services.Verification)
handler.RegisterRoutes(e.Group("/users"), middleware.APIKeyAuth(services.Auth), middleware.BearerAuth())
}

func loginRoute(services service.Services, e *echo.Echo) {
handler := handler.NewLogin(e, services.Auth)
handler.RegisterRoutes(e.Group("/login"), middleware.APIKeyAuth(services.Auth))
}

func verificationRoute(services service.Services, e *echo.Echo) {
handler := handler.NewVerification(e, services.Verification)
handler.RegisterRoutes(e.Group("/verification"))
}

func quoteRoute(services service.Services, e *echo.Echo) {
handler := handler.NewQuote(e, services.Transaction)
handler.RegisterRoutes(e.Group("/quotes"), middleware.APIKeyAuth(services.Auth), middleware.BearerAuth())
}
Loading