Skip to content

Instantly share code, notes, and snippets.

View abhirockzz's full-sized avatar
👋
fmt.Println(hello, world!)

Abhishek Gupta abhirockzz

👋
fmt.Println(hello, world!)
View GitHub Profile
slackResponse := SlackResponse{Text: slackResponseStaticText, Attachments: []Attachment{Attachment{Text: title, ImageURL: url}}}
fdk.AddHeader(out, "Content-Type", "application/json")
json.NewEncoder(out).Encode(slackResponse)
...
vals, err := parse(b)
if err != nil {
fmt.Println("unable to parse data sent by slack", err)
}
giphyTag := vals.Get("text")
...
func parse(b []byte) (url.Values, error) {
vals, e := url.ParseQuery(string(b))
if e != nil {
...
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)
...
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))
...
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)
func main() {
fdk.Handle(fdk.HandlerFunc(funcy))
}
func funcy(ctx context.Context, in io.Reader, out io.Writer) {
....
}
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
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)
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)
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)