This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
slackResponse := SlackResponse{Text: slackResponseStaticText, Attachments: []Attachment{Attachment{Text: title, ImageURL: url}}} | |
fdk.AddHeader(out, "Content-Type", "application/json") | |
json.NewEncoder(out).Encode(slackResponse) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
fdk.Handle(fdk.HandlerFunc(funcy)) | |
} | |
func funcy(ctx context.Context, in io.Reader, out io.Writer) { | |
.... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |