Skip to content

Commit

Permalink
auth added
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillmc committed Apr 18, 2024
1 parent a1f6b30 commit c127cbf
Show file tree
Hide file tree
Showing 78 changed files with 4,509 additions and 4,312 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ generate-user-api:

generate-auth-api:
mkdir -p pkg/auth_v1
protoc --proto_path api/auth_v1 \
protoc --proto_path api/auth_v1 --proto_path vendor.protogen \
--go_out=pkg/auth_v1 --go_opt=paths=source_relative \
--plugin=protoc-gen-go=$(LOCAL_BIN)/protoc-gen-go \
--go-grpc_out=pkg/auth_v1 --go-grpc_opt=paths=source_relative \
--plugin=protoc-gen-go-grpc=$(LOCAL_BIN)/protoc-gen-go-grpc \
--validate_out lang=go:pkg/auth_v1 --validate_opt=paths=source_relative \
--plugin=protoc-gen-validate=$(LOCAL_BIN)/protoc-gen-validate \
--grpc-gateway_out=pkg/auth_v1 --grpc-gateway_opt=paths=source_relative \
--plugin=protoc-gen-grpc-gateway=$(LOCAL_BIN)/protoc-gen-grpc-gateway \
--openapiv2_out=allow_merge=true,merge_file_name=api_auth:pkg/swagger \
--plugin=protoc-gen-openapiv2=$(LOCAL_BIN)/protoc-gen-openapiv2 \
api/auth_v1/auth.proto

generate-access-api:
Expand Down
48 changes: 43 additions & 5 deletions api/auth_v1/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,55 @@ syntax = "proto3";

package auth_v1;

import "google/api/annotations.proto";
import "validate/validate.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "github.com/kirillmc/trainings-auth/pkg/auth_v1;auth_v1";

option(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info:{
title:"Auth API",
version:"1.0.0",
contact:{
name:"Telegram",
email:"https://t.me/McK03"
};
};

host:"localhost:8081",
schemes:HTTP,
schemes:HTTPS,
consumes:"application/json",
produces:"application/json",
};

service AuthV1{
rpc Login(LoginRequest) returns (LoginResponse);
rpc GetRefreshToken(GetRefreshTokenRequest) returns (GetRefreshTokenResponse);
rpc GetAccessToken(GetAccessTokenRequest) returns (GetAccessTokenResponse);
rpc Login(LoginRequest) returns (LoginResponse){
option(google.api.http) = {
post: "/login"
body:"*"
};
}

rpc GetRefreshToken(GetRefreshTokenRequest) returns (GetRefreshTokenResponse){
option(google.api.http) = {
post: "/get-refresh-token"
body:"*"
};
}

rpc GetAccessToken(GetAccessTokenRequest) returns (GetAccessTokenResponse){
option(google.api.http) = {
post: "/get-access-token"
body:"*"
};
}
}

message LoginRequest{
string username = 1;
string password = 2;
string login = 1[(validate.rules).string = {min_len:1,max_len:50}];
string password = 2[(validate.rules).string = {pattern:"^[A-Za-z0-9]*$",min_len:8, max_len:50}];
}

message LoginResponse{
Expand Down
80 changes: 66 additions & 14 deletions api/user_v1/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package user_v1;

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";
import "validate/validate.proto";
Expand All @@ -13,7 +12,7 @@ option go_package = "github.com/kirillmc/trainings-auth/pkg/user_v1;user_v1";

option(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info:{
title:"Auth API",
title:"Create User API",
version:"1.0.0",
contact:{
name:"Telegram",
Expand Down Expand Up @@ -51,6 +50,33 @@ service UserV1{
};
}

rpc UpdatePassword(UpdatePasswordRequest) returns (google.protobuf.Empty){
option(google.api.http) = {
patch:"/update-password"
body:"*"
};
}
rpc UpdateRole(UpdateRoleRequest) returns (google.protobuf.Empty){
option(google.api.http) = {
patch:"/update-role"
body:"*"
};
}

rpc LockUser(LockUserRequest) returns (google.protobuf.Empty){
option(google.api.http) = {
patch:"/lock-user"
body:"*"
};
}

rpc UnlockUser(UnlockUserRequest) returns (google.protobuf.Empty){
option(google.api.http) = {
patch:"/unlock-user"
body:"*"
};
}

rpc Delete(DeleteRequest) returns (google.protobuf.Empty){
option(google.api.http) = {
delete:"/user"
Expand All @@ -61,8 +87,8 @@ service UserV1{
enum Role{
UNKNOWN = 0;
USER = 1;
ADMIN = 2;
MODER = 3;
MODER = 2;
ADMIN = 3;
}

message UserInfo{
Expand All @@ -79,21 +105,28 @@ message UserInfo{
message UpdateUserInfo{
google.protobuf.StringValue login = 1[(validate.rules).string = {min_len:1,max_len:50}];
google.protobuf.StringValue email = 2[(validate.rules).string = {email:true, max_len:50}];
google.protobuf.StringValue password = 3[(validate.rules).string = {pattern:"^[A-Za-z0-9]*$",min_len:8, max_len:50}];
google.protobuf.StringValue password_confirm = 4[(validate.rules).string = {pattern:"^[A-Za-z0-9]*$",min_len:8, max_len:50}];
Role role = 5[(validate.rules).enum.defined_only = true];
google.protobuf.StringValue name = 6;
google.protobuf.StringValue surname = 7;
google.protobuf.StringValue avatar = 8;
google.protobuf.StringValue name = 3;
google.protobuf.StringValue surname = 4;
google.protobuf.StringValue avatar = 5;
}

message UpdatePasswordInfo{
google.protobuf.StringValue password = 1[(validate.rules).string = {pattern:"^[A-Za-z0-9]*$",min_len:8, max_len:50}];
google.protobuf.StringValue password_confirm = 2[(validate.rules).string = {pattern:"^[A-Za-z0-9]*$",min_len:8, max_len:50}];
}

message User{
int64 id = 1;
UserInfo info = 2;
string login = 1[(validate.rules).string = {min_len:1,max_len:50}];
string email = 2[(validate.rules).string = {email:true, max_len:50}];
Role role = 3[(validate.rules).enum.defined_only = true];
string name = 4;
string surname = 5;
string avatar = 6;
bool isLocked = 7;
}

message CreateRequest{
User user = 1;
UserInfo user = 1;
}

message CreateResponse{
Expand All @@ -105,14 +138,33 @@ message GetRequest{
}

message GetResponse{
User user = 1;
int64 id = 1;
User user = 2;
}

message UpdateRequest{
int64 id = 1;
UpdateUserInfo info = 2;
}

message UpdatePasswordRequest{
int64 user_id = 1;
UpdatePasswordInfo info = 2;
}

message UpdateRoleRequest{
int64 user_id = 1;
Role role = 2[(validate.rules).enum.defined_only = true];
}

message LockUserRequest{
int64 user_to_lock_id = 1;
}

message UnlockUserRequest{
int64 user_to_unlock_id = 1;
}

message DeleteRequest{
int64 id = 1;
}
2 changes: 1 addition & 1 deletion cmd/grpc_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"log"

"github.com/kirillmc/auth/internal/app"
"github.com/kirillmc/trainings-auth/internal/app"
)

func main() {
Expand Down
36 changes: 34 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ module github.com/kirillmc/trainings-auth
go 1.21

require (
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/Masterminds/squirrel v1.5.4
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/joho/godotenv v1.5.1
github.com/kirillmc/platform_common v0.0.0-20240409070039-be2988157a23
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/rs/cors v1.10.1
golang.org/x/crypto v0.19.0
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.0
google.golang.org/protobuf v1.33.0
)

require (
github.com/georgysavva/scany v1.2.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.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.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
)

0 comments on commit c127cbf

Please sign in to comment.