Skip to content

Instantly share code, notes, and snippets.

Avatar
🐞
mostly bugs with some code on the side

Abhishek Gupta abhirockzz

🐞
mostly bugs with some code on the side
View GitHub Profile
View funcy-5.go
...
giphyResp, err := http.Get("http://api.giphy.com/v1/gifs/random?tag=" + giphyTag + "&api_key=" + apiKey)
if err != nil {
fmt.Println("giphy did not respond", err)
return
}
resp, err := ioutil.ReadAll(giphyResp.Body)
if err != nil {
fmt.Println("could not read giphy resp", err)
View funcy-3.go
...
if !matchSignature(slackSignature, signingSecret, slackSigningBaseString) {
fmt.Println("Signature did not match. Function was not invoked by Slack")
return
}
...
func matchSignature(slackSignature, signingSecret, slackSigningBaseString string) bool {
//calculate SHA256 of the slackSigningBaseString using signingSecret
mac := hmac.New(sha256.New, []byte(signingSecret))
View funcy-2.go
...
signingSecret, present := fdkCtx.Config()["SLACK_SIGNING_SECRET"]
if !present {
fmt.Println("please set SLACK_SIGNING_SECRET configuration in your app")
return
}
slackTimestamp := fdkCtx.Header().Get("X-Slack-Request-Timestamp")
b, err := ioutil.ReadAll(in)
if err != nil {
fmt.Println("unable to read slack data in message body", err)
View funcy-1.go
func main() {
fdk.Handle(fdk.HandlerFunc(funcy))
}
func funcy(ctx context.Context, in io.Reader, out io.Writer) {
....
}
View Dockerfile
FROM fnproject/fn-java-fdk-build:jdk9-1.0.83 as build-stage
WORKDIR /function
ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
ADD pom.xml /function/pom.xml
ARG OCI_JAVA_SDK_VERSION=1.3.5
RUN echo "using OCI Java SDK version " $OCI_JAVA_SDK_VERSION
ARG OCI_JAVA_SDK_JAR_NAME=oci-java-sdk-full-$OCI_JAVA_SDK_VERSION.jar
ARG OCI_JAVA_SDK_RELEASE_URL=https://github.com/oracle/oci-java-sdk/releases/download/v$OCI_JAVA_SDK_VERSION/oci-java-sdk.zip
View put.java
public String handle(ObjectInfo objectInfo) {
String result = "FAILED";
if (objStoreClient == null) {
System.err.println("There was a problem creating the ObjectStorageClient object. Please check logs");
return result;
}
try {
String nameSpace = System.getenv().get("NAMESPACE");
PutObjectRequest por = PutObjectRequest.builder()
.namespaceName(nameSpace)
View get.java
public String handle(GetObjectInfo objectInfo) {
String result = "FAILED";
if (objStoreClient == null) {
System.err.println("There was a problem creating the ObjectStorageClient object. Please check logs");
return result;
}
try {
String nameSpace = System.getenv().get("NAMESPACE");
GetObjectRequest gor = GetObjectRequest.builder()
.namespaceName(nameSpace)
View list.java
public List<String> handle(String bucketName) {
if (objStoreClient == null) {
System.err.println("There was a problem creating the ObjectStorageClient object. Please check logs");
return Collections.emptyList();
}
List<String> objNames = null;
try {
String nameSpace = System.getenv().get("NAMESPACE");
ListObjectsRequest lor = ListObjectsRequest.builder()
.namespaceName(nameSpace)
View apiclient.java
AuthenticationDetailsProvider provider = SimpleAuthenticationDetailsProvider
.builder()
.tenantId(System.getenv().get("TENANCY"))
.userId(System.getenv().get("USER"))
.fingerprint(System.getenv().get("FINGERPRINT"))
.passPhrase(System.getenv().get("PASSPHRASE"))
.privateKeySupplier(privateKeySupplier)
.build();
objStoreClient = new ObjectStorageClient(provider);
View auth.java
String privateKey = System.getenv().get("OCI_PRIVATE_KEY_FILE_NAME");
Supplier<InputStream> privateKeySupplier = () -> {
InputStream is = null;
String ociPrivateKeyPath = "/function/" + privateKey;
System.err.println("Private key location - " + ociPrivateKeyPath);
try {
is = new FileInputStream(ociPrivateKeyPath);
} catch (FileNotFoundException ex) {
System.err.println("Problem accessing OCI private key at " + ociPrivateKeyPath + " - " + ex.getMessage());