Skip to content

Commit

Permalink
Create request-id to be set as a header on the request for oracle pro…
Browse files Browse the repository at this point in the history
…vider

requests.
  • Loading branch information
JadeRedworth committed Aug 17, 2018
1 parent 687df96 commit 735b2eb
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 2 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"bytes"
"crypto/rand"
"encoding/base32"
"fmt"
"io"
"log"
"os"
"sort"
"strings"
Expand All @@ -17,6 +20,16 @@ import (
"github.com/urfave/cli"
)

func getRequestID() string {
byteArr := make([]byte, 16)
_, err := rand.Read(byteArr)
if err != nil {
log.Fatalf("failed to generate random number for requestID")
}

return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(byteArr)
}

func newFn() *cli.App {
app := cli.NewApp()
app.Name = "fn"
Expand All @@ -29,6 +42,8 @@ func newFn() *cli.App {
if err != nil {
return err
}

viper.Set("request-id", getRequestID())
commandArgOverrides(c)
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions new-func/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine
COPY java-init.tar /
CMD ["cat", "/java-init.tar"]
5 changes: 5 additions & 0 deletions new-func/func.init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runtime: java
cmd: com.example.fn.HelloFunction::handleRequest
build_image: fnproject/fn-java-fdk-build:jdk9-1.0.64
run_image: fnproject/fn-java-fdk:jdk9-1.0.64
format: http
7 changes: 7 additions & 0 deletions new-func/func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: new-func
version: 0.0.1
runtime: java
cmd: com.example.fn.HelloFunction::handleRequest
build_image: fnproject/fn-java-fdk-build:jdk9-1.0.64
run_image: fnproject/fn-java-fdk:jdk9-1.0.64
format: http
Binary file added new-func/java-init.tar
Binary file not shown.
66 changes: 66 additions & 0 deletions new-func/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<fdk.version>1.0.64</fdk.version>
</properties>
<groupId>com.example.fn</groupId>
<artifactId>hello</artifactId>
<version>1.0.0</version>

<repositories>
<repository>
<id>fn-release-repo</id>
<url>https://dl.bintray.com/fnproject/fnproject</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>api</artifactId>
<version>${fdk.version}</version>
</dependency>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>testing-core</artifactId>
<version>${fdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>testing-junit4</artifactId>
<version>${fdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions new-func/src/main/java/com/example/fn/HelloFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.fn;

public class HelloFunction {

public String handleRequest(String input) {
String name = (input == null || input.isEmpty()) ? "world" : input;

return "Hello, " + name + "!";
}

}
22 changes: 22 additions & 0 deletions new-func/src/test/java/com/example/fn/HelloFunctionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.fn;

import com.fnproject.fn.testing.*;
import org.junit.*;

import static org.junit.Assert.*;

public class HelloFunctionTest {

@Rule
public final FnTestingRule testing = FnTestingRule.createDefault();

@Test
public void shouldReturnGreeting() {
testing.givenEvent().enqueue();
testing.thenRun(HelloFunction.class, "handleRequest");

FnResult result = testing.getOnlyResult();
assertEquals("Hello, world!", result.getBodyAsString());
}

}
6 changes: 4 additions & 2 deletions objects/app/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (

"github.com/fnproject/cli/client"
"github.com/fnproject/cli/common"
fnclient "github.com/fnproject/fn_go/client"
fnclient "github.com/fnproject/fn_go/client"
apiapps "github.com/fnproject/fn_go/client/apps"
"github.com/fnproject/fn_go/models"
"github.com/fnproject/fn_go/provider"
"github.com/jmoiron/jsonq"
"github.com/spf13/viper"
"github.com/urfave/cli"
)

Expand All @@ -26,7 +27,8 @@ type appsCmd struct {
}

func (a *appsCmd) list(c *cli.Context) error {
params := &apiapps.GetAppsParams{Context: context.Background()}
ctx := provider.WithRequestID(context.Background(), viper.GetString("request-id"))
params := &apiapps.GetAppsParams{Context: ctx}
var resApps []*models.App
for {
resp, err := a.client.Apps.GetApps(params)
Expand Down
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<fdk.version>1.0.64</fdk.version>
</properties>
<groupId>com.example.fn</groupId>
<artifactId>hello</artifactId>
<version>1.0.0</version>

<repositories>
<repository>
<id>fn-release-repo</id>
<url>https://dl.bintray.com/fnproject/fnproject</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>api</artifactId>
<version>${fdk.version}</version>
</dependency>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>testing-core</artifactId>
<version>${fdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fnproject.fn</groupId>
<artifactId>testing-junit4</artifactId>
<version>${fdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions src/main/java/com/example/fn/HelloFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.fn;

public class HelloFunction {

public String handleRequest(String input) {
String name = (input == null || input.isEmpty()) ? "world" : input;

return "Hello, " + name + "!";
}

}
22 changes: 22 additions & 0 deletions src/test/java/com/example/fn/HelloFunctionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.fn;

import com.fnproject.fn.testing.*;
import org.junit.*;

import static org.junit.Assert.*;

public class HelloFunctionTest {

@Rule
public final FnTestingRule testing = FnTestingRule.createDefault();

@Test
public void shouldReturnGreeting() {
testing.givenEvent().enqueue();
testing.thenRun(HelloFunction.class, "handleRequest");

FnResult result = testing.getOnlyResult();
assertEquals("Hello, world!", result.getBodyAsString());
}

}

0 comments on commit 735b2eb

Please sign in to comment.