From 15ab461a5e02f75ec5f765a751186e0bb996c45d Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 Apr 2023 15:14:42 +0300 Subject: [PATCH] psql first commit --- .idea/.gitignore | 8 +++ .idea/mobility-accounts.iml | 4 ++ .idea/vcs.xml | 6 ++ Dockerfile | 0 LICENCE.md | 0 README.md | 0 config.go | 0 examples/grpcclient/README.md | 0 examples/grpcclient/go.mod | 0 examples/grpcclient/go.sum | 0 .../json/account_with_local_auth.json | 0 examples/grpcclient/main.go | 0 go.mod | 1 + go.sum | 4 ++ grpcapi/README.md | 0 grpcapi/accounts.go | 0 grpcapi/accounts.pb.go | 0 grpcapi/accounts.proto | 0 grpcapi/comasvc.pb.go | 0 grpcapi/comasvc.proto | 0 grpcapi/comasvc_grpc.pb.go | 0 grpcapi/grpcapi.go | 0 handlers/accounts.go | 0 handlers/handlers.go | 0 main.go | 0 oidc-provider/endpoints_auth.go | 0 oidc-provider/endpoints_introspection.go | 0 oidc-provider/endpoints_token.go | 0 oidc-provider/endpoints_userinfo.go | 0 oidc-provider/endpoints_wellknown.go | 0 oidc-provider/fosite.go | 0 oidc-provider/oidc-provider.go | 0 oidc-provider/server.go | 0 oidc-provider/templates/default/auth.html | 0 oidc-provider/templates/parcoursmob/auth.html | 0 schemas/CMS/civil-status.schema.json | 0 schemas/CMS/driving-licence.schema.json | 0 schemas/CMS/favorites.schema.json | 0 schemas/CMS/fr-caf-information.schema.json | 0 schemas/CMS/fr-dgfip-information.schema.json | 0 schemas/CMS/fr-mesri-information.schema.json | 0 .../in-case-of-emergency-contacts.schema.json | 0 schemas/CMS/personal-information.schema.json | 0 storage/accounts.go | 0 storage/etcd.go | 0 storage/mongodb.go | 0 storage/postgresql.go | 63 +++++++++++++++++++ storage/postgresql_test.go | 21 +++++++ storage/storage.go | 3 + 49 files changed, 110 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/mobility-accounts.iml create mode 100644 .idea/vcs.xml mode change 100644 => 100755 Dockerfile mode change 100644 => 100755 LICENCE.md mode change 100644 => 100755 README.md mode change 100644 => 100755 config.go mode change 100644 => 100755 examples/grpcclient/README.md mode change 100644 => 100755 examples/grpcclient/go.mod mode change 100644 => 100755 examples/grpcclient/go.sum mode change 100644 => 100755 examples/grpcclient/json/account_with_local_auth.json mode change 100644 => 100755 examples/grpcclient/main.go mode change 100644 => 100755 go.mod mode change 100644 => 100755 go.sum mode change 100644 => 100755 grpcapi/README.md mode change 100644 => 100755 grpcapi/accounts.go mode change 100644 => 100755 grpcapi/accounts.pb.go mode change 100644 => 100755 grpcapi/accounts.proto mode change 100644 => 100755 grpcapi/comasvc.pb.go mode change 100644 => 100755 grpcapi/comasvc.proto mode change 100644 => 100755 grpcapi/comasvc_grpc.pb.go mode change 100644 => 100755 grpcapi/grpcapi.go mode change 100644 => 100755 handlers/accounts.go mode change 100644 => 100755 handlers/handlers.go mode change 100644 => 100755 main.go mode change 100644 => 100755 oidc-provider/endpoints_auth.go mode change 100644 => 100755 oidc-provider/endpoints_introspection.go mode change 100644 => 100755 oidc-provider/endpoints_token.go mode change 100644 => 100755 oidc-provider/endpoints_userinfo.go mode change 100644 => 100755 oidc-provider/endpoints_wellknown.go mode change 100644 => 100755 oidc-provider/fosite.go mode change 100644 => 100755 oidc-provider/oidc-provider.go mode change 100644 => 100755 oidc-provider/server.go mode change 100644 => 100755 oidc-provider/templates/default/auth.html mode change 100644 => 100755 oidc-provider/templates/parcoursmob/auth.html mode change 100644 => 100755 schemas/CMS/civil-status.schema.json mode change 100644 => 100755 schemas/CMS/driving-licence.schema.json mode change 100644 => 100755 schemas/CMS/favorites.schema.json mode change 100644 => 100755 schemas/CMS/fr-caf-information.schema.json mode change 100644 => 100755 schemas/CMS/fr-dgfip-information.schema.json mode change 100644 => 100755 schemas/CMS/fr-mesri-information.schema.json mode change 100644 => 100755 schemas/CMS/in-case-of-emergency-contacts.schema.json mode change 100644 => 100755 schemas/CMS/personal-information.schema.json mode change 100644 => 100755 storage/accounts.go mode change 100644 => 100755 storage/etcd.go mode change 100644 => 100755 storage/mongodb.go create mode 100644 storage/postgresql.go create mode 100644 storage/postgresql_test.go mode change 100644 => 100755 storage/storage.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/mobility-accounts.iml b/.idea/mobility-accounts.iml new file mode 100644 index 0000000..7ee078d --- /dev/null +++ b/.idea/mobility-accounts.iml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 diff --git a/LICENCE.md b/LICENCE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/config.go b/config.go old mode 100644 new mode 100755 diff --git a/examples/grpcclient/README.md b/examples/grpcclient/README.md old mode 100644 new mode 100755 diff --git a/examples/grpcclient/go.mod b/examples/grpcclient/go.mod old mode 100644 new mode 100755 diff --git a/examples/grpcclient/go.sum b/examples/grpcclient/go.sum old mode 100644 new mode 100755 diff --git a/examples/grpcclient/json/account_with_local_auth.json b/examples/grpcclient/json/account_with_local_auth.json old mode 100644 new mode 100755 diff --git a/examples/grpcclient/main.go b/examples/grpcclient/main.go old mode 100644 new mode 100755 diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 index cb76cc7..7ecaf26 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/google/uuid v1.3.0 github.com/gorilla/csrf v1.7.1 github.com/gorilla/mux v1.8.0 + github.com/lib/pq v1.3.0 github.com/mitchellh/mapstructure v1.5.0 github.com/ory/fosite v0.42.2 github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 index f5d754d..34603d7 --- a/go.sum +++ b/go.sum @@ -707,6 +707,7 @@ github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTRe github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/luna-duclos/instrumentedsql v0.0.0-20181127104832-b7d587d28109/go.mod h1:PWUIzhtavmOR965zfawVsHXbEuU1G29BPZ/CB3C7jXk= github.com/luna-duclos/instrumentedsql v1.1.2/go.mod h1:4LGbEqDnopzNAiyxPPDXhLspyunZxgPTMJBKtC6U0BQ= @@ -790,6 +791,9 @@ github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/oleiade/reflections v1.0.0/go.mod h1:RbATFBbKYkVdqmSFtx13Bb/tVhR0lgOBXunWTZKeL4w= +github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= +github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/grpcapi/README.md b/grpcapi/README.md old mode 100644 new mode 100755 diff --git a/grpcapi/accounts.go b/grpcapi/accounts.go old mode 100644 new mode 100755 diff --git a/grpcapi/accounts.pb.go b/grpcapi/accounts.pb.go old mode 100644 new mode 100755 diff --git a/grpcapi/accounts.proto b/grpcapi/accounts.proto old mode 100644 new mode 100755 diff --git a/grpcapi/comasvc.pb.go b/grpcapi/comasvc.pb.go old mode 100644 new mode 100755 diff --git a/grpcapi/comasvc.proto b/grpcapi/comasvc.proto old mode 100644 new mode 100755 diff --git a/grpcapi/comasvc_grpc.pb.go b/grpcapi/comasvc_grpc.pb.go old mode 100644 new mode 100755 diff --git a/grpcapi/grpcapi.go b/grpcapi/grpcapi.go old mode 100644 new mode 100755 diff --git a/handlers/accounts.go b/handlers/accounts.go old mode 100644 new mode 100755 diff --git a/handlers/handlers.go b/handlers/handlers.go old mode 100644 new mode 100755 diff --git a/main.go b/main.go old mode 100644 new mode 100755 diff --git a/oidc-provider/endpoints_auth.go b/oidc-provider/endpoints_auth.go old mode 100644 new mode 100755 diff --git a/oidc-provider/endpoints_introspection.go b/oidc-provider/endpoints_introspection.go old mode 100644 new mode 100755 diff --git a/oidc-provider/endpoints_token.go b/oidc-provider/endpoints_token.go old mode 100644 new mode 100755 diff --git a/oidc-provider/endpoints_userinfo.go b/oidc-provider/endpoints_userinfo.go old mode 100644 new mode 100755 diff --git a/oidc-provider/endpoints_wellknown.go b/oidc-provider/endpoints_wellknown.go old mode 100644 new mode 100755 diff --git a/oidc-provider/fosite.go b/oidc-provider/fosite.go old mode 100644 new mode 100755 diff --git a/oidc-provider/oidc-provider.go b/oidc-provider/oidc-provider.go old mode 100644 new mode 100755 diff --git a/oidc-provider/server.go b/oidc-provider/server.go old mode 100644 new mode 100755 diff --git a/oidc-provider/templates/default/auth.html b/oidc-provider/templates/default/auth.html old mode 100644 new mode 100755 diff --git a/oidc-provider/templates/parcoursmob/auth.html b/oidc-provider/templates/parcoursmob/auth.html old mode 100644 new mode 100755 diff --git a/schemas/CMS/civil-status.schema.json b/schemas/CMS/civil-status.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/driving-licence.schema.json b/schemas/CMS/driving-licence.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/favorites.schema.json b/schemas/CMS/favorites.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/fr-caf-information.schema.json b/schemas/CMS/fr-caf-information.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/fr-dgfip-information.schema.json b/schemas/CMS/fr-dgfip-information.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/fr-mesri-information.schema.json b/schemas/CMS/fr-mesri-information.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/in-case-of-emergency-contacts.schema.json b/schemas/CMS/in-case-of-emergency-contacts.schema.json old mode 100644 new mode 100755 diff --git a/schemas/CMS/personal-information.schema.json b/schemas/CMS/personal-information.schema.json old mode 100644 new mode 100755 diff --git a/storage/accounts.go b/storage/accounts.go old mode 100644 new mode 100755 diff --git a/storage/etcd.go b/storage/etcd.go old mode 100644 new mode 100755 diff --git a/storage/mongodb.go b/storage/mongodb.go old mode 100644 new mode 100755 diff --git a/storage/postgresql.go b/storage/postgresql.go new file mode 100644 index 0000000..d926830 --- /dev/null +++ b/storage/postgresql.go @@ -0,0 +1,63 @@ +package storage + +import ( + "database/sql" + "fmt" + _ "github.com/lib/pq" + "github.com/spf13/viper" + "strconv" +) + +type PostgresqlStorage struct { + DbConnection *sql.DB +} + +func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) { + var ( + host = cfg.GetString("storage.db.psql.host") + port = cfg.GetString("storage.db.psql.port") + user = cfg.GetString("storage.db.psql.user") + password = cfg.GetString("storage.db.psql.password") + dbname = cfg.GetString("storage.db.psql.dbname") + ) + portInt, _ := strconv.Atoi(port) + psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, portInt, + user, password, dbname) + db, err := sql.Open("postgres", psqlconn) + if err != nil { + fmt.Println("error", err) + return PostgresqlStorage{}, fmt.Errorf("connection to postgresql failed") + } + defer db.Close() + err = db.Ping() + if err != nil { + return PostgresqlStorage{}, fmt.Errorf("connection to postgresql database failed") + } + return PostgresqlStorage{ + DbConnection: db, + }, nil +} + +func (PostgresqlStorage) GetAccount(id string) (*Account, error) { + return nil, fmt.Errorf("") +} + +func (PostgresqlStorage) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) { + return nil, fmt.Errorf("") +} + +func (PostgresqlStorage) GetAccounts(namespaces []string) ([]Account, error) { + return nil, fmt.Errorf("") +} + +func (PostgresqlStorage) GetAccountsByIds(accountids []string) ([]Account, error) { + return nil, fmt.Errorf("") +} + +func (PostgresqlStorage) CreateAccount(account Account) error { + return fmt.Errorf("") +} + +func (PostgresqlStorage) UpdateAccount(account Account) error { + return fmt.Errorf("") +} diff --git a/storage/postgresql_test.go b/storage/postgresql_test.go new file mode 100644 index 0000000..52a0106 --- /dev/null +++ b/storage/postgresql_test.go @@ -0,0 +1,21 @@ +package storage + +import ( + "github.com/spf13/viper" + "testing" +) + +func TestNewPostgresqlStorage(t *testing.T) { + cfg := viper.New() + cfg.Set("storage.db.psql.host", "localhost") + cfg.Set("storage.db.psql.port", "5432") + cfg.Set("storage.db.psql.user", "postgres") + cfg.Set("storage.db.psql.password", "postgres") + cfg.Set("storage.db.psql.dbname", "mobilityaccounts") + + storage, err := NewPostgresqlStorage(cfg) + if err != nil { + t.Errorf("error creating new PostgreSQL storage: %v", err) + } + defer storage.DbConnection.Close() +} diff --git a/storage/storage.go b/storage/storage.go old mode 100644 new mode 100755 index f42331d..297221f --- a/storage/storage.go +++ b/storage/storage.go @@ -46,6 +46,9 @@ func NewDBStorage(cfg *viper.Viper) (DBStorage, error) { case "mongodb": s, err := NewMongoDBStorage(cfg) return s, err + case "psql": + s, err := NewPostgresqlStorage(cfg) + return s, err default: return nil, fmt.Errorf("storage type %v is not supported", storage_type) }