Coder Social home page Coder Social logo

kruzio / exodus Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 159 KB

Export file(s) to external targets easily

License: Apache License 2.0

Makefile 6.52% Go 80.41% Shell 12.75% Dockerfile 0.32%
slack s3 s3-bucket azure-blob azure-storage webhook webhook-client gcp-bucket gcp-storage mail smtp sendfile export exporter filesender kubernetes k8s library golang

exodus's Introduction

release Go Version Release codecov License Tweet

logo

exodus

  • Export file(s) to external targets easily
  • Send Alert Notification to one or more desitnations

Supported Targets

+--------------+-------------------------------------------------------------------------------------------------------------------------------------------+
|    SCHEME    |                                                                   INFO                                                                    |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| GS           |   Upload to GCP Cloud Storage              | gs://my-bucket                                                                               |
|              |                                            | For additional information see https://gocloud.dev/howto/blob/#gcs-ctor                      |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| SLACK        |   Post file to a slack channel             | slack://mychannel?apikey=<mykey>[&file-type=json&title=mymsgtitle]                           |
|              |                                            |                                                                                              |
|              |   apikey=<mykey>                           | Slack API token - xoxo-YOURTOKEN                                                             |
|              |                                            | For additional information see https://api.slack.com/apps                                    |
|              |                                            | Note that your app must join the destintation channel                                        |
|              |   file-type=json                           | The content type                                                                             |
|              |   title=mymsgtitle                         | The notification title                                                                       |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| FILE         |   Save file to the local file system using | file:///path/to/dir                                                                          |
|              |                                            | The filename will be the same as name of the inout file name                                 |
|              |                                            | For additional information see https://gocloud.dev/howto/blob/#local                         |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| WEBHOOK+HTTP |   Post file to a webhook                   | For example: webhook+http://myserver?x-headers=X-myheader:myval&token-bearer=1234            |
|              |                                            |                                                                                              |
|              |   >> Authentication Options <<             |                                                                                              |
|              |   token-bearer=<token>                     | Support Authorization Bearer token based authentication                                      |
|              |   username=<username>                      | Basic HTTP Authentication scheme                                                             |
|              |   password=<password>                      | Basic HTTP Authentication scheme                                                             |
|              |                                            |                                                                                              |
|              |   >> Additional Options <<                 |                                                                                              |
|              |   proxy-url=<proxy>                        | The proxy URL the webhook client should connect to                                           |
|              |   content-type=<contentType>               | defaults to json and can be one of: json | text | xml | html | multipart                     |
|              |   x-headers=k1:v1,k2:v2                    | additional custom request headers                                                            |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| WEBHOOK      |   Post file to a webhook                   | For example: webhook://myserver?x-headers=X-myheader:myval&token-bearer=1234                 |
|              |                                            |                                                                                              |
|              |   >> Authentication Options <<             |                                                                                              |
|              |   token-bearer=<token>                     | Support Authorization Bearer token based authentication                                      |
|              |   username=<username>                      | Basic HTTP Authentication scheme                                                             |
|              |   password=<password>                      | Basic HTTP Authentication scheme                                                             |
|              |                                            |                                                                                              |
|              |   >> Additional Options <<                 |                                                                                              |
|              |   proxy-url=<proxy>                        | The proxy URL the webhook client should connect to                                           |
|              |   content-type=<contentType>               | defaults to json and can be one of: json | text | xml | html | multipart                     |
|              |   x-headers=k1:v1,k2:v2                    | additional custom request headers                                                            |
|              |                                            |                                                                                              |
|              |   >> TLS Options <<                        |                                                                                              |
|              |   skip-verify=true                         | If one wished to allow connection to untrusted server                                        |
|              |   ca-file=<path-to-file>                   | CA PEM file                                                                                  |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| SMTP         |   Send file via email (smtp)               | smtp://smtpserver?to=<email>&from=<email>&username=myuser&password=mypass                    |
|              |                                            |                                                                                              |
|              |   to=<target>[,<target>]                   | the destination email address(es) - required                                                 |
|              |   from=<from-email>                        | From email address - required                                                                |
|              |   username=<username>                      | The smtp server authentication information - required                                        |
|              |   password=<password>                      | The smtp server authentication information - required                                        |
|              |                                            |                                                                                              |
|              |   subject=<subject>                        | The Subject line of the email message                                                        |
|              |   skip-verify=true                         | Skip SMTP server TLS verification - (not recommended)                                        |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| S3           |   Upload to AWS S3 bucket                  | s3://bucket-name/subdir?region=us-west-1                                                     |
|              |                                            | For additional information see https://gocloud.dev/howto/blob/#s3                            |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
| AZBLOB       |   Upload to Azure Blob storage             | azblob://my-container                                                                        |
|              |                                            | For additional information see https://gocloud.dev/howto/blob/#azure                         |
|              | -------------------------------------------+--------------------------------------------------------------------------------------------- |
|              |                                                                                                                                           |
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------+

Using Exodus as Library

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/kruzio/exodus/pkg/sendfile"
)

func main() {
	data, err := ioutil.ReadFile("somefile.json")

	if err != nil {
		os.Exit(255)
	}

	//Let's create our client
	uploadUrl := fmt.Sprintf("webhook://dest.io?skip-verify=true&x-headers=X-myheader:myval&token-bearer=1234")

	uploader, err := sendfile.NewUploader(uploadUrl)
	if err != nil {
		os.Exit(255)
	}

	_ = uploader.SetDestName("somefile")

	err = uploader.Export([]byte(data))
	if err != nil {
		os.Exit(255)
	}
}

Using Exodus as an add-on

# Send to Slack
echo myfilecontent | exodus sendfile -f -  --target="slack://mychannel?apikey=xoxb-myslackapp-oauth-token&title=My File"

# Send files from a watch directory (one shot)
exodus sendfile  --target=webhook+http://localhost:8080/stuff?content-type=text --watch /tmp/exodus

# Send files from a watch directory (forever)
exodus sendfile  --target=webhook+http://localhost:8080/stuff?content-type=text --watch /tmp/exodus --watch-forever

Using Exodus in Kubernetes

kind: Namespace
metadata:
  name: exodus
---
apiVersion: v1
kind: Secret
metadata:
  name: export-targets
  namespace: exodus
type: Opaque
data:
  # printf "webhook://dest.io?skip-verify=true&token-bearer=1234&content-type=text" | base64
  targets: d2ViaG9vazovL2Rlc3QuaW8/c2tpcC12ZXJpZnk9dHJ1ZSZ0b2tlbi1iZWFyZXI9MTIzNCZjb250ZW50LXR5cGU9dGV4dA==
---
apiVersion: batch/v1
kind: Job
metadata:
  name: example
  namespace: exodus
  labels:
    app.kubernetes.io/name: exodus-example
    app.kubernetes.io/instance: example
    app.kubernetes.io/version: "1.0.0"
spec:
  backoffLimit: 1
  template:
    spec:
      # Pod Security
      automountServiceAccountToken: false
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000590000
        runAsGroup: 1000590000
        fsGroup: 1000590000

      volumes:
        # Our Send Box
        - name: sendbox
          emptyDir: {}
      containers:
        - name: exodus
          image: kruzio/exodus:v0.2.0
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: /sendbox
              name: sendbox
          args:
            - "sendfile"
            - "--watch"
            - "/sendbox"
            - "--watch-forever"
            - "false"
            # Debugging
            #- "-v"
            #- "7"

          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - ALL
          env:
            - name: KRUZIO_EXODUS_SENDFILE_TARGETS
              valueFrom:
                secretKeyRef:
                  name: export-targets
                  key: targets
        - name: producer
          image: busybox:latest
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: /sendbox
              name: sendbox
          command: ["/bin/sh"]
          args:
              - -c
              - "sleep 3 && echo hello > /sendbox/file-to-send.txt && sleep 3 && ls -la /sendbox/ && exit 0"
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - ALL
      restartPolicy: Never

Contributing

Bugs

If you think you have found a bug please follow the instructions below.

  • Please spend a small amount of time giving due diligence to the issue tracker. Your issue might be a duplicate.
  • Open a new issue if a duplicate doesn't already exist.

Features

If you have an idea to enhance exodus follow the steps below.

  • Open a new issue.
  • Remember users might be searching for your issue in the future, so please give it a meaningful title to helps others.
  • Clearly define the use case, using concrete examples.
  • Feel free to include any technical design for your feature.

Pull Requests

  • Your PR is more likely to be accepted if it focuses on just one change.
  • Please include a comment with the results before and after your change.
  • Your PR is more likely to be accepted if it includes tests.
  • You're welcome to submit a draft PR if you would like early feedback on an idea or an approach.

Stargazers over time

exodus's People

Contributors

gadinaor-r7 avatar thekruzer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.