Skip to content

Commit

Permalink
Merge pull request #2 from rzrbld/feature/next-release
Browse files Browse the repository at this point in the history
Feature/next release
  • Loading branch information
rzrbld authored Mar 21, 2020
2 parents b980cd0 + 5162a8b commit 546cfe0
Show file tree
Hide file tree
Showing 24 changed files with 1,596 additions and 468 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.DS_Store
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13-alpine
FROM golang:1.14-alpine

LABEL maintainer="rzrbld <[email protected]>"

Expand All @@ -9,10 +9,9 @@ ENV GOPROXY https://proxy.golang.org

RUN \
apk add --no-cache git && \
git clone https://github.com/minio/minio && cd minio/ && git checkout d4dcf1d7225a38ecf94abe7cbe7c69a93dc7c0b0 && cd pkg/madmin/examples/ && \
git clone https://github.com/rzrbld/adminio-api && go build adminio-api/src/main.go && cp main /go/bin/adminio
FROM alpine:3.9

FROM alpine:3.11

EXPOSE 8080

Expand Down
12 changes: 4 additions & 8 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13-alpine
FROM golang:1.14-alpine

LABEL maintainer="rzrbld <[email protected]>"

Expand All @@ -7,15 +7,11 @@ ENV CGO_ENABLED 0
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org

RUN \
apk add --no-cache git && \
git clone https://github.com/minio/minio && cd minio/ && git checkout d4dcf1d7225a38ecf94abe7cbe7c69a93dc7c0b0 && cd pkg/madmin/examples/
ADD src /src/

COPY src/main.go minio/pkg/madmin/examples/
RUN cd /src/ && go build main.go && cp main /go/bin/adminio

RUN cd minio/pkg/madmin/examples && go build main.go && cp main /go/bin/adminio

FROM alpine:3.9
FROM alpine:3.11

EXPOSE 8080

Expand Down
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Adminio-api
This is a simple admin "REST" API for [minio](https://min.io/) s3 server.
This is a simple admin "REST" API for [minio](https://min.io/) s3 server.
Here is a Web UI for this API - [adminio-ui](https://github.com/rzrbld/adminio-ui)

### Breaking changes in 0.9 version

- env renamed: API_HOST_PORT > ADMINIO_HOST_PORT
- API version v1 is depicated and soon will be removed.

### Run full stack demo
obtain [docker-compose.yml](https://raw.githubusercontent.com/rzrbld/adminio-ui/master/docker-compose.yml) from [adminio-ui](https://github.com/rzrbld/adminio-ui) repository. And run it:
`` docker-compose -f docker-compose.yml up ``

it will bring up:

- minio server on 9000 port
- minio server on 9000 port
- adminio API on 8080 port
- adminio UI on 80 port

Expand All @@ -25,10 +30,41 @@ after that you can go to `` http://localhost `` and try out
### Env variables
| Variable | Description | Default |
|--------------|:-----------------------:|-----------:|
| API_HOST_PORT | which host and port API should listening. This is Iris based API, so you will need to provide 0.0.0.0:8080 for listening on all interfaces | localhost:8080 |
| MINIO_HOST_PORT | provide a minio server host and port | localhost:9000 |
| MINIO_SSL | enable or disable ssl | false |
| MINIO_REGION | set minio region | us-east-1 |
| MINIO_ACCESS | set minio Access Key | test |
| MINIO_SECRET | set minio Secret Key | testtest123 |
| ADMINIO_CORS_DOMAIN | set adminio-api CORS policy domain | * |
| `ADMINIO_HOST_PORT` | which host and port API should listening. This is Iris based API, so you will need to provide 0.0.0.0:8080 for listening on all interfaces | localhost:8080 |
| `MINIO_HOST_PORT` | provide a minio server host and port | localhost:9000 |
| `MINIO_SSL` | enable or disable ssl | false |
| `MINIO_REGION` | set minio region | us-east-1 |
| `MINIO_ACCESS` | set minio Access Key | test |
| `MINIO_SECRET` | set minio Secret Key | testtest123 |
| `ADMINIO_CORS_DOMAIN` | set adminio-api CORS policy domain | * |
| `ADMINIO_OAUTH_ENABLE` | enable oauth over supported providers | false |
| `ADMINIO_OAUTH_PROVIDER` | oauth provider, for more information see the full list of supported providers | github |
| `ADMINIO_OAUTH_CLIENT_ID` | oauth app client id | my-github-oauth-app-client-id |
| `ADMINIO_OAUTH_CLIENT_SECRET` | oauth app secret | my-github-oauth-app-secret |
| `ADMINIO_OAUTH_CALLBACK` | oauth callback, default listener on /auth/callback | http://"+ADMINIO_HOST_PORT+"/auth/callback |
| `ADMINIO_OAUTH_CUSTOM_DOMAIN` | oauth custom domain, for supported providers (auth0\wso2) | - |
| `ADMINIO_COOKIE_HASH_KEY` | hash key for session cookies. AES only supports key sizes of 16, 24 or 32 bytes | NRUeuq6AdskNPa7ewZuxG9TrDZC4xFat |
| `ADMINIO_COOKIE_BLOCK_KEY` | block key for session cookies. AES only supports key sizes of 16, 24 or 32 bytes | bnfYuphzxPhJMR823YNezH83fuHuddFC |
| `ADMINIO_COOKIE_NAME` | name for the session cookie | adminiosessionid |
| `ADMINIO_AUDIT_LOG_ENABLE` | enable audit log, mae sense if oauth is enabled, othervise set to false | false |
| `ADMINIO_METRICS_ENABLE` | enable default iris\golang metrics and bucket sizes metric on /metric/ uri path | false |

### Supported oauth providers

- amazon
- auth0
- bitbucket
- box
- digitalocean
- dropbox
- github
- gitlab
- heroku
- onedrive
- salesforce
- slack
- wso2

### example config
prometheus config: `examples/prometheus.yml`
bucket policy: `examples/policy.xml`
Binary file removed dist/main
Binary file not shown.
13 changes: 13 additions & 0 deletions examples/policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<LifecycleConfiguration>
<Rule>
<ID>expire-bucket</ID>
<Status>Enabled</Status>
<Filter>
<And></And>
<Tag></Tag>
</Filter>
<Expiration>
<Days>1</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
6 changes: 6 additions & 0 deletions examples/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scrape_configs:
- job_name: adminio
metrics_path: /metrics
scheme: http
static_configs:
- targets: ['adminio-host:8080']
15 changes: 15 additions & 0 deletions src/audit/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package audit

import (
iris "github.com/kataras/iris/v12"
"github.com/markbates/goth"
cnf "github.com/rzrbld/adminio-api/config"
log "log"
)

func DefaultAuditLog(user goth.User, ctx iris.Context) {
ctx.ViewData("", user)
if cnf.AuditLogEnable {
log.Print("userNickName: ", user.NickName, "; userID: ", user.UserID, "; method:", ctx.RouteName())
}
}
21 changes: 21 additions & 0 deletions src/clients/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package clients

import (
minio "github.com/minio/minio-go/v6"
madmin "github.com/minio/minio/pkg/madmin"
cnf "github.com/rzrbld/adminio-api/config"
"log"
)

var MadmClnt, MadmErr = madmin.New(cnf.Server, cnf.Maccess, cnf.Msecret, cnf.Ssl)
var MinioClnt, MinioErr = minio.New(cnf.Server, cnf.Maccess, cnf.Msecret, cnf.Ssl)

func main() {
if MadmErr != nil {
log.Fatal("Error while connecting via admin client ", MadmErr)
}

if MinioErr != nil {
log.Fatal("Error while connecting via minio client ", MinioErr)
}
}
40 changes: 40 additions & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package config

import (
"os"
strconv "strconv"
)

var (
Server = getEnv("MINIO_HOST_PORT", "localhost:9000")
Maccess = getEnv("MINIO_ACCESS", "test")
Msecret = getEnv("MINIO_SECRET", "testtest123")
Region = getEnv("MINIO_REGION", "us-east-1")
Ssl, _ = strconv.ParseBool(getEnv("MINIO_SSL", "false"))
ServerHostPort = getEnv("ADMINIO_HOST_PORT", "localhost:8080")
AdminioCORS = getEnv("ADMINIO_CORS_DOMAIN", "*")
// AES only supports key sizes of 16, 24 or 32 bytes.
// You either need to provide exactly that amount or you derive the key from what you type in.
ScHashKey = getEnv("ADMINIO_COOKIE_HASH_KEY", "NRUeuq6AdskNPa7ewZuxG9TrDZC4xFat")
ScBlockKey = getEnv("ADMINIO_COOKIE_BLOCK_KEY", "bnfYuphzxPhJMR823YNezH83fuHuddFC")
// ---------------
ScCookieName = getEnv("ADMINIO_COOKIE_NAME", "adminiosessionid")
OauthEnable, _ = strconv.ParseBool(getEnv("ADMINIO_OAUTH_ENABLE", "false"))
AuditLogEnable, _ = strconv.ParseBool(getEnv("ADMINIO_AUDIT_LOG_ENABLE", "false"))
MetricsEnable, _ = strconv.ParseBool(getEnv("ADMINIO_METRICS_ENABLE", "false"))
OauthProvider = getEnv("ADMINIO_OAUTH_PROVIDER", "github")
OauthClientId = getEnv("ADMINIO_OAUTH_CLIENT_ID", "my-github-oauth-app-client-id")
OauthClientSecret = getEnv("ADMINIO_OAUTH_CLIENT_SECRET", "my-github-oauth-app-secret")
OauthCallback = getEnv("ADMINIO_OAUTH_CALLBACK", "http://"+ServerHostPort+"/auth/callback")
OauthCustomDomain = getEnv("ADMINIO_OAUTH_CUSTOM_DOMAIN", "")
)

func getEnv(key, fallback string) string {
value, exist := os.LookupEnv(key)

if !exist {
return fallback
}

return value
}
35 changes: 35 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module github.com/rzrbld/adminio-api

go 1.14

require (
github.com/ajg/form v1.5.1 // indirect
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gorilla/securecookie v1.1.1
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/iris-contrib/middleware/cors v0.0.0-20191219204441-78279b78a367
github.com/iris-contrib/middleware/prometheus v0.0.0-20191219204441-78279b78a367
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/kataras/iris/v12 v12.1.8
github.com/markbates/goth v1.62.0
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/minio/minio v0.0.0-20200315185552-c9212819afbf
github.com/minio/minio-go/v6 v6.0.50-0.20200306231101-b882ba63d570
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/prometheus/client_golang v1.2.1
github.com/rzrbld/goth-provider-wso2 v0.0.0-20200321083654-32bbe73a67d4
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/valyala/fasthttp v1.9.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/net v0.0.0-20200320220750-118fecf932d8 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading

0 comments on commit 546cfe0

Please sign in to comment.