forked from ClusterCockpit/cc-backend
-
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 ClusterCockpit#289 from ClusterCockpit/dev
Update Q4 2024
- Loading branch information
Showing
161 changed files
with
18,449 additions
and
9,271 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
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,33 @@ | ||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg. | ||
// All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
package main | ||
|
||
import "flag" | ||
|
||
var ( | ||
flagReinitDB, flagInit, flagServer, flagSyncLDAP, flagGops, flagMigrateDB, flagRevertDB, flagForceDB, flagDev, flagVersion, flagLogDateTime bool | ||
flagNewUser, flagDelUser, flagGenJWT, flagConfigFile, flagImportJob, flagLogLevel string | ||
) | ||
|
||
func cliInit() { | ||
flag.BoolVar(&flagInit, "init", false, "Setup var directory, initialize swlite database file, config.json and .env") | ||
flag.BoolVar(&flagReinitDB, "init-db", false, "Go through job-archive and re-initialize the 'job', 'tag', and 'jobtag' tables (all running jobs will be lost!)") | ||
flag.BoolVar(&flagSyncLDAP, "sync-ldap", false, "Sync the 'user' table with ldap") | ||
flag.BoolVar(&flagServer, "server", false, "Start a server, continues listening on port after initialization and argument handling") | ||
flag.BoolVar(&flagGops, "gops", false, "Listen via github.com/google/gops/agent (for debugging)") | ||
flag.BoolVar(&flagDev, "dev", false, "Enable development components: GraphQL Playground and Swagger UI") | ||
flag.BoolVar(&flagVersion, "version", false, "Show version information and exit") | ||
flag.BoolVar(&flagMigrateDB, "migrate-db", false, "Migrate database to supported version and exit") | ||
flag.BoolVar(&flagRevertDB, "revert-db", false, "Migrate database to previous version and exit") | ||
flag.BoolVar(&flagForceDB, "force-db", false, "Force database version, clear dirty flag and exit") | ||
flag.BoolVar(&flagLogDateTime, "logdate", false, "Set this flag to add date and time to log messages") | ||
flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`") | ||
flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: `<username>:[admin,support,manager,api,user]:<password>`") | ||
flag.StringVar(&flagDelUser, "del-user", "", "Remove user by `username`") | ||
flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`") | ||
flag.StringVar(&flagImportJob, "import-job", "", "Import a job. Argument format: `<path-to-meta.json>:<path-to-data.json>,...`") | ||
flag.StringVar(&flagLogLevel, "loglevel", "warn", "Sets the logging level: `[debug,info,warn (default),err,fatal,crit]`") | ||
flag.Parse() | ||
} |
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,85 @@ | ||
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg. | ||
// All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ClusterCockpit/cc-backend/internal/repository" | ||
"github.com/ClusterCockpit/cc-backend/internal/util" | ||
"github.com/ClusterCockpit/cc-backend/pkg/log" | ||
) | ||
|
||
const envString = ` | ||
# Base64 encoded Ed25519 keys (DO NOT USE THESE TWO IN PRODUCTION!) | ||
# You can generate your own keypair using the gen-keypair tool | ||
JWT_PUBLIC_KEY="kzfYrYy+TzpanWZHJ5qSdMj5uKUWgq74BWhQG6copP0=" | ||
JWT_PRIVATE_KEY="dtPC/6dWJFKZK7KZ78CvWuynylOmjBFyMsUWArwmodOTN9itjL5POlqdZkcnmpJ0yPm4pRaCrvgFaFAbpyik/Q==" | ||
# Some random bytes used as secret for cookie-based sessions (DO NOT USE THIS ONE IN PRODUCTION) | ||
SESSION_KEY="67d829bf61dc5f87a73fd814e2c9f629" | ||
` | ||
|
||
const configString = ` | ||
{ | ||
"addr": "127.0.0.1:8080", | ||
"archive": { | ||
"kind": "file", | ||
"path": "./var/job-archive" | ||
}, | ||
"jwts": { | ||
"max-age": "2000h" | ||
}, | ||
"clusters": [ | ||
{ | ||
"name": "name", | ||
"metricDataRepository": { | ||
"kind": "cc-metric-store", | ||
"url": "http://localhost:8082", | ||
"token": "" | ||
}, | ||
"filterRanges": { | ||
"numNodes": { | ||
"from": 1, | ||
"to": 64 | ||
}, | ||
"duration": { | ||
"from": 0, | ||
"to": 86400 | ||
}, | ||
"startTime": { | ||
"from": "2023-01-01T00:00:00Z", | ||
"to": null | ||
} | ||
} | ||
} | ||
] | ||
} | ||
` | ||
|
||
func initEnv() { | ||
if util.CheckFileExists("var") { | ||
fmt.Print("Directory ./var already exists. Exiting!\n") | ||
os.Exit(0) | ||
} | ||
|
||
if err := os.WriteFile("config.json", []byte(configString), 0o666); err != nil { | ||
log.Fatalf("Writing config.json failed: %s", err.Error()) | ||
} | ||
|
||
if err := os.WriteFile(".env", []byte(envString), 0o666); err != nil { | ||
log.Fatalf("Writing .env failed: %s", err.Error()) | ||
} | ||
|
||
if err := os.Mkdir("var", 0o777); err != nil { | ||
log.Fatalf("Mkdir var failed: %s", err.Error()) | ||
} | ||
|
||
err := repository.MigrateDB("sqlite3", "./var/job.db") | ||
if err != nil { | ||
log.Fatalf("Initialize job.db failed: %s", err.Error()) | ||
} | ||
} |
Oops, something went wrong.