-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from solumD/Task-6
Task 6
- Loading branch information
Showing
123 changed files
with
349 additions
and
19,436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
/bin//coverage.out | ||
/bin | ||
/coverage.out | ||
/tls/ | ||
/vendor.protogen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[req] | ||
default_bits = 4096 | ||
prompt = no | ||
default_md = sha256 | ||
req_extensions = req_ext | ||
distinguished_name = dn | ||
[dn] | ||
C = RU | ||
ST = Moscow | ||
O = Solum INC. | ||
CN = localhost | ||
[req_ext] | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = localhost | ||
IP.1 = ::1 | ||
IP.2 = 127.0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/solumD/auth/pkg/access_v1" | ||
) | ||
|
||
// Client интерфейс клиента auth | ||
type Client interface { | ||
Check(ctx context.Context, endpoint string) error | ||
} | ||
|
||
type client struct { | ||
accessClient access_v1.AccessV1Client | ||
} | ||
|
||
// New возвращает новый объект клиента auth | ||
func New(accessClient access_v1.AccessV1Client) Client { | ||
return &client{ | ||
accessClient: accessClient, | ||
} | ||
} | ||
|
||
// Check отправляет запрос в сервис auth на проверкку доступа | ||
func (c *client) Check(ctx context.Context, endpoint string) error { | ||
req := &access_v1.CheckRequest{ | ||
EndpointAddress: endpoint, | ||
} | ||
|
||
if _, err := c.accessClient.Check(ctx, req); err != nil { | ||
return fmt.Errorf("access check error: %v", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"net" | ||
"os" | ||
) | ||
|
||
const ( | ||
authGrpcHostEnvName = "AUTH_GRPC_HOST" | ||
authGrpcPortEnvName = "AUTH_GRPC_PORT" | ||
authCertPathEnvName = "CERT_PATH" | ||
) | ||
|
||
type authConfig struct { | ||
host string | ||
port string | ||
certPath string | ||
} | ||
|
||
// NewAuthConfig returns new auth client config | ||
func NewAuthConfig() (AuthConfig, error) { | ||
host := os.Getenv(authGrpcHostEnvName) | ||
if len(host) == 0 { | ||
return nil, errors.New("auth client host not found") | ||
} | ||
|
||
port := os.Getenv(authGrpcPortEnvName) | ||
if len(port) == 0 { | ||
return nil, errors.New("auth client port not found") | ||
} | ||
|
||
certPath := os.Getenv(authCertPathEnvName) | ||
if len(certPath) == 0 { | ||
return nil, errors.New("cert path not found") | ||
} | ||
|
||
return &authConfig{ | ||
host: host, | ||
port: port, | ||
certPath: certPath, | ||
}, nil | ||
} | ||
|
||
// Address returns a full address of a auth client | ||
func (cfg *authConfig) Address() string { | ||
return net.JoinHostPort(cfg.host, cfg.port) | ||
} | ||
|
||
func (cfg *authConfig) CertPath() string { | ||
return cfg.certPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package interceptor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/solumD/chat-server/internal/client/auth" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/metadata" | ||
) | ||
|
||
type authInterceptor struct { | ||
authClient auth.Client | ||
} | ||
|
||
// NewAuthInterceptor возвращает структуру интерцептора auth | ||
func NewAuthInterceptor(authClient auth.Client) *authInterceptor { | ||
return &authInterceptor{ | ||
authClient: authClient, | ||
} | ||
} | ||
|
||
// Get возвращает интерцептор, который делает запрос к сервису auth | ||
func (i *authInterceptor) Get() grpc.UnaryServerInterceptor { | ||
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { | ||
md, ok := metadata.FromIncomingContext(ctx) | ||
if ok { | ||
ctx = metadata.NewOutgoingContext(ctx, md) | ||
} | ||
|
||
if err = i.authClient.Check(ctx, info.FullMethod); err != nil { | ||
return nil, err | ||
} | ||
|
||
return handler(ctx, req) | ||
} | ||
} |
Oops, something went wrong.