Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
106 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package constants | ||
|
||
const ( | ||
MIMEApplicationJSON = "application/json" | ||
MIMEApplicationProtobuf = "application/protobuf" | ||
MIMEOctetStream = "application/octet-stream" | ||
MIMEApplicationForm = "application/x-www-form-urlencoded" | ||
MIMEMultipartForm = "multipart/form-data" | ||
MIMETextEventStream = "text/event-stream" | ||
MIMETextPlain = "text/plain" | ||
MIMETextHTML = "text/html" | ||
MIMEKeepAlive = "keep-alive" | ||
) | ||
|
||
const ( | ||
HeaderAuthorization = "Authorization" | ||
HeaderCacheControl = "Cache-Control" | ||
) | ||
|
||
const ( | ||
XMSAPIKey = "X-MS-Api-Key" | ||
XMSProvider = "X-MS-Provider" | ||
XMSConfig = "X-MS-Config" | ||
XMSCache = "X-MS-Cache" | ||
XMSRequestId = "X-MS-Request-Id" | ||
XMSTraceId = "X-MS-Trace-Id" | ||
XMSRetryCount = "X-MS-Retry-count" | ||
) | ||
|
||
const ( | ||
XMSRetryAttemptCount = "X-MS-Retry-Attempt-count" | ||
XMSCacheStatus = "X-MS-Cache-Status" | ||
) |
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,16 @@ | ||
package errors | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/missingstudio/studio/backend/internal/constants" | ||
"github.com/missingstudio/studio/common/errors" | ||
) | ||
|
||
var ( | ||
ErrProviderHeaderNotExit = errors.NewBadRequest(fmt.Sprintf("%s header is required", constants.XMSProvider)) | ||
ErrRequiredHeaderNotExit = errors.NewBadRequest(fmt.Sprintf("either %s or %s header is required", constants.XMSProvider, constants.XMSConfig)) | ||
ErrRateLimitExceeded = errors.NewForbidden("rate limit exceeded") | ||
ErrUnauthenticated = errors.NewUnauthorized("unauthenticated") | ||
ErrProviderNotFound = errors.NewNotFound("provider is not found") | ||
) |
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,35 @@ | ||
package interceptor | ||
|
||
import ( | ||
"context" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/missingstudio/studio/backend/internal/constants" | ||
"github.com/missingstudio/studio/backend/internal/errors" | ||
"github.com/missingstudio/studio/backend/internal/providers" | ||
) | ||
|
||
func ProviderInterceptor() connect.UnaryInterceptorFunc { | ||
interceptor := func(next connect.UnaryFunc) connect.UnaryFunc { | ||
return connect.UnaryFunc(func( | ||
ctx context.Context, | ||
req connect.AnyRequest, | ||
) (connect.AnyResponse, error) { | ||
// Check if required headers are available | ||
provider := req.Header().Get(constants.XMSProvider) | ||
config := req.Header().Get(constants.XMSConfig) | ||
if provider == "" || config == "" { | ||
return nil, errors.ErrRequiredHeaderNotExit | ||
} | ||
|
||
// Check if provider has registered of not | ||
_, ok := providers.ProviderFactories[provider] | ||
if !ok { | ||
return nil, errors.ErrProviderNotFound | ||
} | ||
|
||
return next(ctx, req) | ||
}) | ||
} | ||
return connect.UnaryInterceptorFunc(interceptor) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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