Skip to content

Commit

Permalink
minor fixes for updated by user
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-allen committed Oct 18, 2024
1 parent 8cae4d1 commit 68e87b3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
25 changes: 14 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
######################################
FROM node:18 as npm_builder
WORKDIR /go/src/github.com/Allen-Career-Institute/flagr
ARG ENVIRONMENT=production
ARG ENVIRONMENT=local
ENV ENVIRONMENT=${ENVIRONMENT}
ADD . .
COPY . .
ARG FLAGR_UI_POSSIBLE_ENTITY_TYPES=null
ENV VUE_APP_FLAGR_UI_POSSIBLE_ENTITY_TYPES ${FLAGR_UI_POSSIBLE_ENTITY_TYPES}
RUN make build_ui
Expand All @@ -16,30 +16,32 @@ RUN make build_ui
FROM golang:1.21-alpine as go_builder
WORKDIR /go/src/github.com/Allen-Career-Institute/flagr

RUN apk add --no-cache git make build-base
ADD . .
RUN apk add --no-cache build-base git make
COPY . .
RUN make build

FROM alpine

COPY --from=go_builder /go/src/github.com/Allen-Career-Institute/flagr/flagr .

ENV HOST=0.0.0.0
ENV PORT=3000
# ENV PORT=3000 (for local testing)
ENV PORT=18000

ENV FLAGR_DB_DBDRIVER=sqlite3
ENV FLAGR_DB_DBCONNECTIONSTR=/data/demo_sqlite3.db
ENV FLAGR_RECORDER_ENABLED=false

# JWT Environment Variables
ENV FLAGR_JWT_AUTH_ENABLED=true
ENV FLAGR_JWT_AUTH_DEBUG=true
ENV FLAGR_JWT_AUTH_WHITELIST_PATHS="/api/v1/health,/api/v1/evaluation,/login,/callback,/static,/favicon.ico,/flags"
ENV FLAGR_JWT_AUTH_WHITELIST_PATHS="/api/v1/health,/api/v1/evaluation,/login,/callback,/static,/favicon.ico"
ENV FLAGR_JWT_AUTH_EXACT_WHITELIST_PATHS=",/,/login,/callback"
ENV FLAGR_JWT_AUTH_COOKIE_TOKEN_NAME="access_token"
#ENV FLAGR_JWT_AUTH_SECRET="<your-jwt-secret>"
# ENV FLAGR_JWT_AUTH_SECRET="secret"
ENV FLAGR_JWT_AUTH_NO_TOKEN_STATUS_CODE=307
ENV FLAGR_JWT_AUTH_NO_TOKEN_REDIRECT_URL="http://localhost:3000/login"
ENV FLAGR_JWT_AUTH_USER_PROPERTY=flagr_user
# ENV FLAGR_JWT_AUTH_NO_TOKEN_REDIRECT_URL="http://localhost:3000/login" (for local testing)
ENV FLAGR_JWT_AUTH_NO_TOKEN_REDIRECT_URL="http://localhost:18000/login"
ENV FLAGR_JWT_AUTH_USER_CLAIM=uid
ENV FLAGR_JWT_AUTH_SIGNING_METHOD=HS256

Expand All @@ -48,8 +50,9 @@ COPY --from=npm_builder /go/src/github.com/Allen-Career-Institute/flagr/browser/
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

ADD --chown=appuser:appgroup ./buildscripts/demo_sqlite3.db /data/demo_sqlite3.db
COPY --chown=appuser:appgroup ./buildscripts/demo_sqlite3.db /data/demo_sqlite3.db

EXPOSE 3000
# EXPOSE 3000 (for local testing)
EXPOSE 18000

CMD "./flagr"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ifeq ($(ENVIRONMENT),dev)
BUILD_CMD = build:dev
else ifeq ($(ENVIRONMENT),stage)
BUILD_CMD = build:stage
else ifeq ($(ENVIRONMENT),local)
BUILD_CMD = build:local
else
BUILD_CMD = build
endif
Expand Down
1 change: 1 addition & 0 deletions browser/flagr-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode stage",
"build:dev": "vue-cli-service build --mode dev",
"build:local": "vue-cli-service build --mode local",
"lint": "vue-cli-service lint",
"watch": "vue-cli-service build --watch"
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/jwtmiddleware/jwt_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type errorHandler func(w http.ResponseWriter, r *http.Request, err string)
// be treated as an error. An empty string should be returned in that case.
type TokenExtractor func(r *http.Request) (string, error)

// Define a custom type for the key
type contextKey string
// ContextKey Define a custom type for the key
type ContextKey string

// Options is a struct for specifying configuration options for the middleware.
type Options struct {
Expand Down Expand Up @@ -233,7 +233,7 @@ func (m *JWTMiddleware) CheckJWT(w http.ResponseWriter, r *http.Request) error {

// If we get here, everything worked and we can set the
// user property in context.
newRequest := r.WithContext(context.WithValue(r.Context(), contextKey(m.Options.UserProperty), parsedToken))
newRequest := r.WithContext(context.WithValue(r.Context(), ContextKey(m.Options.UserProperty), parsedToken))
// Update the current request with the new context information.
*r = *newRequest
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/jwtmiddleware/jwt_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
// in the token as json -> {"text":"bar"}
func protectedHandler(w http.ResponseWriter, r *http.Request) {
// retrieve the token from the context
u := r.Context().Value(contextKey(userPropertyName))
u := r.Context().Value(ContextKey(userPropertyName))
if u == nil {
http.Error(w, "Unauthorized: no token present", http.StatusUnauthorized)
return
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func createCORSMiddleware() negroni.Handler {

// applyStaticFileMiddleware handles static files and Vue.js routing
func applyStaticFileMiddleware(n *negroni.Negroni) {
n.Use(&negroni.Static{
Dir: http.Dir("./browser/flagr-ui/dist/"),
Prefix: Config.WebPrefix,
IndexFile: "index.html",
})

n.UseFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if strings.Contains(r.URL.Path, "/api/") {
next(w, r)
Expand Down
11 changes: 7 additions & 4 deletions pkg/handler/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
}

logs := []*models.SegmentDebugLog{}
var vID int64
var sID int64

var evalNextSegment bool
var (
vID int64
sID int64
evalNextSegment bool
)

for _, segment := range flag.Segments {
sID = int64(segment.ID)
Expand All @@ -200,10 +201,12 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
}
evalResult := BlankResult(flag, evalContext, "")
evalResult.EvalDebugLog.SegmentDebugLogs = logs

if !evalNextSegment {
evalResult.SegmentID = sID
}
evalResult.VariantID = vID

v := flag.FlagEvaluation.VariantsMap[util.SafeUint(vID)]
if v != nil {
evalResult.VariantAttachment = v.Attachment
Expand Down
4 changes: 3 additions & 1 deletion pkg/handler/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package handler
import (
"net/http"

"github.com/Allen-Career-Institute/flagr/pkg/config/jwtmiddleware"

"github.com/Allen-Career-Institute/flagr/pkg/config"
"github.com/Allen-Career-Institute/flagr/pkg/util"

Expand All @@ -15,7 +17,7 @@ func getSubjectFromRequest(r *http.Request) string {
}

if config.Config.JWTAuthEnabled {
token, ok := r.Context().Value(config.Config.JWTAuthUserProperty).(*jwt.Token)
token, ok := r.Context().Value(jwtmiddleware.ContextKey(config.Config.JWTAuthUserProperty)).(*jwt.Token)
if !ok {
return ""
}
Expand Down

0 comments on commit 68e87b3

Please sign in to comment.