all: drop CONFIG_ prefix for configuration (#297)

Fixes #251
This commit is contained in:
C Cirello
2016-11-15 19:19:21 +01:00
committed by Seif Lotfy سيف لطفي
parent 6e58321928
commit 02d3b18497
13 changed files with 40 additions and 42 deletions

View File

@@ -128,12 +128,10 @@ func handleRequest(c *gin.Context, enqueue models.Enqueue) {
// app config
for k, v := range app.Config {
envVars[ToEnvName("CONFIG", k)] = v
envVars[ToEnvName("", k)] = v
}
// route config
for k, v := range found.Config {
envVars[ToEnvName("CONFIG", k)] = v
envVars[ToEnvName("", k)] = v
}
// params

View File

@@ -49,21 +49,21 @@ func TestRouteRunnerAsyncExecution(t *testing.T) {
expectedCode int
expectedEnv map[string]string
}{
{"/r/myapp/myroute", ``, map[string][]string{}, http.StatusOK, map[string]string{"CONFIG_TEST": "true", "CONFIG_APP": "true"}},
{"/r/myapp/myroute", ``, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
{
"/r/myapp/myroute/1",
``,
map[string][]string{"X-Function": []string{"test"}},
http.StatusOK,
map[string]string{
"CONFIG_TEST": "true",
"CONFIG_APP": "true",
"TEST": "true",
"APP": "true",
"PARAM_PARAM": "1",
"HEADER_X_FUNCTION": "test",
},
},
{"/r/myapp/myerror", ``, map[string][]string{}, http.StatusOK, map[string]string{"CONFIG_TEST": "true", "CONFIG_APP": "true"}},
{"/r/myapp/myroute", `{ "name": "test" }`, map[string][]string{}, http.StatusOK, map[string]string{"CONFIG_TEST": "true", "CONFIG_APP": "true"}},
{"/r/myapp/myerror", ``, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
{"/r/myapp/myroute", `{ "name": "test" }`, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
} {
body := bytes.NewBuffer([]byte(test.body))

View File

@@ -7,7 +7,7 @@ Applications are the top level object that groups routes together to create an A
When creating or updating an app, you can pass in a map of config variables.
`config` is a map of values passed to the route runtime in the form of
environment variables prefixed with `CONFIG_`.
environment variables.
Note: Route level configuration overrides app level configuration.

View File

@@ -20,7 +20,7 @@ dispatches a new request, gets a task ID back and closes the HTTP connection.
Default: `sync`.
`config` is a map of values passed to the route runtime in the form of
environment variables prefixed with `CONFIG_`.
environment variables.
Note: Route level configuration overrides app level configuration.

View File

@@ -1,6 +1,6 @@
# Writing Functions
This will give you the basic overview of writing base level functions. You can also use higher level
This will give you the basic overview of writing base level functions. You can also use higher level
abstractions that make it easier such as [lambda](lambda/README.md).
Also, for complete examples in various languages, see the [examples directory](/examples).
@@ -16,7 +16,7 @@ body = JSON.parse(STDIN)
# Do something
return_struct = doSomething(body)
# Respond if sync:
# Respond if sync:
STDOUT.write(JSON.generate(return_struct))
# or update something if async
db.update(return_struct)
@@ -24,27 +24,27 @@ db.update(return_struct)
## Inputs
Inputs are provided through standard input and environment variables. We'll just talk about the default input format here, but you can find others [here](function-format.md).
To read in the function body, just read from STDIN.
Inputs are provided through standard input and environment variables. We'll just talk about the default input format here, but you can find others [here](function-format.md).
To read in the function body, just read from STDIN.
You will also have access to a set of environment variables.
You will also have access to a set of environment variables.
* REQUEST_URL - the full URL for the request
* ROUTE - the matched route
* METHOD - the HTTP method for the request
* CONFIG_X - any configuration values you've set for the Application or the Route. Replace X with the upper cased name of the config variable you set.
* HEADER_X - the HTTP headers that were set for this request. Replace X with the upper cased name of the header and replace dashes in the header with underscores.
* HEADER_X - the HTTP headers that were set for this request. Replace X with the upper cased name of the header and replace dashes in the header with underscores.
* any configuration values you've set for the Application or the Route. Replace X with the upper cased name of the config variable you set.
Warning: these may change before release.
## Logging
Standard out is where you should write response data for synchronous functions. Standard error
is where you should write for logging, as [it was intended](http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout).
Standard out is where you should write response data for synchronous functions. Standard error
is where you should write for logging, as [it was intended](http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout).
So to write output to logs, simply log to STDERR. Here are some examples in a few languages.
So to write output to logs, simply log to STDERR. Here are some examples in a few languages.
In Go, simply use the [log](https://golang.org/pkg/log/) package, it writes to STDERR by default.
In Go, simply use the [log](https://golang.org/pkg/log/) package, it writes to STDERR by default.
```go
log.Println("hi")

View File

@@ -116,12 +116,12 @@ This command should return `{"error":"Invalid authentication"}` because we aren'
First let's create our blog user. In this example an user `test` with password `test`.
```
docker run --rm -e CONFIG_DB=$MONGODB -e NEWUSER='{ "username": "test", "password": "test" }' $USERNAME/functions-blog
docker run --rm -e DB=$MONGODB -e NEWUSER='{ "username": "test", "password": "test" }' $USERNAME/functions-blog
```
##### Getting authorization token
Now, to get authorized to post in our Blog API endpoints we must request a new token with a valid user.
Now, to get authorized to post in our Blog API endpoints we must request a new token with a valid user.
```
curl -X POST --data '{ "username": "test", "password": "test" }' http://$FUNCAPI/r/blog/token

View File

@@ -15,7 +15,7 @@ var noAuth = map[string]interface{}{}
func main() {
request := fmt.Sprintf("%s %s", os.Getenv("METHOD"), os.Getenv("ROUTE"))
dbURI := os.Getenv("CONFIG_DB")
dbURI := os.Getenv("DB")
if dbURI == "" {
dbURI = "127.0.0.1/blog"
}

View File

@@ -9,8 +9,8 @@ docker rm test-mongo-func
docker run -p 27017:27017 --name test-mongo-func -d mongo
echo '{ "title": "My New Post", "body": "Hello world!", "user": "test" }' | docker run --rm -i -e METHOD=POST -e ROUTE=/posts -e CONFIG_DB=mongo:27017 --link test-mongo-func:mongo -e TEST=1 iron/func-blog
docker run --rm -i -e METHOD=GET -e ROUTE=/posts -e CONFIG_DB=mongo:27017 --link test-mongo-func:mongo -e TEST=1 iron/func-blog
echo '{ "title": "My New Post", "body": "Hello world!", "user": "test" }' | docker run --rm -i -e METHOD=POST -e ROUTE=/posts -e DB=mongo:27017 --link test-mongo-func:mongo -e TEST=1 iron/func-blog
docker run --rm -i -e METHOD=GET -e ROUTE=/posts -e DB=mongo:27017 --link test-mongo-func:mongo -e TEST=1 iron/func-blog
docker stop test-mongo-func
docker rm test-mongo-func

View File

@@ -74,5 +74,5 @@ curl -X POST --data '{
Now that we created our IronFunction route, let's test our new route
```
curl -X POST --data '{ "env_vars": { "config_test": "1" } }' http://$FUNCAPI/r/checker/check
curl -X POST --data '{ "env_vars": { "test": "1" } }' http://$FUNCAPI/r/checker/check
```

View File

@@ -29,7 +29,7 @@ func main() {
}
// Dialing redis server
c, err := redis.Dial("tcp", os.Getenv("CONFIG_SERVER"))
c, err := redis.Dial("tcp", os.Getenv("SERVER"))
if err != nil {
log.Println("Failed to dial redis server")
log.Fatal(err)
@@ -37,8 +37,8 @@ func main() {
}
// Authenticate to redis server if exists the password
if os.Getenv("CONFIG_REDIS_AUTH") != "" {
if _, err := c.Do("AUTH", os.Getenv("CONFIG_REDIS_AUTH")); err != nil {
if os.Getenv("REDIS_AUTH") != "" {
if _, err := c.Do("AUTH", os.Getenv("REDIS_AUTH")); err != nil {
log.Println("Failed to authenticate to redis server")
log.Fatal(err)
return
@@ -46,16 +46,16 @@ func main() {
}
// Check if payload command is valid
if os.Getenv("CONFIG_COMMAND") != "GET" && os.Getenv("CONFIG_COMMAND") != "SET" {
if os.Getenv("COMMAND") != "GET" && os.Getenv("COMMAND") != "SET" {
log.Println("Invalid command")
return
}
// Execute command on redis server
var r interface{}
if os.Getenv("CONFIG_COMMAND") == "GET" {
if os.Getenv("COMMAND") == "GET" {
r, err = c.Do("GET", pl.Key)
} else if os.Getenv("CONFIG_COMMAND") == "SET" {
} else if os.Getenv("COMMAND") == "SET" {
r, err = c.Do("SET", pl.Key, pl.Value)
}

View File

@@ -14,8 +14,8 @@ docker rm test-redis-func
docker run -p 6379:6379 --name test-redis-func -d redis
echo $PAYLOAD | docker run --rm -i -e CONFIG_SERVER=redis:6379 -e CONFIG_COMMAND=SET --link test-redis-func:redis iron/func-redis
echo $PAYLOAD | docker run --rm -i -e CONFIG_SERVER=redis:6379 -e CONFIG_COMMAND=GET --link test-redis-func:redis iron/func-redis
echo $PAYLOAD | docker run --rm -i -e SERVER=redis:6379 -e COMMAND=SET --link test-redis-func:redis iron/func-redis
echo $PAYLOAD | docker run --rm -i -e SERVER=redis:6379 -e COMMAND=GET --link test-redis-func:redis iron/func-redis
docker stop test-redis-func
docker rm test-redis-func

View File

@@ -36,8 +36,8 @@ func main() {
fmt.Println("Looking for tweets of the account:", username)
// Twitter auth config
config := oauth1.NewConfig(os.Getenv("CONFIG_CUSTOMER_KEY"), os.Getenv("CONFIG_CUSTOMER_SECRET"))
token := oauth1.NewToken(os.Getenv("CONFIG_ACCESS_TOKEN"), os.Getenv("CONFIG_ACCESS_SECRET"))
config := oauth1.NewConfig(os.Getenv("CUSTOMER_KEY"), os.Getenv("CUSTOMER_SECRET"))
token := oauth1.NewToken(os.Getenv("ACCESS_TOKEN"), os.Getenv("ACCESS_SECRET"))
httpClient := config.Client(oauth1.NoContext, token)

View File

@@ -6,7 +6,7 @@
Init will help you create a [function file](../docs/function-file.md) (func.yaml) in the current directory.
To make things simple, we try to use convention over configuration, so `init` will look for a file named `func.{language-extension}`. For example,
To make things simple, we try to use convention over configuration, so `init` will look for a file named `func.{language-extension}`. For example,
if you are using Node, put the code that you want to execute in the file `func.js`. If you are using Python, use `func.py`. Ruby, use `func.rb`. Go, `func.go`. Etc.
Run:
@@ -21,7 +21,7 @@ If you want to override the convention with configuration, you can do that as we
fnctl init [--runtime node] [--entrypoint "node hello.js"] <DOCKER_HUB_USERNAME>/<FUNCTION_NAME>
```
Or, if you want full control, just make a Dockerfile. If `init` finds a Dockerfile, it will use that instead of runtime and entrypoint.
Or, if you want full control, just make a Dockerfile. If `init` finds a Dockerfile, it will use that instead of runtime and entrypoint.
### Build, Bump, Run, Push
@@ -92,7 +92,7 @@ fnctl apps create --config DB_URL=http://example.org/ otherapp
```
`--config` is a map of values passed to the route runtime in the form of
environment variables prefixed with `CONFIG_`.
environment variables.
Repeated calls to `fnctl apps create` will trigger an update of the given
route, thus you will be able to change any of these attributes later in time
@@ -116,7 +116,7 @@ until the request is successfully completed, or `async`, in which the clients
dispatches a new request, gets a task ID back and closes the HTTP connection.
`--config` is a map of values passed to the route runtime in the form of
environment variables prefixed with `CONFIG_`.
environment variables.
Repeated calls to `fnctl route create` will trigger an update of the given
route, thus you will be able to change any of these attributes later in time