mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
committed by
Seif Lotfy سيف لطفي
parent
6e58321928
commit
02d3b18497
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ 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.
|
||||
* 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.
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ 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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
```
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user