Skip to content

Commit

Permalink
feat: add missing pre commits
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Feb 27, 2024
1 parent 0fd03fd commit 1d65b8d
Show file tree
Hide file tree
Showing 36 changed files with 199 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ tests-integration:
pre-commit: # Generate the final spec and run all the pre-commit hooks
LOCALLY
BUILD --pass-args ./releases+sdk-generate
FOR component IN $(cd ./libs && ls -d */)
BUILD --pass-args ./libs/${component}+pre-commit
END
FOR component IN $(cd ./tools && ls -d */)
BUILD --pass-args ./tools/${component}+pre-commit
END
Expand Down
43 changes: 43 additions & 0 deletions libs/events/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
allow-parallel-runners: true
run:
timeout: 5m
linters:
disable-all: true
enable:
- gofmt
- goimports
- unused
- gosec
linters-settings:
gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
includes:
- G103 # Audit the use of unsafe block
- G104 # Audit errors not checked
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
- G108 # Profiling endpoint automatically exposed on /debug/pprof
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
- G110 # Potential DoS vulnerability via decompression bomb
- G111 # Potential directory traversal
- G112 # Potential slowloris attack
# - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G203 # Use of unescaped data in HTML templates
- G204 # Audit use of command execution
- G301 # Poor file permissions used when creating a directory
- G302 # Poor file permissions used with chmod
- G303 # Creating tempfile using a predictable path
- G304 # File path provided as taint input
- G305 # File traversal when extracting zip/tar archive
- G306 # Poor file permissions used when writing to a new file
- G307 # Poor file permissions used when creating a file with os.Create
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G403 # Ensure minimum RSA key length of 2048 bits
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G602 # Slice access out of bounds
46 changes: 46 additions & 0 deletions libs/events/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
VERSION --arg-scope-and-set --pass-args --use-function-keyword 0.7

ARG core=github.com/formancehq/earthly:v0.11.1
IMPORT $core AS core
IMPORT ../.. AS stack

FROM core+base-image

go-sources:
COPY events.go go.* base.yaml /src/
COPY --dir services /src/
WORKDIR /src
SAVE ARTIFACT /src

tidy:
FROM core+builder-image
COPY (+go-sources/*) /src
WORKDIR /src
DO --pass-args stack+GO_TIDY
SAVE ARTIFACT go.* AS LOCAL ./

lint:
FROM core+builder-image
COPY (+go-sources/*) /src
WORKDIR /src
COPY --pass-args +tidy/go.* .
DO --pass-args stack+GO_LINT
SAVE ARTIFACT * AS LOCAL ./

generate:
RUN apk add nodejs npm
WORKDIR /src
COPY package* .
RUN npm install
RUN mkdir generated
COPY index.js base.yaml .
COPY --dir services .
RUN node index.js
SAVE ARTIFACT generated AS LOCAL ./generated

pre-commit:
WAIT
BUILD --pass-args +tidy
END
BUILD --pass-args +lint
BUILD --pass-args +generate
3 changes: 2 additions & 1 deletion libs/events/events.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"embed"
"fmt"
"path/filepath"

"embed"

"github.com/pkg/errors"
"github.com/xeipuuv/gojsonschema"
"golang.org/x/mod/semver"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"ledger":{"type":"string"},"transactions":{"type":"array","items":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"},"reverted":{"type":"boolean"}},"required":["postings","reference","metadata","id","timestamp","reverted"]}}},"required":["ledger","transactions"]}},"required":["date","app","version","type","payload"]}
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"ledger":{"type":"string"},"transactions":{"type":"array","items":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"},"reverted":{"type":"boolean"}},"required":["postings","metadata","id","timestamp","reverted"]}}},"required":["ledger","transactions"]}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"ledger":{"type":"string"},"revertedTransaction":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"},"reverted":{"type":"boolean"}},"required":["postings","reference","metadata","id","timestamp","reverted"]},"revertTransaction":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"}},"required":["postings","reference","metadata","id","timestamp"]}},"required":["ledger","revertedTransaction","revertTransaction"]}},"required":["date","app","version","type","payload"]}
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"ledger":{"type":"string"},"revertedTransaction":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"},"reverted":{"type":"boolean"}},"required":["postings","metadata","id","timestamp","reverted"]},"revertTransaction":{"type":"object","properties":{"postings":{"type":"array","items":{"type":"object","properties":{"source":{"type":"string"},"destination":{"type":"string"},"amount":{"type":"number"},"asset":{"type":"string"}},"required":["source","destination","amount","asset"]}},"reference":{"type":"string"},"metadata":{"type":"object","properties":{},"required":[]},"id":{"type":"number"},"timestamp":{"type":"string"}},"required":["postings","metadata","id","timestamp"]}},"required":["ledger","revertedTransaction","revertTransaction"]}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"createdAt":{"type":"string"},"connector":{"type":"string"}},"required":["createdAt","connector"]}},"required":["date","app","version","type","payload"]}
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"createdAt":{"type":"string"},"connector":{"type":"string"}},"required":["createdAt","connectorId"]}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","createdAt"],"properties":{"id":{"type":"string"},"createdAt":{"type":"string","format":"date-time"}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","createdAt"],"properties":{"id":{"type":"string"},"createdAt":{"type":"string","format":"date-time"}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","reference","createdAt","connectorId","provider","defaultAsset","accountName","type"],"properties":{"id":{"type":"string"},"reference":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"connectorId":{"type":"string"},"provider":{"type":"string"},"defaultAsset":{"type":"string"},"accountName":{"type":"string"},"type":{"type":"string","enum":["UNKNOWN","INTERNAL","EXTERNAL"]}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["accountID","connectorId","createdAt","asset","balance"],"properties":{"accountID":{"type":"string"},"connectorId":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"asset":{"type":"string"},"balance":{"type":"number","format":"bigint"}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","createdAt","name","country"],"properties":{"id":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"name":{"type":"string"},"country":{"type":"string"},"accountNumber":{"type":"string"},"iban":{"type":"string"},"swiftBicCode":{"type":"string"},"adjustments":{"type":["array","null"],"items":{"type":"object","required":["id","createdAt","accountID","connectorID","provider"],"properties":{"id":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"accountID":{"type":"string"},"connectorID":{"type":"string"},"provider":{"type":"string"}}}}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","properties":{"provider":{"type":"string"},"reference":{"type":"string"},"scheme":{"type":"string","enum":["unknown","other","visa","mastercard","amex","diners","discover","jcb","unionpay","sepa debit","sepa credit","sepa","apple pay","google pay","a2a","ach debit","ach","rtp"]},"type":{"type":"string","enum":["PAY-IN","PAYOUT","TRANSFER","OTHER"]},"status":{"type":"string"},"id":{"type":"string"},"initialAmount":{"type":"number"},"createdAt":{"type":"string","format":"date-time"}}}},"required":["date","app","version","type","payload"]}
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","reference","createdAt","connectorId","provider","type","status","scheme","asset","amount","initialAmount"],"properties":{"id":{"type":"string"},"reference":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"connectorId":{"type":"string"},"provider":{"type":"string"},"type":{"type":"string","enum":["PAY-IN","PAYOUT","TRANSFER","OTHER"]},"status":{"type":"string"},"scheme":{"type":"string","enum":["unknown","other","visa","mastercard","amex","diners","discover","jcb","unionpay","alipay","cup","sepa debit","sepa credit","sepa","apple pay","google pay","doku","dragonpay","maestro","molpay","a2a","ach debit","ach","rtp"]},"asset":{"type":"string"},"amount":{"type":"number","format":"bigint"},"initialAmount":{"type":"number","format":"bigint"},"sourceAccountId":{"type":"string"},"destinationAccountId":{"type":"string"},"links":{"type":["array","null"],"items":{"type":"object","properties":{"name":{"type":"string"},"uri":{"type":"string"}}}},"rawData":{"type":"object"},"metadata":{"type":"object","additionalProperties":{"type":"string"}}}}},"required":["date","app","version","type","payload"]}
1 change: 1 addition & 0 deletions libs/events/generated/payments-v1.0.0-SAVED_POOL.yaml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","name","createdAt","accountIDs"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"accountIDs":{"type":"array","items":{"type":"string"}}}}},"required":["date","app","version","type","payload"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"object","properties":{"app":{"type":"string"},"version":{"type":"string"},"date":{"type":"string","format":"date-time"},"type":{"type":"string"},"ledger":{"type":"string"},"payload":{"type":"object","required":["id","createdAt","scheduledAt","connectorId","provider","description","type","destinationAccountId","amount","asset","attempts","status","error"],"properties":{"id":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"scheduledAt":{"type":"string","format":"date-time"},"connectorId":{"type":"string"},"provider":{"type":"string"},"description":{"type":"string"},"type":{"type":"string","enum":["TRANSFER","PAYOUT"]},"sourceAccountId":{"type":"string"},"destinationAccountId":{"type":"string"},"amount":{"type":"number","format":"bigint"},"asset":{"type":"string"},"attempts":{"type":"number"},"status":{"type":"string","enum":["WAITING_FOR_VALIDATION","PROCESSING","PROCESSED","FAILED","REJECTED","VALIDATED","ASK_RETRIED","ASK_REVERSED","REVERSE_PROCESSING","REVERSE_FAILED","PARTIALLY_REVERSED","REVERSED"]},"error":{"type":"string"},"relatedPayments":{"type":["array","null"],"items":{"type":"object","required":["transferInitiationId","paymentId","createdAt","status","error"],"properties":{"transferInitiationId":{"type":"string"},"paymentId":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"status":{"type":"string"},"error":{"type":"string"}}}}}}},"required":["date","app","version","type","payload"]}
3 changes: 1 addition & 2 deletions libs/events/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require("fs/promises");
const yaml = require('yaml')
const JsonSchemaStaticDocs = require("json-schema-static-docs");
const yaml = require('yaml');

(async () => {

Expand Down
43 changes: 43 additions & 0 deletions libs/go-libs/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
allow-parallel-runners: true
run:
timeout: 5m
linters:
disable-all: true
enable:
- gofmt
- goimports
- unused
- gosec
linters-settings:
gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
includes:
- G103 # Audit the use of unsafe block
- G104 # Audit errors not checked
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
- G108 # Profiling endpoint automatically exposed on /debug/pprof
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
- G110 # Potential DoS vulnerability via decompression bomb
- G111 # Potential directory traversal
- G112 # Potential slowloris attack
# - G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G203 # Use of unescaped data in HTML templates
- G204 # Audit use of command execution
- G301 # Poor file permissions used when creating a directory
- G302 # Poor file permissions used with chmod
- G303 # Creating tempfile using a predictable path
- G304 # File path provided as taint input
- G305 # File traversal when extracting zip/tar archive
- G306 # Poor file permissions used when writing to a new file
- G307 # Poor file permissions used when creating a file with os.Create
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G403 # Ensure minimum RSA key length of 2048 bits
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G602 # Slice access out of bounds
17 changes: 16 additions & 1 deletion libs/go-libs/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ VERSION --arg-scope-and-set --pass-args --use-function-keyword 0.7

ARG core=github.com/formancehq/earthly:v0.11.1
IMPORT $core AS core
IMPORT ../.. AS stack

FROM core+base-image

Expand All @@ -15,4 +16,18 @@ tidy:
COPY (+sources/*) /src
WORKDIR /src
DO --pass-args stack+GO_TIDY
SAVE ARTIFACT go.* AS LOCAL ./
SAVE ARTIFACT go.* AS LOCAL ./

lint:
FROM core+builder-image
COPY (+sources/*) /src
WORKDIR /src
COPY --pass-args +tidy/go.* .
DO --pass-args stack+GO_LINT
SAVE ARTIFACT * AS LOCAL ./

pre-commit:
WAIT
BUILD --pass-args +tidy
END
BUILD --pass-args +lint
1 change: 1 addition & 0 deletions libs/go-libs/aws/iam/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iam

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/spf13/pflag"
Expand Down
3 changes: 2 additions & 1 deletion libs/go-libs/bun/bunconnect/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package bunconnect
import (
"context"
"database/sql/driver"
"time"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/formancehq/stack/libs/go-libs/aws/iam"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/formancehq/stack/libs/go-libs/service"
"github.com/lib/pq"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"time"
)

const (
Expand Down
1 change: 1 addition & 0 deletions libs/go-libs/bun/bunconnect/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql/driver"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/rds/auth"
"github.com/formancehq/stack/libs/go-libs/logging"
Expand Down
1 change: 1 addition & 0 deletions libs/go-libs/bun/bunconnect/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bunconnect

import (
"context"

"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/uptrace/bun"
"go.uber.org/fx"
Expand Down
1 change: 1 addition & 0 deletions libs/go-libs/bun/bunmigrate/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/formancehq/stack/libs/go-libs/bun/bunconnect"
"github.com/spf13/cobra"
"github.com/uptrace/bun"

// Import the postgres driver.
_ "github.com/lib/pq"
)
Expand Down
Loading

0 comments on commit 1d65b8d

Please sign in to comment.