Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
91pavan committed Dec 15, 2022
0 parents commit cfc6c29
Show file tree
Hide file tree
Showing 23 changed files with 2,363 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
75 changes: 75 additions & 0 deletions .github/workflows/passthrough-connector-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: passthrough-connector CI

on:
push:
branches:
- main
- 'releases/**'
tags:
- '*'
pull_request:
branches:
- main
- 'releases/**'
- '*'

env:
REGISTRY: docker.io
IMAGE_NAME: ${{ secrets.DOCKER_REPO }}/${{ github.event.repository.name }}

jobs:
test:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...


deploy:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags')
steps:
- name: Extract Version
id: version_step
run: |
echo "##[set-output name=version;]VERSION=${GITHUB_REF#$"refs/tags/v"}"
echo "##[set-output name=version_tag;]$GITHUB_REPOSITORY:${GITHUB_REF#$"refs/tags/v"}"
echo "##[set-output name=latest_tag;]$GITHUB_REPOSITORY:latest"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'amd64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Project
.project
.settings
.vscode
.idea

# Dependencies
vendor/
vendors/

# Coverage Reports
reports/
coverage.out
coverage.html
coverage.txt
junitFormatReport.xml

# Executable
go-mux-jwt
main

# mac crap
.DS_Store

# livereload helper
gin-bin

# Logs
logs

*.log

# Runtime data
pids
*.pid
*.seed
swag

# Node Modules
node_modules/
package*.json

# Openapi generation for connector endpoints. We don't need it as we're acting as a true proxy.
docs/

14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM docker.io/golang:alpine as builder
RUN apk add git
RUN mkdir /build
ADD . /build/
WORKDIR /build
RUN rm /build/go.sum
RUN go mod tidy
RUN go build -o passthrough-connector .
FROM docker.io/alpine
RUN adduser -S -D -H -h /app appuser
USER appuser
COPY --from=builder /build/passthrough-connector /app/
WORKDIR /app
CMD ["./passthrough-connector"]
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
BINARY_NAME=passthrough-connector

hello:
echo "hello"

build:
GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME}-darwin main.go
GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME}-linux main.go

compile:
echo "Compiling for every OS and Platform"
GOOS=linux GOARCH=arm go build -o bin/${BINARY_NAME}-linux-arm main.go
GOOS=linux GOARCH=arm64 go build -o bin/${BINARY_NAME}-linux-arm64 main.go
GOOS=freebsd GOARCH=386 go build -o bin/${BINARY_NAME}-freebsd-386 main.go


clean:
echo "execute this command to clean up the binaries generated"
go clean
rm ${BINARY_NAME}-darwin
rm ${BINARY_NAME}-linux

test:
go test ./...

test_coverage:
go test ./... -coverprofile=coverage.out

dep:
go mod download

vet:
go vet

all: hello build

52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Kosha Passthrough Connector

The passthrough connector APIs allow you to perform 'RESTful' operations such as reading, modifying, adding or deleting data from the service of your choice. The APIs also support Cross-Origin Resource Sharing (CORS).

It currently supports 2 forms of authentication.

1. Basic Auth (i.e., std username/password, sent via request headers)
2. API Keys (sent via request headers)

![Passthrough](images/passthrough.jpg)

This Connector API exposes REST API endpoints to perform any operations on any third-party API in a simple, quick and intuitive fashion.

It describes various API operations, related request and response structures, and error codes.

## Build

To build the project binary, run
```
go build -o main .
```

## Run locally

To run the project, simply provide env variables to supply the API key and Freshdesk domain name.


```bash
go build -o main .
API_KEY=<API_KEY> DOMAIN_NAME=<DOMAIN_NAME> ./main
```

This will start a worker and expose the API on port `8012` on the host machine

Swagger docs is available at `https://localhost:8012/docs`

## Generating Swagger Documentation

To generate `swagger.json` and `swagger.yaml` files based on the API documentation, simple run -

```bash
go install github.com/swaggo/swag/cmd/swag@latest
swag init -g main.go --parseDependency --parseInternal
```

To generate OpenAPISpec version 3 from Swagger 2.0 specification, run -

```bash
npm i api-spec-converter
npx api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=json ./docs/swagger.json > openapi.json
```
1 change: 1 addition & 0 deletions connector_spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
46 changes: 46 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module github.com/kosha/passthrough-connector

go 1.18

require (
github.com/getkin/kin-openapi v0.110.0
github.com/gorilla/mux v1.8.0
github.com/prometheus/client_golang v1.12.2
github.com/stretchr/testify v1.8.1
github.com/swaggo/http-swagger v1.3.0
github.com/swaggo/swag v1.8.3
go.uber.org/zap v1.21.0
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/invopop/yaml v0.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/tools v0.1.10 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit cfc6c29

Please sign in to comment.