psql first commit

This commit is contained in:
root 2023-04-25 15:14:42 +03:00
parent c96b6ed943
commit 15ab461a5e
49 changed files with 110 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="Go" enabled="true" />
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

0
Dockerfile Normal file → Executable file
View File

0
LICENCE.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
config.go Normal file → Executable file
View File

0
examples/grpcclient/README.md Normal file → Executable file
View File

0
examples/grpcclient/go.mod Normal file → Executable file
View File

0
examples/grpcclient/go.sum Normal file → Executable file
View File

0
examples/grpcclient/json/account_with_local_auth.json Normal file → Executable file
View File

0
examples/grpcclient/main.go Normal file → Executable file
View File

1
go.mod Normal file → Executable file
View File

@ -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

4
go.sum Normal file → Executable file
View File

@ -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=

0
grpcapi/README.md Normal file → Executable file
View File

0
grpcapi/accounts.go Normal file → Executable file
View File

0
grpcapi/accounts.pb.go Normal file → Executable file
View File

0
grpcapi/accounts.proto Normal file → Executable file
View File

0
grpcapi/comasvc.pb.go Normal file → Executable file
View File

0
grpcapi/comasvc.proto Normal file → Executable file
View File

0
grpcapi/comasvc_grpc.pb.go Normal file → Executable file
View File

0
grpcapi/grpcapi.go Normal file → Executable file
View File

0
handlers/accounts.go Normal file → Executable file
View File

0
handlers/handlers.go Normal file → Executable file
View File

0
main.go Normal file → Executable file
View File

0
oidc-provider/endpoints_auth.go Normal file → Executable file
View File

0
oidc-provider/endpoints_introspection.go Normal file → Executable file
View File

0
oidc-provider/endpoints_token.go Normal file → Executable file
View File

0
oidc-provider/endpoints_userinfo.go Normal file → Executable file
View File

0
oidc-provider/endpoints_wellknown.go Normal file → Executable file
View File

0
oidc-provider/fosite.go Normal file → Executable file
View File

0
oidc-provider/oidc-provider.go Normal file → Executable file
View File

0
oidc-provider/server.go Normal file → Executable file
View File

0
oidc-provider/templates/default/auth.html Normal file → Executable file
View File

0
oidc-provider/templates/parcoursmob/auth.html Normal file → Executable file
View File

0
schemas/CMS/civil-status.schema.json Normal file → Executable file
View File

0
schemas/CMS/driving-licence.schema.json Normal file → Executable file
View File

0
schemas/CMS/favorites.schema.json Normal file → Executable file
View File

0
schemas/CMS/fr-caf-information.schema.json Normal file → Executable file
View File

0
schemas/CMS/fr-dgfip-information.schema.json Normal file → Executable file
View File

0
schemas/CMS/fr-mesri-information.schema.json Normal file → Executable file
View File

0
schemas/CMS/in-case-of-emergency-contacts.schema.json Normal file → Executable file
View File

0
schemas/CMS/personal-information.schema.json Normal file → Executable file
View File

0
storage/accounts.go Normal file → Executable file
View File

0
storage/etcd.go Normal file → Executable file
View File

0
storage/mongodb.go Normal file → Executable file
View File

63
storage/postgresql.go Normal file
View File

@ -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("")
}

View File

@ -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()
}

3
storage/storage.go Normal file → Executable file
View File

@ -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)
}