Embed phoenix and serve it
So far Phoenix have been embedded into the binary and we can customize the required config based on flags, env variables and optionally via config file. For now I'm embedding the whole Phonix content, optherwise the all-in-one binary `ocis` will get pretty complicated until we add the generate commands to that repo as well and provide a mechanism to inject the embedding.
This commit is contained in:
@@ -2,3 +2,5 @@ coverage.out
|
||||
|
||||
/bin
|
||||
/dist
|
||||
|
||||
/phoenix
|
||||
|
||||
@@ -14,7 +14,7 @@ endif
|
||||
|
||||
PACKAGES ?= $(shell go list ./...)
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
GENERATE ?= $(PACKAGES)
|
||||
GENERATE ?= $(IMPORT)/pkg/assets
|
||||
|
||||
TAGS ?=
|
||||
|
||||
@@ -50,7 +50,7 @@ sync:
|
||||
.PHONY: clean
|
||||
clean:
|
||||
go clean -i ./...
|
||||
rm -rf $(BIN) $(DIST)
|
||||
rm -rf $(BIN) $(DIST) phoenix/
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
@@ -69,7 +69,7 @@ lint: gorunpkg
|
||||
for PKG in $(PACKAGES); do gorunpkg golang.org/x/lint/golint -set_exit_status $$PKG || exit 1; done;
|
||||
|
||||
.PHONY: generate
|
||||
generate: gorunpkg
|
||||
generate: gorunpkg phoenix
|
||||
go generate $(GENERATE)
|
||||
|
||||
.PHONY: changelog
|
||||
@@ -125,3 +125,6 @@ gorunpkg:
|
||||
ifndef HAS_GORUNPKG
|
||||
go get -u github.com/vektah/gorunpkg
|
||||
endif
|
||||
|
||||
phoenix:
|
||||
mkdir phoenix/ && curl -slL -o- https://github.com/owncloud/phoenix/releases/download/0.2.0/phoenix.tar.gz | tar xvzf - -C phoenix/
|
||||
|
||||
+19
-4
@@ -1,8 +1,23 @@
|
||||
---
|
||||
server:
|
||||
addr: 0.0.0.0:8080
|
||||
|
||||
metrics:
|
||||
debug:
|
||||
addr: 0.0.0.0:8090
|
||||
token:
|
||||
pprof: false
|
||||
|
||||
http:
|
||||
addr: 0.0.0.0:8080
|
||||
root: /
|
||||
|
||||
asset:
|
||||
path:
|
||||
|
||||
config:
|
||||
custom:
|
||||
server:
|
||||
theme: owncloud
|
||||
version: 0.1.0
|
||||
client:
|
||||
apps:
|
||||
- files
|
||||
|
||||
...
|
||||
|
||||
@@ -3,9 +3,14 @@ module github.com/owncloud/ocis-phoenix
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/UnnoTed/fileb0x v1.1.3 // indirect
|
||||
github.com/go-chi/chi v4.0.2+incompatible
|
||||
github.com/haya14busa/goverage v0.0.0-20180129164344-eec3514a20b5 // indirect
|
||||
github.com/oklog/run v1.0.0
|
||||
github.com/prometheus/client_golang v0.9.3
|
||||
github.com/restic/calens v0.0.0-20190419101620-10f36cb4a529 // indirect
|
||||
github.com/rs/zerolog v1.15.0
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/viper v1.4.0
|
||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092
|
||||
)
|
||||
|
||||
@@ -2,11 +2,18 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/UnnoTed/fileb0x v1.1.3 h1:TUfJRey+psXuivBqasgp7Du3iXB4hzjI5UXDl+BCrzE=
|
||||
github.com/UnnoTed/fileb0x v1.1.3/go.mod h1:AyTnLP7elx6MM4eHxahl5sBEWBw0QLf6TM/s64LtM4s=
|
||||
github.com/airking05/termui v2.2.0+incompatible h1:S3j2WJzr70u8KjUktaQ0Cmja+R0edOXChltFoQSGG8I=
|
||||
github.com/airking05/termui v2.2.0+incompatible/go.mod h1:B/M5sgOwSZlvGm3TsR98s1BSzlSH4wPQzUUNwZG+uUM=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ=
|
||||
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
@@ -23,6 +30,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
|
||||
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
@@ -34,6 +43,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -49,6 +59,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/karrick/godirwalk v1.7.8 h1:VfG72pyIxgtC7+3X9CMHI0AOl4LwyRAg98WAgsvffi8=
|
||||
github.com/karrick/godirwalk v1.7.8/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
@@ -58,32 +70,57 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/labstack/echo v3.2.1+incompatible h1:J2M7YArHx4gi8p/3fDw8tX19SXhBCoRpviyAZSN3I88=
|
||||
github.com/labstack/echo v3.2.1+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
||||
github.com/labstack/gommon v0.2.7 h1:2qOPq/twXDrQ6ooBGrn3mrmVOC+biLlatwgIu8lbzRM=
|
||||
github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
||||
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/maruel/panicparse v1.1.1 h1:k62YPcEoLncEEpjMt92GtG5ugb8WL/510Ys3/h5IkRc=
|
||||
github.com/maruel/panicparse v1.1.1/go.mod h1:nty42YY5QByNC5MM7q/nj938VbgPU7avs45z6NClpxI=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
|
||||
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e h1:fvw0uluMptljaRKSU8459cJ4bmi3qUYyMs5kzpic2fY=
|
||||
github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8=
|
||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/common v0.4.0 h1:7etb9YClo3a6HjLzfl6rIQaU+FDfi0VSX39io3aQ+DM=
|
||||
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084 h1:sofwID9zm4tzrgykg80hfFph1mryUeLRsUfoocVVmRY=
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/restic/calens v0.0.0-20190419101620-10f36cb4a529 h1:TPB3vbGNwppek0lcfpKG8rVRtvr5D78d/1MnlbfNfgA=
|
||||
github.com/restic/calens v0.0.0-20190419101620-10f36cb4a529/go.mod h1:I3AyHROuWXtWtZtI5ApjLbnN0si15sWvPQO7ul4gDow=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
@@ -110,23 +147,32 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/zenazn/goji v0.9.0 h1:RSQQAbXGArQ0dIDEq+PI6WqN6if+5KHu6x2Cx/GXLTQ=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180921000356-2f5d2388922f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
|
||||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -135,6 +181,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
//go:generate gorunpkg github.com/UnnoTed/fileb0x embed.yml
|
||||
|
||||
// assets gets initialized by New and provides the handler.
|
||||
type assets struct {
|
||||
path string
|
||||
}
|
||||
|
||||
// Open just implements the HTTP filesystem interface.
|
||||
func (a assets) Open(original string) (http.File, error) {
|
||||
if a.path != "" {
|
||||
if stat, err := os.Stat(a.path); err == nil && stat.IsDir() {
|
||||
custom := path.Join(
|
||||
a.path,
|
||||
original,
|
||||
)
|
||||
|
||||
if _, err := os.Stat(custom); !os.IsNotExist(err) {
|
||||
f, err := os.Open(custom)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
} else {
|
||||
log.Warn().
|
||||
Msg("Assets directory doesn't exist")
|
||||
}
|
||||
}
|
||||
|
||||
return FS.OpenFile(
|
||||
CTX,
|
||||
original,
|
||||
os.O_RDONLY,
|
||||
0644,
|
||||
)
|
||||
}
|
||||
|
||||
// New returns a new http filesystem to serve assets.
|
||||
func New(opts ...Option) http.FileSystem {
|
||||
a := new(assets)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(a)
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
// Fake the import to make the dep tree happy.
|
||||
_ "golang.org/x/net/context"
|
||||
|
||||
// Fake the import to make the dep tree happy.
|
||||
_ "golang.org/x/net/webdav"
|
||||
)
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,23 @@
|
||||
---
|
||||
pkg: "assets"
|
||||
dest: "."
|
||||
output: "embed.go"
|
||||
fmt: true
|
||||
noprefix: true
|
||||
|
||||
compression:
|
||||
compress: true
|
||||
|
||||
custom:
|
||||
- files:
|
||||
- "../../phoenix/"
|
||||
base: "../../phoenix/"
|
||||
prefix: ""
|
||||
exclude:
|
||||
- "appinfo/**"
|
||||
- "LICENSE/**"
|
||||
- "CHANGELOG.md"
|
||||
- "README.md"
|
||||
- "config.json"
|
||||
|
||||
...
|
||||
@@ -0,0 +1,11 @@
|
||||
package assets
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*assets)
|
||||
|
||||
// WithPath returns an option to set custom assets path.
|
||||
func WithPath(val string) Option {
|
||||
return func(a *assets) {
|
||||
a.path = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// init defined the default options for viper.
|
||||
func init() {
|
||||
viper.SetDefault("debug.addr", "0.0.0.0:8090")
|
||||
viper.SetDefault("debug.token", "")
|
||||
viper.SetDefault("debug.pprof", false)
|
||||
|
||||
viper.SetDefault("http.addr", "0.0.0.0:8080")
|
||||
viper.SetDefault("http.root", "/")
|
||||
|
||||
viper.SetDefault("asset.path", "")
|
||||
|
||||
viper.SetDefault("config.custom", "")
|
||||
viper.SetDefault("config.server", "")
|
||||
viper.SetDefault("config.theme", "owncloud")
|
||||
viper.SetDefault("config.version", "0.1.0")
|
||||
viper.SetDefault("config.client", "")
|
||||
viper.SetDefault("config.apps", []string{"files"})
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
viper.SetDefault("server.addr", "0.0.0.0:8080")
|
||||
viper.SetDefault("metrics.addr", "0.0.0.0:8090")
|
||||
}
|
||||
@@ -14,14 +14,14 @@ func Health() *cobra.Command {
|
||||
Long: "",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Info().
|
||||
Str("addr", viper.GetString("metrics.addr")).
|
||||
Str("addr", viper.GetString("debug.addr")).
|
||||
Msg("Executed health command")
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String("metrics-addr", "", "Address to metrics endpoint")
|
||||
viper.BindPFlag("metrics.addr", cmd.Flags().Lookup("metrics-addr"))
|
||||
viper.BindEnv("metrics.addr", "PHOENIX_METRICS_ADDR")
|
||||
cmd.Flags().String("debug-addr", "", "Address to debug endpoint")
|
||||
viper.BindPFlag("debug.addr", cmd.Flags().Lookup("debug-addr"))
|
||||
viper.BindEnv("debug.addr", "PHOENIX_DEBUG_ADDR")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func Root() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// setupLogger prepares the logger.
|
||||
func setupLogger() {
|
||||
switch strings.ToLower(viper.GetString("log.level")) {
|
||||
case "panic":
|
||||
@@ -73,6 +74,7 @@ func setupLogger() {
|
||||
}
|
||||
}
|
||||
|
||||
// setupConfig prepares the config
|
||||
func setupConfig() {
|
||||
viper.SetConfigName("phoenix")
|
||||
|
||||
@@ -84,7 +86,7 @@ func setupConfig() {
|
||||
switch err.(type) {
|
||||
case viper.ConfigFileNotFoundError:
|
||||
log.Debug().
|
||||
Msg("Continue without config")
|
||||
Msg("Initializing without config file")
|
||||
case viper.UnsupportedConfigError:
|
||||
log.Fatal().
|
||||
Msg("Unsupported config type")
|
||||
+150
-7
@@ -1,6 +1,15 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/router/debug"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/router/server"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -12,16 +21,150 @@ func Server() *cobra.Command {
|
||||
Use: "server",
|
||||
Short: "Start integrated server",
|
||||
Long: "",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
log.Info().
|
||||
Str("addr", viper.GetString("server.addr")).
|
||||
Msg("Executed server command")
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var gr run.Group
|
||||
|
||||
{
|
||||
server := &http.Server{
|
||||
Addr: viper.GetString("debug.addr"),
|
||||
Handler: debug.Router(
|
||||
debug.WithToken(viper.GetString("debug.token")),
|
||||
debug.WithPprof(viper.GetBool("debug.pprof")),
|
||||
),
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
gr.Add(func() error {
|
||||
log.Info().
|
||||
Str("addr", viper.GetString("debug.addr")).
|
||||
Msg("Starting debug server")
|
||||
|
||||
return server.ListenAndServe()
|
||||
}, func(reason error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("Failed to shutdown debug server gracefully")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Err(reason).
|
||||
Msg("Shutdown debug server gracefully")
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
server := &http.Server{
|
||||
Addr: viper.GetString("http.addr"),
|
||||
Handler: server.Router(
|
||||
server.WithRoot(viper.GetString("http.root")),
|
||||
server.WithPath(viper.GetString("asset.path")),
|
||||
server.WithCustom(viper.GetString("config.custom")),
|
||||
server.WithServer(viper.GetString("config.server")),
|
||||
server.WithTheme(viper.GetString("config.theme")),
|
||||
server.WithVersion(viper.GetString("config.version")),
|
||||
server.WithClient(viper.GetString("config.client")),
|
||||
server.WithApps(viper.GetStringSlice("config.apps")),
|
||||
),
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
gr.Add(func() error {
|
||||
log.Info().
|
||||
Str("addr", viper.GetString("http.addr")).
|
||||
Msg("Starting http server")
|
||||
|
||||
return server.ListenAndServe()
|
||||
}, func(reason error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("Failed to shutdown http server gracefully")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Err(reason).
|
||||
Msg("Shutdown http server gracefully")
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
stop := make(chan os.Signal, 1)
|
||||
|
||||
gr.Add(func() error {
|
||||
signal.Notify(stop, os.Interrupt)
|
||||
|
||||
<-stop
|
||||
|
||||
return nil
|
||||
}, func(err error) {
|
||||
close(stop)
|
||||
})
|
||||
}
|
||||
|
||||
return gr.Run()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String("server-addr", "", "Address to bind the server")
|
||||
viper.BindPFlag("server.addr", cmd.Flags().Lookup("server-addr"))
|
||||
viper.BindEnv("server.addr", "PHOENIX_SERVER_ADDR")
|
||||
cmd.Flags().String("debug-addr", "", "Address to bind debug server")
|
||||
viper.BindPFlag("debug.addr", cmd.Flags().Lookup("debug-addr"))
|
||||
viper.BindEnv("debug.addr", "PHOENIX_DEBUG_ADDR")
|
||||
|
||||
cmd.Flags().String("debug-token", "", "Token to grant metrics access")
|
||||
viper.BindPFlag("debug.token", cmd.Flags().Lookup("debug-token"))
|
||||
viper.BindEnv("debug.token", "PHOENIX_DEBUG_TOKEN")
|
||||
|
||||
cmd.Flags().Bool("debug-pprof", false, "Enable pprof debugging")
|
||||
viper.BindPFlag("debug.pprof", cmd.Flags().Lookup("debug-pprof"))
|
||||
viper.BindEnv("debug.pprof", "PHOENIX_DEBUG_PPROF")
|
||||
|
||||
cmd.Flags().String("http-addr", "", "Address to bind http server")
|
||||
viper.BindPFlag("http.addr", cmd.Flags().Lookup("http-addr"))
|
||||
viper.BindEnv("http.addr", "PHOENIX_HTTP_ADDR")
|
||||
|
||||
cmd.Flags().String("http-root", "", "Root path for http endpoint")
|
||||
viper.BindPFlag("http.root", cmd.Flags().Lookup("http-root"))
|
||||
viper.BindEnv("http.root", "PHOENIX_HTTP_ROOT")
|
||||
|
||||
cmd.Flags().String("asset-path", "", "Path to custom assets")
|
||||
viper.BindPFlag("asset.path", cmd.Flags().Lookup("asset-path"))
|
||||
viper.BindEnv("asset.path", "PHOENIX_ASSET_PATH")
|
||||
|
||||
cmd.Flags().String("config-custom", "", "Path to custom config")
|
||||
viper.BindPFlag("config.custom", cmd.Flags().Lookup("config-custom"))
|
||||
viper.BindEnv("config.custom", "PHOENIX_CONFIG_CUSTOM")
|
||||
|
||||
cmd.Flags().String("config-server", "", "URL to ownCloud server")
|
||||
viper.BindPFlag("config.server", cmd.Flags().Lookup("config-server"))
|
||||
viper.BindEnv("config.server", "PHOENIX_CONFIG_SERVER")
|
||||
|
||||
cmd.Flags().String("config-theme", "", "The to use with Phoenix")
|
||||
viper.BindPFlag("config.theme", cmd.Flags().Lookup("config-theme"))
|
||||
viper.BindEnv("config.theme", "PHOENIX_CONFIG_THEME")
|
||||
|
||||
cmd.Flags().String("config-version", "", "Config version for Phoenix")
|
||||
viper.BindPFlag("config.version", cmd.Flags().Lookup("config-version"))
|
||||
viper.BindEnv("config.version", "PHOENIX_CONFIG_VERSION")
|
||||
|
||||
cmd.Flags().String("config-client", "", "Client ID used for OAuth2")
|
||||
viper.BindPFlag("config.client", cmd.Flags().Lookup("config-client"))
|
||||
viper.BindEnv("config.client", "PHOENIX_CONFIG_CLIENT")
|
||||
|
||||
cmd.Flags().StringSlice("config-apps", []string{}, "List of enabled apps")
|
||||
viper.BindPFlag("config.apps", cmd.Flags().Lookup("config-apps"))
|
||||
viper.BindEnv("config.apps", "PHOENIX_CONFIG_APPS")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrConfigInvalid is returned when the config parse is invalid.
|
||||
ErrConfigInvalid = `Invalid or missing config`
|
||||
)
|
||||
|
||||
// config gets initialized by New and provides the handler.
|
||||
type config struct {
|
||||
custom string
|
||||
server string
|
||||
theme string
|
||||
version string
|
||||
client string
|
||||
apps []string
|
||||
}
|
||||
|
||||
// auth is part of the phoenix config repsonse.
|
||||
type auth struct {
|
||||
ClientID string `json:"clientId"`
|
||||
URL string `json:"url"`
|
||||
AuthURL string `json:"authUrl"`
|
||||
}
|
||||
|
||||
// phoenix is part of the phoenix config response.
|
||||
type phoenix struct {
|
||||
Server string `json:"server"`
|
||||
Theme string `json:"theme"`
|
||||
Version string `json:"version"`
|
||||
Apps []string `json:"apps"`
|
||||
Auth auth `json:"auth"`
|
||||
}
|
||||
|
||||
// ServeHTTP just implements the http.Handler interface.
|
||||
func (c config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := c.payload()
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, ErrConfigInvalid, http.StatusUnprocessableEntity)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(resp)
|
||||
}
|
||||
|
||||
// payload prepares the phoenix config content.
|
||||
func (c config) payload() ([]byte, error) {
|
||||
if c.custom != "" {
|
||||
if _, err := os.Stat(c.custom); os.IsNotExist(err) {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("config", c.custom).
|
||||
Msg("Custom config doesn't exist")
|
||||
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
payload, err := ioutil.ReadFile(c.custom)
|
||||
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("config", c.custom).
|
||||
Msg("Failed to read custom config")
|
||||
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(phoenix{
|
||||
Server: c.server,
|
||||
Theme: c.theme,
|
||||
Version: c.version,
|
||||
Apps: c.apps,
|
||||
Auth: auth{
|
||||
ClientID: c.client,
|
||||
URL: fmt.Sprintf("%s/apps/oauth2/api/v1/token", c.server),
|
||||
AuthURL: fmt.Sprintf("%s/apps/oauth2/authorize", c.server),
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("Failed to generate config")
|
||||
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
// Handler returns the handler for config endpoint.
|
||||
func Handler(opts ...Option) http.Handler {
|
||||
c := new(config)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package config
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*config)
|
||||
|
||||
// WithServer returns an option to set server.
|
||||
func WithServer(val string) Option {
|
||||
return func(c *config) {
|
||||
c.server = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithTheme returns an option to set theme.
|
||||
func WithTheme(val string) Option {
|
||||
return func(c *config) {
|
||||
c.theme = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithVersion returns an option to set version.
|
||||
func WithVersion(val string) Option {
|
||||
return func(c *config) {
|
||||
c.version = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithClient returns an option to set client id.
|
||||
func WithClient(val string) Option {
|
||||
return func(c *config) {
|
||||
c.client = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithApps returns an option to set apps.
|
||||
func WithApps(val []string) Option {
|
||||
return func(c *config) {
|
||||
c.apps = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustom returns an option to set custom config.
|
||||
func WithCustom(val string) Option {
|
||||
return func(c *config) {
|
||||
c.custom = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidToken is returned when the request token is invalid.
|
||||
ErrInvalidToken = `Invalid or missing token`
|
||||
)
|
||||
|
||||
// metrics gets initialized by New and provides the handler.
|
||||
type metrics struct {
|
||||
token string
|
||||
}
|
||||
|
||||
// ServeHTTP just implements the http.Handler interface.
|
||||
func (m metrics) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if m.token == "" {
|
||||
promhttp.Handler().ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
header := r.Header.Get("Authorization")
|
||||
|
||||
if header == "" {
|
||||
log.Debug().
|
||||
Msg("Missing auth header")
|
||||
|
||||
http.Error(w, ErrInvalidToken, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if header != fmt.Sprintf("Bearer %s", m.token) {
|
||||
log.Debug().
|
||||
Msg("Invalid token provided")
|
||||
|
||||
http.Error(w, ErrInvalidToken, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
promhttp.Handler().ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Handler returns the handler for metrics endpoint.
|
||||
func Handler(opts ...Option) http.Handler {
|
||||
m := new(metrics)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package metrics
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*metrics)
|
||||
|
||||
// WithToken returns an option to set a token.
|
||||
func WithToken(val string) Option {
|
||||
return func(m *metrics) {
|
||||
m.token = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package static
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*static)
|
||||
|
||||
// WithRoot returns an option to set a root.
|
||||
func WithRoot(val string) Option {
|
||||
return func(s *static) {
|
||||
s.root = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithPath returns an option to set a path.
|
||||
func WithPath(val string) Option {
|
||||
return func(s *static) {
|
||||
s.path = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package static
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis-phoenix/pkg/assets"
|
||||
)
|
||||
|
||||
// static gets initialized by New and provides the handler.
|
||||
type static struct {
|
||||
root string
|
||||
path string
|
||||
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
// ServeHTTP just implements the http.Handler interface.
|
||||
func (s static) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Handler returns the handler for static endpoint.
|
||||
func Handler(opts ...Option) http.Handler {
|
||||
s := new(static)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(s)
|
||||
}
|
||||
|
||||
s.handler = http.StripPrefix(
|
||||
s.root,
|
||||
http.FileServer(
|
||||
assets.New(
|
||||
assets.WithPath(s.path),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package header
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis-phoenix/pkg/version"
|
||||
)
|
||||
|
||||
// Cache writes required cache headers to all requests.
|
||||
func Cache(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate, value")
|
||||
w.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")
|
||||
w.Header().Set("Last-Modified", time.Now().UTC().Format(http.TimeFormat))
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// Options writes required option headers to all requests.
|
||||
func Options(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "OPTIONS" {
|
||||
next.ServeHTTP(w, r)
|
||||
} else {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "authorization, origin, content-type, accept")
|
||||
w.Header().Set("Allow", "HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Secure writes required access headers to all requests.
|
||||
func Secure(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("X-Frame-Options", "DENY")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
||||
|
||||
if r.TLS != nil {
|
||||
w.Header().Set("Strict-Transport-Security", "max-age=31536000")
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// Version writes the current version to the headers.
|
||||
func Version(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-PHOENIX-VERSION", version.String)
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/handler/metrics"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/middleware/header"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// debug gets initialized by Router and configures the router.
|
||||
type debug struct {
|
||||
token string
|
||||
pprof bool
|
||||
}
|
||||
|
||||
// Router initializes a router for the debug server.
|
||||
func Router(opts ...Option) *chi.Mux {
|
||||
d := new(debug)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(d)
|
||||
}
|
||||
|
||||
mux := chi.NewRouter()
|
||||
|
||||
mux.Use(hlog.NewHandler(log.Logger))
|
||||
mux.Use(hlog.RemoteAddrHandler("ip"))
|
||||
mux.Use(hlog.URLHandler("path"))
|
||||
mux.Use(hlog.MethodHandler("method"))
|
||||
mux.Use(hlog.RequestIDHandler("request_id", "Request-Id"))
|
||||
|
||||
mux.Use(middleware.RealIP)
|
||||
mux.Use(header.Version)
|
||||
mux.Use(header.Cache)
|
||||
mux.Use(header.Secure)
|
||||
mux.Use(header.Options)
|
||||
|
||||
mux.Route("/", func(root chi.Router) {
|
||||
if d.pprof {
|
||||
root.Mount(
|
||||
"/debug",
|
||||
middleware.Profiler(),
|
||||
)
|
||||
}
|
||||
|
||||
root.Mount(
|
||||
"/metrics",
|
||||
metrics.Handler(
|
||||
metrics.WithToken(d.token),
|
||||
),
|
||||
)
|
||||
|
||||
root.Get("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
io.WriteString(w, http.StatusText(http.StatusOK))
|
||||
})
|
||||
|
||||
root.Get("/readyz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
io.WriteString(w, http.StatusText(http.StatusOK))
|
||||
})
|
||||
})
|
||||
|
||||
return mux
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package debug
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*debug)
|
||||
|
||||
// WithToken returns an option to set a token.
|
||||
func WithToken(val string) Option {
|
||||
return func(d *debug) {
|
||||
d.token = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithPprof returns an option to enable pprof.
|
||||
func WithPprof(val bool) Option {
|
||||
return func(d *debug) {
|
||||
d.pprof = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package server
|
||||
|
||||
// Option configures an assets option.
|
||||
type Option func(*server)
|
||||
|
||||
// WithRoot returns an option to set a root.
|
||||
func WithRoot(val string) Option {
|
||||
return func(s *server) {
|
||||
s.root = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithPath returns an option to set a path.
|
||||
func WithPath(val string) Option {
|
||||
return func(s *server) {
|
||||
s.path = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustom returns an option to set a path.
|
||||
func WithCustom(val string) Option {
|
||||
return func(s *server) {
|
||||
s.custom = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithServer returns an option to set a path.
|
||||
func WithServer(val string) Option {
|
||||
return func(s *server) {
|
||||
s.server = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithTheme returns an option to set a path.
|
||||
func WithTheme(val string) Option {
|
||||
return func(s *server) {
|
||||
s.theme = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithVersion returns an option to set a path.
|
||||
func WithVersion(val string) Option {
|
||||
return func(s *server) {
|
||||
s.version = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithClient returns an option to set a path.
|
||||
func WithClient(val string) Option {
|
||||
return func(s *server) {
|
||||
s.client = val
|
||||
}
|
||||
}
|
||||
|
||||
// WithApps returns an option to set a path.
|
||||
func WithApps(val []string) Option {
|
||||
return func(s *server) {
|
||||
s.apps = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/handler/config"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/handler/static"
|
||||
"github.com/owncloud/ocis-phoenix/pkg/middleware/header"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// server gets initialized by Router and configures the router.
|
||||
type server struct {
|
||||
root string
|
||||
path string
|
||||
custom string
|
||||
server string
|
||||
theme string
|
||||
version string
|
||||
client string
|
||||
apps []string
|
||||
}
|
||||
|
||||
// Router initializes a router for the http server.
|
||||
func Router(opts ...Option) *chi.Mux {
|
||||
s := new(server)
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(s)
|
||||
}
|
||||
|
||||
mux := chi.NewRouter()
|
||||
|
||||
mux.Use(hlog.NewHandler(log.Logger))
|
||||
mux.Use(hlog.RemoteAddrHandler("ip"))
|
||||
mux.Use(hlog.URLHandler("path"))
|
||||
mux.Use(hlog.MethodHandler("method"))
|
||||
mux.Use(hlog.RequestIDHandler("request_id", "Request-Id"))
|
||||
|
||||
mux.Use(hlog.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
|
||||
hlog.FromRequest(r).Debug().
|
||||
Str("method", r.Method).
|
||||
Str("url", r.URL.String()).
|
||||
Int("status", status).
|
||||
Int("size", size).
|
||||
Dur("duration", duration).
|
||||
Msg("")
|
||||
}))
|
||||
|
||||
mux.Use(middleware.RealIP)
|
||||
mux.Use(header.Version)
|
||||
mux.Use(header.Cache)
|
||||
mux.Use(header.Secure)
|
||||
mux.Use(header.Options)
|
||||
|
||||
mux.Route(s.root, func(root chi.Router) {
|
||||
root.Mount(
|
||||
"/config.json",
|
||||
config.Handler(
|
||||
config.WithCustom(s.custom),
|
||||
config.WithServer(s.server),
|
||||
config.WithTheme(s.theme),
|
||||
config.WithVersion(s.version),
|
||||
config.WithClient(s.client),
|
||||
config.WithApps(s.apps),
|
||||
),
|
||||
)
|
||||
|
||||
root.Mount(
|
||||
"/",
|
||||
static.Handler(
|
||||
static.WithRoot(s.root),
|
||||
static.WithPath(s.path),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user