Skip to content

Commit

Permalink
fix: refactor server package out of internal directory (#252)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <thekushsharma@gmail.com>
  • Loading branch information
kushsharma committed Jun 3, 2023
1 parent 9c83031 commit 09797ef
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cmd/serve.go
Expand Up @@ -10,6 +10,8 @@ import (
"syscall"
"time"

"github.com/odpf/shield/pkg/server/consts"

"github.com/odpf/shield/core/invitation"

"github.com/odpf/shield/pkg/mailer"
Expand All @@ -19,14 +21,12 @@ import (

"github.com/odpf/shield/core/deleter"

"github.com/odpf/shield/core/authenticate/session"
"github.com/odpf/shield/core/metaschema"
"github.com/odpf/shield/internal/server/consts"

_ "github.com/authzed/authzed-go/proto/authzed/api/v0"
_ "github.com/jackc/pgx/v4/stdlib"
newrelic "github.com/newrelic/go-agent"
"github.com/odpf/shield/core/authenticate"
"github.com/odpf/shield/core/authenticate/session"
"github.com/odpf/shield/core/metaschema"

"github.com/odpf/shield/config"
"github.com/odpf/shield/core/group"
Expand Down
5 changes: 3 additions & 2 deletions core/authenticate/registration_flow.go
Expand Up @@ -7,7 +7,8 @@ import (
"strings"
"time"

"github.com/odpf/shield/internal/bootstrap"
"github.com/odpf/shield/pkg/utils"

"github.com/odpf/shield/pkg/mailer"

"github.com/odpf/salt/log"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (r RegistrationService) SupportedStrategies() []string {
}

func (r RegistrationService) Start(ctx context.Context, request RegistrationStartRequest) (*RegistrationStartResponse, error) {
if !bootstrap.Contains(r.SupportedStrategies(), request.Method) {
if !utils.Contains(r.SupportedStrategies(), request.Method) {
return nil, ErrUnsupportedMethod
}
flow := &Flow{
Expand Down
2 changes: 1 addition & 1 deletion core/authenticate/session/service.go
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"time"

"github.com/odpf/shield/internal/server/consts"
"github.com/odpf/shield/pkg/server/consts"

"github.com/google/uuid"
"github.com/odpf/salt/log"
Expand Down
3 changes: 2 additions & 1 deletion internal/api/v1beta1/authenticate.go
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"fmt"

"github.com/odpf/shield/pkg/server/consts"

"github.com/google/uuid"
grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/odpf/shield/core/authenticate"
shieldsession "github.com/odpf/shield/core/authenticate/session"
"github.com/odpf/shield/core/organization"
"github.com/odpf/shield/core/user"
"github.com/odpf/shield/internal/server/consts"
"github.com/odpf/shield/pkg/errors"
shieldv1beta1 "github.com/odpf/shield/proto/v1beta1"
"google.golang.org/grpc"
Expand Down
4 changes: 3 additions & 1 deletion internal/bootstrap/generator.go
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"strings"

"github.com/odpf/shield/pkg/utils"

aznamespace "github.com/authzed/spicedb/pkg/namespace"
azcore "github.com/authzed/spicedb/pkg/proto/core/v1"
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
Expand Down Expand Up @@ -76,7 +78,7 @@ func BuildServiceDefinitionFromAZSchema(azDefinitions []*azcore.NamespaceDefinit
permission = permissionParts[0]
}

if len(serviceFilter) > 0 && !Contains(serviceFilter, service) {
if len(serviceFilter) > 0 && !utils.Contains(serviceFilter, service) {
// ignore service if filter was requested, and it doesn't match
continue
}
Expand Down
11 changes: 5 additions & 6 deletions internal/server/server.go
Expand Up @@ -7,17 +7,15 @@ import (
"net/http"
"time"

grpc_validator "github.com/grpc-ecosystem/go-grpc-middleware/validator"

"github.com/odpf/shield/internal/server/interceptors"
"github.com/odpf/shield/ui"
"github.com/odpf/shield/pkg/server"
"github.com/odpf/shield/pkg/server/interceptors"

"github.com/gorilla/securecookie"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
grpc_validator "github.com/grpc-ecosystem/go-grpc-middleware/validator"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
newrelic "github.com/newrelic/go-agent"
"github.com/newrelic/go-agent/_integrations/nrgrpc"
Expand All @@ -29,6 +27,7 @@ import (
"github.com/odpf/shield/internal/server/health"
"github.com/odpf/shield/pkg/telemetry"
shieldv1beta1 "github.com/odpf/shield/proto/v1beta1"
"github.com/odpf/shield/ui"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -101,7 +100,7 @@ func Serve(
}

// json web key set handler
if jwksHandler, err := NewTokenJWKSHandler(cfg.Authentication.Token); err != nil {
if jwksHandler, err := server.NewTokenJWKSHandler(cfg.Authentication.Token.RSAPath); err != nil {
return err
} else {
httpMux.Handle("/jwks.json", jwksHandler)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/odpf/shield/internal/server/consts"
"github.com/odpf/shield/pkg/server/consts"

"github.com/gorilla/securecookie"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
Expand Down
Expand Up @@ -7,22 +7,21 @@ import (
"net/http"

"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/odpf/shield/core/authenticate"
)

type TokenJWKSHandler struct {
keySet jwk.Set
}

func NewTokenJWKSHandler(cfg authenticate.TokenConfig) (*TokenJWKSHandler, error) {
func NewTokenJWKSHandler(RSAKeyPath string) (*TokenJWKSHandler, error) {
// if no config provided for path, ignore jwks
if len(cfg.RSAPath) == 0 {
if len(RSAKeyPath) == 0 {
return &TokenJWKSHandler{
keySet: jwk.NewSet(),
}, nil
}

privateSet, err := jwk.ReadFile(cfg.RSAPath)
privateSet, err := jwk.ReadFile(RSAKeyPath)
if err != nil {
return nil, fmt.Errorf("failed to read rsa key path: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/bootstrap/utils.go → pkg/utils/bootstrap.go
@@ -1,4 +1,4 @@
package bootstrap
package utils

func AppendIfUnique[T comparable](slice1 []T, slice2 []T) []T {
for _, i := range slice2 {
Expand Down
@@ -1,4 +1,4 @@
package bootstrap
package utils

import (
"fmt"
Expand Down

0 comments on commit 09797ef

Please sign in to comment.