Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GOATS-auth] add auth service #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_PASS = 1111
DB_USER = postgres
DB_NAME = Netflix
DB_HOST = localhost
DB_PORT = 5432
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/validation-service/bin/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/2024_2_GOATS.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.22.2

WORKDIR /

COPY . ./app

WORKDIR /app

RUN go mod download
RUN go mod tidy
RUN go build cmd/main.go

EXPOSE 8081

CMD [ "main" ]

# /app/
# /api
# /cmd
#...
5 changes: 5 additions & 0 deletions auth-service/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_PASS = 1111
DB_USER = postgres
DB_NAME = Netflix
DB_HOST = localhost
DB_PORT = 5432
45 changes: 45 additions & 0 deletions auth-service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include .env
export

LOCAL_BIN:=$(CURDIR)/bin

MIGRATION_FOLDER=$(CURDIR)/internal/pkg/database/migrations

install-deps:
GOBIN=$(LOCAL_BIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
GOBIN=$(LOCAL_BIN) go install -mod=mod google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
GOBIN=$(LOCAL_BIN) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.15.2

get-deps:
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway

generate:
make install-deps
make get-deps
make generate-auth-api

generate-auth-api:
mkdir -p internal/pb/auth
protoc --proto_path api/auth --proto_path vendor.protogen \
--proto_path=vendor.protogen/google \
--go_out=internal/pb/auth --go_opt=paths=source_relative \
--plugin=protoc-gen-go=bin/protoc-gen-go \
--go-grpc_out=internal/pb/auth --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=bin/protoc-gen-go-grpc \
--grpc-gateway_out=internal/pb/auth --grpc-gateway_opt=paths=source_relative \
--plugin=protoc-gen-grpc-gateway=bin/protoc-gen-grpc-gateway \
api/auth/auth.proto

vendor-proto:
@if [ ! -d vendor.protogen/google ]; then \
git clone https://github.com/googleapis/googleapis vendor.protogen/googleapis &&\
mkdir -p vendor.protogen/google/ &&\
mv vendor.protogen/googleapis/google/api vendor.protogen/google &&\
rm -rf vendor.protogen/googleapis ;\
fi

.PHONY: migration-up
migration-up:
goose -dir "$(MIGRATION_FOLDER)" postgres "user=$(DB_USER) password=$(DB_PASS) dbname=$(DB_NAME) host=$(DB_HOST) port=$(DB_PORT) sslmode=disable" up
58 changes: 58 additions & 0 deletions auth-service/api/auth/auth.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";

package auth;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";

option go_package = ".";

service Auth {
rpc Register(RegisterRequest) returns (AuthResponse) {
option (google.api.http) = {
post: "/register"
body: "*"
};
}
rpc Login(AuthRequest) returns (AuthResponse) {
option (google.api.http) = {
post: "/login"
body: "*"
};
}
rpc Logout(LogoutRequest) returns (AuthResponse) {
option (google.api.http) = {
post: "/logout"
body: "*"
};
}
}

message RegisterRequest {
string email = 1;
string password = 2;
string password_confirm = 3; // Может быть пустым
string nickname = 4;
string sex = 5;
google.protobuf.Timestamp birthdate = 6;
}

message LogoutRequest {
string email = 1;
}

message AuthRequest {
string email = 1;
string password = 2;
}

message ErrorMessage {
string code = 1;
string error = 2;
}

message AuthResponse {
bool success = 1;
repeated ErrorMessage errors = 2;
}
Binary file added auth-service/bin/protoc-gen-go
Binary file not shown.
Binary file added auth-service/bin/protoc-gen-go-grpc
Binary file not shown.
Binary file added auth-service/bin/protoc-gen-grpc-gateway
Binary file not shown.
21 changes: 21 additions & 0 deletions auth-service/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"context"
"log"

"github.com/go-park-mail-ru/2024_2_GOATS/internal/app"
)

func main() {
ctx := context.Background()

a, authImpl, err := app.New(ctx)
if err != nil {
log.Fatalf("can't create app: %s", err)
}

if err = a.Run(ctx, authImpl); err != nil {
log.Fatalf("can't run app: %s", err)
}
}
36 changes: 36 additions & 0 deletions auth-service/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module github.com/go-park-mail-ru/2024_2_GOATS

go 1.22.2

require (
github.com/georgysavva/scany v1.2.2
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgx/v4 v4.18.3
github.com/redis/go-redis/v9 v9.6.1
golang.org/x/crypto v0.26.0
google.golang.org/genproto/googleapis/api v0.0.0-20240924160255-9d4c2d233b61
google.golang.org/grpc v1.67.0
google.golang.org/protobuf v1.34.2
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading