Skip to content

Commit

Permalink
Enabling code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Archisman-Mridha committed Jan 13, 2024
1 parent ed70826 commit 0985e2e
Show file tree
Hide file tree
Showing 98 changed files with 7,326 additions and 4,803 deletions.
31 changes: 31 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "gomod"
directory: "/backend/gateway"
schedule:
interval: "weekly"

- package-ecosystem: "gomod"
directory: "/kubernetes/operators/application"
schedule:
interval: "weekly"

- package-ecosystem: "npm"
directory: "/frontend"
schedule:
interval: "weekly"

- package-ecosystem: "terraform"
directory: "/cloud"
schedule:
interval: "weekly"
10 changes: 5 additions & 5 deletions backend/gateway/authentication_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ func authenticationMiddleware(next http.Handler) http.Handler {

jwt, err := utils.ExtractJwtFromAuthorizationHeader(authorizationHeader)
if err != nil {
http.Error(w, err.Error( ), http.StatusBadRequest)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// TODO: Add a timeout.
response, err := usersMicroserviceConnector.VerifyJwt(context.Background( ),
&grpc_generated.VerifyJwtRequest{ Jwt: jwt })
response, err := usersMicroserviceConnector.VerifyJwt(context.Background(),
&grpc_generated.VerifyJwtRequest{Jwt: jwt})
if err != nil {
http.Error(w, "server error occurred", http.StatusInternalServerError)
return
}

// Add the user-id in context.
ctx := context.WithValue(r.Context( ), utils.USER_ID_CONTEXT_KEY, response.UserId)
ctx := context.WithValue(r.Context(), utils.USER_ID_CONTEXT_KEY, response.UserId)
r = r.WithContext(ctx)

next.ServeHTTP(w, r)
})
}
}
13 changes: 7 additions & 6 deletions backend/gateway/connectors/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
)

type Connector interface {
Healthcheck( ) error
Healthcheck() error

Disconnect( )
Disconnect()
}

func createGrpcConnection(serviceName, address string) *grpc.ClientConn {
connection, err := grpc.Dial(address,
grpc.WithTransportCredentials(insecure.NewCredentials( )),
grpc.WithStatsHandler(otelgrpc.NewClientHandler( )),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
)
if err != nil {
log.Fatalf("Couldn't connect to %s at %s : %v", serviceName, address, err)}
log.Fatalf("Couldn't connect to %s at %s : %v", serviceName, address, err)
}

return connection
}
}
35 changes: 19 additions & 16 deletions backend/gateway/connectors/feeds_microservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ type FeedsMicroserviceConnector struct {
grpcConnection *grpc.ClientConn
}

func NewFeedsMicroserviceConnector( ) *FeedsMicroserviceConnector {
u := &FeedsMicroserviceConnector {
func NewFeedsMicroserviceConnector() *FeedsMicroserviceConnector {
u := &FeedsMicroserviceConnector{
serviceName: "feeds microservice",
address: utils.Envs.FEEDS_MICROSERVICE_URL,
address: utils.Envs.FEEDS_MICROSERVICE_URL,
}

u.grpcConnection= createGrpcConnection(u.serviceName, u.address)
u.FeedsServiceClient= grpc_generated.NewFeedsServiceClient(u.grpcConnection)
u.grpcConnection = createGrpcConnection(u.serviceName, u.address)
u.FeedsServiceClient = grpc_generated.NewFeedsServiceClient(u.grpcConnection)

if err := u.Healthcheck( ); err != nil {
log.Fatalf("Couldn't connect to feeds microservice : %v", err)}
if err := u.Healthcheck(); err != nil {
log.Fatalf("Couldn't connect to feeds microservice : %v", err)
}

log.Debugf("Connected to %s", u.serviceName)

return u
}

func(u *FeedsMicroserviceConnector) Healthcheck( ) error {
ctx, cancel := context.WithTimeout(context.Background( ), 5 * time.Second)
defer cancel( )
func (u *FeedsMicroserviceConnector) Healthcheck() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if _, err := u.Ping(ctx, &emptypb.Empty{ }); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)}
if _, err := u.Ping(ctx, &emptypb.Empty{}); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)
}

return nil
}

func(u *FeedsMicroserviceConnector) Disconnect( ) {
if err := u.grpcConnection.Close( ); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)}
func (u *FeedsMicroserviceConnector) Disconnect() {
if err := u.grpcConnection.Close(); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)
}

log.Debugf("Closed connection to %s", u.serviceName)
}
}
35 changes: 19 additions & 16 deletions backend/gateway/connectors/followships_microservice_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ type FollowshipsMicroserviceConnector struct {
grpcConnection *grpc.ClientConn
}

func NewFollowshipsMicroserviceConnector( ) *FollowshipsMicroserviceConnector {
u := &FollowshipsMicroserviceConnector {
func NewFollowshipsMicroserviceConnector() *FollowshipsMicroserviceConnector {
u := &FollowshipsMicroserviceConnector{
serviceName: "followships microservice",
address: utils.Envs.FOLLOWSHIPS_MICROSERVICE_URL,
address: utils.Envs.FOLLOWSHIPS_MICROSERVICE_URL,
}

u.grpcConnection= createGrpcConnection(u.serviceName, u.address)
u.FollowshipsServiceClient= grpc_generated.NewFollowshipsServiceClient(u.grpcConnection)
u.grpcConnection = createGrpcConnection(u.serviceName, u.address)
u.FollowshipsServiceClient = grpc_generated.NewFollowshipsServiceClient(u.grpcConnection)

if err := u.Healthcheck( ); err != nil {
log.Fatalf("Couldn't connect to followships microservice : %v", err)}
if err := u.Healthcheck(); err != nil {
log.Fatalf("Couldn't connect to followships microservice : %v", err)
}

log.Debugf("Connected to %s", u.serviceName)

return u
}

func(u *FollowshipsMicroserviceConnector) Healthcheck( ) error {
ctx, cancel := context.WithTimeout(context.Background( ), 5 * time.Second)
defer cancel( )
func (u *FollowshipsMicroserviceConnector) Healthcheck() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if _, err := u.Ping(ctx, &emptypb.Empty{ }); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)}
if _, err := u.Ping(ctx, &emptypb.Empty{}); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)
}

return nil
}

func(u *FollowshipsMicroserviceConnector) Disconnect( ) {
if err := u.grpcConnection.Close( ); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)}
func (u *FollowshipsMicroserviceConnector) Disconnect() {
if err := u.grpcConnection.Close(); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)
}

log.Debugf("Closed connection to %s", u.serviceName)
}
}
35 changes: 19 additions & 16 deletions backend/gateway/connectors/posts_microservice_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ type PostsMicroserviceConnector struct {
grpcConnection *grpc.ClientConn
}

func NewPostsMicroserviceConnector( ) *PostsMicroserviceConnector {
u := &PostsMicroserviceConnector {
func NewPostsMicroserviceConnector() *PostsMicroserviceConnector {
u := &PostsMicroserviceConnector{
serviceName: "posts microservice",
address: utils.Envs.POSTS_MICROSERVICE_URL,
address: utils.Envs.POSTS_MICROSERVICE_URL,
}

u.grpcConnection= createGrpcConnection(u.serviceName, u.address)
u.PostsServiceClient= grpc_generated.NewPostsServiceClient(u.grpcConnection)
u.grpcConnection = createGrpcConnection(u.serviceName, u.address)
u.PostsServiceClient = grpc_generated.NewPostsServiceClient(u.grpcConnection)

if err := u.Healthcheck( ); err != nil {
log.Fatalf("Couldn't connect to posts microservice : %v", err)}
if err := u.Healthcheck(); err != nil {
log.Fatalf("Couldn't connect to posts microservice : %v", err)
}

log.Debugf("Connected to %s", u.serviceName)

return u
}

func(u *PostsMicroserviceConnector) Healthcheck( ) error {
ctx, cancel := context.WithTimeout(context.Background( ), 5 * time.Second)
defer cancel( )
func (u *PostsMicroserviceConnector) Healthcheck() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if _, err := u.Ping(ctx, &emptypb.Empty{ }); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)}
if _, err := u.Ping(ctx, &emptypb.Empty{}); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)
}

return nil
}

func(u *PostsMicroserviceConnector) Disconnect( ) {
if err := u.grpcConnection.Close( ); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)}
func (u *PostsMicroserviceConnector) Disconnect() {
if err := u.grpcConnection.Close(); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)
}

log.Debugf("Closed connection to %s", u.serviceName)
}
}
35 changes: 19 additions & 16 deletions backend/gateway/connectors/profiles_microservice_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ type ProfilesMicroserviceConnector struct {
grpcConnection *grpc.ClientConn
}

func NewProfilesMicroserviceConnector( ) *ProfilesMicroserviceConnector {
u := &ProfilesMicroserviceConnector {
func NewProfilesMicroserviceConnector() *ProfilesMicroserviceConnector {
u := &ProfilesMicroserviceConnector{
serviceName: "profiles microservice",
address: utils.Envs.PROFILES_MICROSERVICE_URL,
address: utils.Envs.PROFILES_MICROSERVICE_URL,
}

u.grpcConnection= createGrpcConnection(u.serviceName, u.address)
u.ProfilesServiceClient= grpc_generated.NewProfilesServiceClient(u.grpcConnection)
u.grpcConnection = createGrpcConnection(u.serviceName, u.address)
u.ProfilesServiceClient = grpc_generated.NewProfilesServiceClient(u.grpcConnection)

if err := u.Healthcheck( ); err != nil {
log.Fatalf("Couldn't connect to profiles microservice : %v", err)}
if err := u.Healthcheck(); err != nil {
log.Fatalf("Couldn't connect to profiles microservice : %v", err)
}

log.Debugf("Connected to %s", u.serviceName)

return u
}

func(u *ProfilesMicroserviceConnector) Healthcheck( ) error {
ctx, cancel := context.WithTimeout(context.Background( ), 5 * time.Second)
defer cancel( )
func (u *ProfilesMicroserviceConnector) Healthcheck() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if _, err := u.Ping(ctx, &emptypb.Empty{ }); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)}
if _, err := u.Ping(ctx, &emptypb.Empty{}); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)
}

return nil
}

func(u *ProfilesMicroserviceConnector) Disconnect( ) {
if err := u.grpcConnection.Close( ); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)}
func (u *ProfilesMicroserviceConnector) Disconnect() {
if err := u.grpcConnection.Close(); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)
}

log.Debugf("Closed connection to %s", u.serviceName)
}
}
35 changes: 19 additions & 16 deletions backend/gateway/connectors/users_microservice_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ type UsersMicroserviceConnector struct {
grpcConnection *grpc.ClientConn
}

func NewUsersMicroserviceConnector( ) *UsersMicroserviceConnector {
u := &UsersMicroserviceConnector {
func NewUsersMicroserviceConnector() *UsersMicroserviceConnector {
u := &UsersMicroserviceConnector{
serviceName: "users microservice",
address: utils.Envs.USERS_MICROSERVICE_URL,
address: utils.Envs.USERS_MICROSERVICE_URL,
}

u.grpcConnection= createGrpcConnection(u.serviceName, u.address)
u.UsersServiceClient= grpc_generated.NewUsersServiceClient(u.grpcConnection)
u.grpcConnection = createGrpcConnection(u.serviceName, u.address)
u.UsersServiceClient = grpc_generated.NewUsersServiceClient(u.grpcConnection)

if err := u.Healthcheck( ); err != nil {
log.Fatalf("Couldn't connect to users microservice : %v", err)}
if err := u.Healthcheck(); err != nil {
log.Fatalf("Couldn't connect to users microservice : %v", err)
}

log.Debugf("Connected to %s", u.serviceName)

return u
}

func(u *UsersMicroserviceConnector) Healthcheck( ) error {
ctx, cancel := context.WithTimeout(context.Background( ), 5 * time.Second)
defer cancel( )
func (u *UsersMicroserviceConnector) Healthcheck() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if _, err := u.Ping(ctx, &emptypb.Empty{ }); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)}
if _, err := u.Ping(ctx, &emptypb.Empty{}); err != nil {
return fmt.Errorf("error pinging %s: %v", u.serviceName, err)
}

return nil
}

func(u *UsersMicroserviceConnector) Disconnect( ) {
if err := u.grpcConnection.Close( ); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)}
func (u *UsersMicroserviceConnector) Disconnect() {
if err := u.grpcConnection.Close(); err != nil {
log.Errorf("Error closing connection to %s : %v", u.serviceName, err)
}

log.Debugf("Closed connection to %s", u.serviceName)
}
}
10 changes: 5 additions & 5 deletions backend/gateway/generated/graphql/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
// It serves as dependency injection for your app, add any dependencies you require here.

type Resolver struct {
UsersMicroservice *connectors.UsersMicroserviceConnector
ProfilesMicroservice *connectors.ProfilesMicroserviceConnector
UsersMicroservice *connectors.UsersMicroserviceConnector
ProfilesMicroservice *connectors.ProfilesMicroserviceConnector
FollowshipsMicroservice *connectors.FollowshipsMicroserviceConnector
PostsMicroservice *connectors.PostsMicroserviceConnector
FeedsMicroservice *connectors.FeedsMicroserviceConnector
PostsMicroservice *connectors.PostsMicroserviceConnector
FeedsMicroservice *connectors.FeedsMicroserviceConnector

Tracer trace.Tracer
}
}
Loading

0 comments on commit 0985e2e

Please sign in to comment.