-
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.
feat(jobserver): allow to specify global configuration via env file (#11
) * feat(jobserver): allow to specify global configuration via env file As an example we provide to the webscraper a WEBSCRAPER_BLACKLIST environment variable which contains a comma separated list of url to blacklist during scraping. The JobConfiguration is a generic map[string]interface{} that can be populated top-level. It gets unmarshalled as JSON by the jobs to map the relevant fields in the configuration. Signed-off-by: mudler <[email protected]> * add .env.example Signed-off-by: mudler <[email protected]> --------- Signed-off-by: mudler <[email protected]>
- Loading branch information
Showing
14 changed files
with
124 additions
and
23 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 |
---|---|---|
|
@@ -74,6 +74,6 @@ snippets.txt | |
dist/ | ||
bp-todo.md | ||
|
||
.masa/ | ||
.masa/.env | ||
# TEE | ||
tee/private.pem |
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,2 @@ | ||
# Set of websites to always blacklist | ||
# WEBSCRAPER_BLACKLIST=google.com,foo.bar |
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,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/masa-finance/tee-worker/api/types" | ||
) | ||
|
||
func readConfig() types.JobConfiguration { | ||
dataDir := os.Getenv("DATA_DIR") | ||
if dataDir == "" { | ||
dataDir = "/home/masa" | ||
os.Setenv("DATA_DIR", dataDir) | ||
} | ||
|
||
// Read the env file | ||
if err := godotenv.Load(filepath.Join(dataDir, ".env")); err != nil { | ||
fmt.Println("Failed reading env file!") | ||
panic(err) | ||
} | ||
|
||
webScraperBlacklist := os.Getenv("WEBSCRAPER_BLACKLIST") | ||
|
||
blacklistURLs := strings.Split(webScraperBlacklist, ",") | ||
for i, u := range blacklistURLs { | ||
blacklistURLs[i] = strings.TrimSpace(u) | ||
} | ||
|
||
// Read the .env file and set the global configuration for all the jobs | ||
// The jobs will then unmarshal from this configuration to the specific configuration | ||
// that is needed for the job | ||
jc := types.JobConfiguration{} | ||
jc["webscraper_blacklist"] = blacklistURLs | ||
|
||
return jc | ||
} | ||
|
||
func listenAddress() string { | ||
listenAddress := os.Getenv("LISTEN_ADDRESS") | ||
if listenAddress == "" { | ||
listenAddress = ":8080" | ||
} | ||
|
||
return listenAddress | ||
} |
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
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
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