Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: authentication lib integration #150

Merged
merged 32 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
720dfd8
imported bento-auth locally
SanjeevLakhwani Dec 25, 2023
e697628
added auth reducers to store
SanjeevLakhwani Dec 25, 2023
caa6f8a
temp progress commit
SanjeevLakhwani Dec 30, 2023
cb6d23f
temp
SanjeevLakhwani Jan 17, 2024
b059f67
added more features
SanjeevLakhwani Feb 22, 2024
5718be5
auth configs from env variables
v-rocheleau Feb 28, 2024
0b0616e
works with up to date bento-auth-js
v-rocheleau Mar 4, 2024
4c60513
auth hooks
v-rocheleau Mar 6, 2024
0be0b92
use react-router's BrowserRouter
v-rocheleau Mar 6, 2024
e17bf20
persisted oidc config and auto authentication
v-rocheleau Mar 7, 2024
abf7970
factor out config values from endpoint to env
v-rocheleau Mar 11, 2024
2d7eac8
remove unused echo configs
v-rocheleau Mar 12, 2024
3f2019c
Merge branch 'main' into auth-integration
v-rocheleau Mar 12, 2024
d7a957f
chore(deps): use bento-auth-js v4.0.0
v-rocheleau Mar 12, 2024
8387e7a
prod image config creation
v-rocheleau Mar 13, 2024
eabad3b
fix dockerfile
v-rocheleau Mar 13, 2024
2ff49d0
address review comments
v-rocheleau Mar 13, 2024
63c7220
use node image for prod config
v-rocheleau Mar 13, 2024
13040e6
use bento node image
v-rocheleau Mar 13, 2024
d1e759e
fix client name prod config script
v-rocheleau Mar 13, 2024
0514eb9
declare prod global config
v-rocheleau Mar 13, 2024
3cb5119
lint
v-rocheleau Mar 13, 2024
d6cd351
declare BENTO_PUBLIC_CONFIG as var
v-rocheleau Mar 13, 2024
196f77e
add missing config script to index
v-rocheleau Mar 13, 2024
8b270da
refact: remove golang config endpoint
v-rocheleau Mar 14, 2024
6e376f9
refact: remove golang katsu overview endpoint
v-rocheleau Mar 14, 2024
c9dbb47
refact: remove golang endpoints for katsu overview, fields and proven…
v-rocheleau Mar 15, 2024
3489502
cleanup
v-rocheleau Mar 15, 2024
3b29e17
signed out modal translations
v-rocheleau Mar 15, 2024
55ce992
order imports, translation capitalization
v-rocheleau Mar 18, 2024
5cddfd1
lint
v-rocheleau Mar 18, 2024
e17795d
factor out constants and functions
v-rocheleau Mar 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ dist/*
.idea/
.vscode/
www/

.yalc
yalc.lock
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ COPY main.go .
RUN go build -o ./reactapp


FROM ghcr.io/bento-platform/bento_base_image:plain-debian-2024.03.01
FROM ghcr.io/bento-platform/bento_base_image:node-debian-2024.03.01

ENV BENTO_PUBLIC_PACKAGE_JSON_PATH=/bento-public/package.json
WORKDIR /bento-public

COPY entrypoint.bash .
COPY package.json .
COPY create_config_prod.js .
COPY run.bash .

# Copy web app
COPY --from=nodebuilder /node/build/www /bento-public/www
Expand All @@ -46,4 +48,4 @@ COPY --from=nodebuilder /node/build/www /bento-public/www
COPY --from=gobuilder /build/reactapp /bento-public/reactapp

ENTRYPOINT [ "/bin/bash", "./entrypoint.bash" ]
CMD [ "./reactapp" ]
CMD ["bash", "./run.bash"]
22 changes: 22 additions & 0 deletions create_config_prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const parseBoolean = (value) => ["true", "1", "yes"].includes((value || "").toLocaleLowerCase());

const siteConfig = {
CLIENT_NAME: process.env.BENTO_PUBLIC_CLIENT_NAME || null,
PORTAL_URL: process.env.BENTO_PUBLIC_PORTAL_URL || null,
TRANSLATED: parseBoolean(process.env.BENTO_PUBLIC_TRANSLATED),
BEACON_URL: process.env.BEACON_URL || null,
BEACON_UI_ENABLED: parseBoolean(process.env.BENTO_BEACON_UI_ENABLED),

// Authentication
PUBLIC_URL: process.env.BENTO_PUBLIC_URL || null,
CLIENT_ID: process.env.CLIENT_ID || null,
OPENID_CONFIG_URL: process.env.OPENID_CONFIG_URL || null,
};

if (typeof require !== "undefined" && require.main === module) {
process.stdout.write(`BENTO_PUBLIC_CONFIG = ${JSON.stringify(siteConfig, null, 2)};\n`);
}

module.exports = {
siteConfig,
};
32 changes: 13 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ const ConfigLogTemplate = `Config --
Service ID: %s
package.json: %s
Static Files: %s
Client Name: %s
Katsu URL: %v
Gohan URL: %v
Bento Portal Url: %s
Port: %d
Translated: %t
Beacon URL: %s
Beacon UI enabled: %t
`

type BentoConfig struct {
// App configs
ServiceId string `envconfig:"BENTO_PUBLIC_SERVICE_ID"`
PackageJsonPath string `envconfig:"BENTO_PUBLIC_PACKAGE_JSON_PATH" default:"./package.json"`
StaticFilesPath string `envconfig:"BENTO_PUBLIC_STATIC_FILES_PATH" default:"./www"`
Expand All @@ -40,9 +36,6 @@ type BentoConfig struct {
GohanUrl string `envconfig:"BENTO_PUBLIC_GOHAN_URL"`
BentoPortalUrl string `envconfig:"BENTO_PUBLIC_PORTAL_URL"`
Port int `envconfig:"INTERNAL_PORT" default:"8090"`
Translated bool `envconfig:"BENTO_PUBLIC_TRANSLATED" default:"true"`
BeaconUrl string `envconfig:"BEACON_URL"`
BeaconUiEnabled bool `envconfig:"BENTO_BEACON_UI_ENABLED"`
}

type JsonLike map[string]interface{}
Expand Down Expand Up @@ -112,14 +105,9 @@ func main() {
cfg.ServiceId,
cfg.PackageJsonPath,
cfg.StaticFilesPath,
cfg.ClientName,
cfg.KatsuUrl,
cfg.GohanUrl,
cfg.BentoPortalUrl,
cfg.Port,
cfg.Translated,
cfg.BeaconUrl,
cfg.BeaconUiEnabled,
)

// Set up HTTP client
Expand Down Expand Up @@ -292,7 +280,13 @@ func main() {

// Begin MVC Routes
// -- Root : static files
e.Use(middleware.Static(cfg.StaticFilesPath))
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: cfg.StaticFilesPath,
// Enable HTML5 mode by forwarding all not-found requests to root so that
// SPA (single-page application) can handle the routing.
// Required for react-router BrowserRouter fallback
HTML5: true,
}))

// -- GA4GH-compatible service information response
e.GET("/service-info", func(c echo.Context) error {
Expand Down Expand Up @@ -321,6 +315,7 @@ func main() {
// purges expired items every 10 minutes
var katsuCache = cache.New(5*time.Minute, 10*time.Minute)

// TODO: rm
e.GET("/config", func(c echo.Context) error {
// restore from cache if present/not expired
publicOverview, err := getKatsuPublicOverview(c, katsuCache)
Expand All @@ -329,15 +324,11 @@ func main() {
}

return c.JSON(http.StatusOK, JsonLike{
"clientName": cfg.ClientName,
"maxQueryParameters": publicOverview["max_query_parameters"],
"portalUrl": cfg.BentoPortalUrl,
"translated": cfg.Translated,
"beaconUrl": cfg.BeaconUrl,
"beaconUiEnabled": cfg.BeaconUiEnabled,
})
})

// TODO: rm
e.GET("/overview", func(c echo.Context) error {
// restore from cache if present/not expired
publicOverview, err := getKatsuPublicOverview(c, katsuCache)
Expand All @@ -348,6 +339,7 @@ func main() {
return c.JSON(http.StatusOK, JsonLike{"overview": publicOverview})
})

// TODO: rm
// get request handler for /katsu that relays the request to the Katsu API and returns response
e.GET("/katsu", func(c echo.Context) error {
// get query parameters
Expand All @@ -362,12 +354,14 @@ func main() {
return katsuRequest("/api/public", qs, c, jsonDeserialize)
})

// TODO: rm
e.GET("/fields", func(c echo.Context) error {
// Query Katsu for publicly available search fields
// TODO: formalize response type
return katsuRequestBasic("/api/public_search_fields", c)
})

// TODO: rm
e.GET("/provenance", func(c echo.Context) error {
// Query Katsu for datasets provenance
return katsuRequestBasic("/api/public_dataset", c)
Expand Down
Loading