Skip to content

Commit

Permalink
Some more initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrekmonko committed Dec 30, 2023
1 parent 9f6b666 commit d10359c
Show file tree
Hide file tree
Showing 30 changed files with 869 additions and 669 deletions.
6 changes: 5 additions & 1 deletion .portfello.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
database_dsn: "postgres://user:pass@localhost:5432/portfello?sslmode=disable"
database_dsn: "postgres://user:pass@localhost:15432/portfello?sslmode=disable"
logging:
format: "dev"
level: "debug"
graphql:
host: "http://localhost"
port: "8080"
enable_playground: true
auth:
provider: "local"
domain: "YOUR_DOMAIN.auth0.com"
client_id: "YOUR_CLIENT_ID"
client_secret: "YOUR_CLIENT_SECRET"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ How it works?

Portfello Server can be either self-hosted - to maximize your security, or used as a service @ www.portfel.lo

After setting up self-hosted server/signing up at www.portel.lo, you are able to create and share as many Wallets
After setting up self-hosted server/signing up at www.portfel.lo, you are able to create and share as many Wallets
as you wish. Each Wallet can represent any of available sync sources, either bank accounts, prepaid cards (supported
ones only) or prepaid phones. To set up synchronisation of your Wallet with Banking Provider you have to provide an
API key for accessing that provider, and an encryption key to securely store your API key.
Expand Down Expand Up @@ -177,7 +177,8 @@ Next steps
==========

After logging in test out a Wallet by using a Banking Provider's sandbox such as this one:
[MBank](https://developer.api.mbank.pl/documentation/sandbox-v2#section/How-to-test-requests-for-AIS).
[MBank](https://developer.api.mbank.pl/documentation/sandbox-v2#section/How-to-test-requests-for-AIS),
or this one: [Alior](https://developer.aliorbank.pl/openapipl/sb/).
Generate a key and configure your first Wallet using it, then observe how the data changes in UI, all without
using your real account.

Expand Down
15 changes: 8 additions & 7 deletions cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"github.com/piotrekmonko/portfello/pkg/auth"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/dao"
"github.com/piotrekmonko/portfello/pkg/logz"
"github.com/spf13/cobra"
"log"
"time"
)

Expand All @@ -42,16 +42,17 @@ var provisionCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
conf := config.New()
authProvider, err := auth.NewAuth0Provider(ctx, conf)
log := logz.NewLogger(&conf.Logging)
db, dbq, err := dao.NewDAO(ctx, log, conf.DatabaseDSN)
if err != nil {
log.Fatal(err)
return
}
authService := auth.New(authProvider)
db, dbq, err := dao.NewDAO(ctx, conf.DatabaseDSN)
defer db.Close()
authProvider, err := auth.NewProvider(ctx, log, conf, dbq)
if err != nil {
log.Fatal(err)
return
}
defer db.Close()
authService := auth.New(authProvider)

if email, _ := cmd.Flags().GetString("user"); email != "" {
if err := provisionUser(cmd.Context(), authService, email); err != nil {
Expand Down
14 changes: 10 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cmd

import (
"fmt"
"github.com/piotrekmonko/portfello/pkg/logz"
"go.uber.org/zap"
"os"

Expand All @@ -43,15 +44,20 @@ var rootCmd = &cobra.Command{
Short: "Backend services for PortfelloApp",
Long: `PortfelloApp is an opensource project for managing your household budget.`,
Version: "v1.0.0-dev",
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
lvl, err := cmd.Flags().GetString("level")
if err != nil {
return fmt.Errorf("cannot read log level: %w", err)
}
return logz.ParseFlag(lvl)
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
rootCmd.Version = fmt.Sprintf("%s-%s", baseVersion, buildNumber)
logz.SetVer(rootCmd.Version)
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down Expand Up @@ -80,7 +86,7 @@ func initConfig() {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
cobra.CheckErr(fmt.Errorf("fatal error config file @ %s: %w \n", cfgFile, err))
cobra.CheckErr(fmt.Errorf("fatal error config file @ %s: %w", cfgFile, err))
}
}

Expand Down
17 changes: 9 additions & 8 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/piotrekmonko/portfello/pkg/auth"
"github.com/piotrekmonko/portfello/pkg/config"
"github.com/piotrekmonko/portfello/pkg/dao"
"github.com/piotrekmonko/portfello/pkg/logz"
"github.com/piotrekmonko/portfello/pkg/server"
"github.com/spf13/cobra"
"log"
"net/http"
"os"
"os/signal"
Expand All @@ -44,34 +44,35 @@ var serveCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
conf := config.New()
log := logz.NewLogger(&conf.Logging)

db, dbQuerier, err := dao.NewDAO(ctx, conf.DatabaseDSN)
db, dbQuerier, err := dao.NewDAO(ctx, log, conf.DatabaseDSN)
if err != nil {
log.Fatal(err)
return
}
defer db.Close()

authProvider, err := auth.NewAuth0Provider(cmd.Context(), conf)
authProvider, err := auth.NewProvider(ctx, log, conf, dbQuerier)
if err != nil {
log.Fatal(err)
return
}
authService := auth.New(authProvider)

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

httpSrv := server.NewServer(ctx, conf, dbQuerier, authService)
httpSrv := server.NewServer(ctx, log, conf, dbQuerier, authService)
go func() {
if err := httpSrv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
_ = log.Errorw(ctx, err, "error while running http server")
}
}()
<-sigs

closeCtx, closeCanc := context.WithTimeout(ctx, time.Second)
defer closeCanc()
cobra.CheckErr(httpSrv.Shutdown(closeCtx))
log.Println("Server stopped")
log.Infow(ctx, "Server stopped")
},
}

Expand Down
1 change: 1 addition & 0 deletions dbschema/migrations/0001_initial.down.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
drop table if exists expense cascade;
drop table if exists wallet cascade;
drop table if exists history cascade;
drop table if exists local_user cascade;
13 changes: 13 additions & 0 deletions dbschema/migrations/0001_initial.up.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
create table local_user
(
email varchar(256) not null
primary key,
display_name text not null,
roles text not null,
pwdHash text not null,
created_at timestamp default now() not null
);

comment on table local_user is 'Holds user data for auth.LocalProvider. Development use only.';


create table history
(
id varchar(512) not null
Expand Down
12 changes: 12 additions & 0 deletions dbschema/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ SELECT * FROM expense WHERE wallet_id = $1 AND wallet_id IN (
SELECT id FROM wallet WHERE user_id = $2
)
ORDER BY id;

-- name: LocalUserInsert :exec
INSERT INTO local_user (email, display_name, roles, created_at) VALUES ($1, $2, $3, $4);

-- name: LocalUserUpdate :exec
UPDATE local_user SET roles = $1 WHERE email = $2;

-- name: LocalUserGetByEmail :one
SELECT * FROM local_user WHERE email = $1;

-- name: LocalUserList :many
SELECT * FROM local_user ORDER BY email;
78 changes: 40 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ module github.com/piotrekmonko/portfello
go 1.21

require (
github.com/99designs/gqlgen v0.17.40
github.com/auth0/go-auth0 v1.2.0
github.com/auth0/go-jwt-middleware/v2 v2.1.0
github.com/brianvoe/gofakeit/v6 v6.24.0
github.com/99designs/gqlgen v0.17.42
github.com/auth0/go-auth0 v1.4.0
github.com/auth0/go-jwt-middleware/v2 v2.2.0
github.com/brianvoe/gofakeit/v6 v6.26.3
github.com/eko/gocache/lib/v4 v4.1.5
github.com/eko/gocache/store/go_cache/v4 v4.2.1
github.com/go-acme/lego/v4 v4.14.2
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/uuid v1.4.0
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/google/uuid v1.5.0
github.com/lithammer/shortuuid/v4 v4.0.0
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
github.com/sqlc-dev/sqlc v1.23.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/sqlc-dev/sqlc v1.24.0
github.com/stretchr/testify v1.8.4
github.com/vektah/gqlparser/v2 v2.5.10
go.uber.org/zap v1.26.0
)
Expand All @@ -26,6 +27,7 @@ require (
github.com/PuerkitoBio/rehttp v1.3.0 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand All @@ -36,69 +38,69 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.18.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/google/cel-go v0.18.2 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.1 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mattn/go-sqlite3 v1.14.19 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pganalyze/pg_query_go/v4 v4.2.3 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/pingcap/tidb/parser v0.0.0-20231013125129-93a834a6bf8d // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/pingcap/tidb/pkg/parser v0.0.0-20240102121832-237b2c7d5078 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/riza-io/grpc-go v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sosodev/duration v1.2.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/urfave/cli/v2 v2.25.7 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d10359c

Please sign in to comment.