From 540fe818699ad5d565d423ea724ae73504797d8d Mon Sep 17 00:00:00 2001 From: Igor Shishkin Date: Sun, 7 Jul 2024 11:11:23 +0300 Subject: [PATCH] Add main components boilerplate Signed-off-by: Igor Shishkin --- .goreleaser.yaml | 42 ++++- cmd/access/main.go | 162 +++++++++++++++++- go.mod | 13 +- go.sum | 23 ++- presenter/access/html/handlers.go | 108 ++++++++++++ presenter/access/html/renderer.go | 16 ++ .../access/html/templates/container-list.html | 14 ++ .../access/html/templates/object-list.html | 17 ++ .../access/html/templates/version-list.html | 16 ++ 9 files changed, 405 insertions(+), 6 deletions(-) create mode 100644 presenter/access/html/handlers.go create mode 100644 presenter/access/html/renderer.go create mode 100644 presenter/access/html/templates/container-list.html create mode 100644 presenter/access/html/templates/object-list.html create mode 100644 presenter/access/html/templates/version-list.html diff --git a/.goreleaser.yaml b/.goreleaser.yaml index afda7a1..c5a605c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,12 +9,31 @@ builds: env: - CGO_ENABLED=0 goos: + - darwin + - dragonfly + - freebsd - linux + - netbsd + - openbsd + - solaris + - windows goarch: + # x86 - amd64 + - "386" + + # ARM - arm64 + - arm + + # MIPS + - mips64 + - mips64le + - mips + - mipsle goamd64: ["v1", "v2", "v3"] - goarm: ["7"] + goarm: ["6", "7"] + gomips: ["hardfloat", "softfloat"] mod_timestamp: "{{ .CommitTimestamp }}" - id: archived-cli main: ./cmd/cli @@ -58,12 +77,31 @@ builds: env: - CGO_ENABLED=0 goos: + - darwin + - dragonfly + - freebsd - linux + - netbsd + - openbsd + - solaris + - windows goarch: + # x86 - amd64 + - "386" + + # ARM - arm64 + - arm + + # MIPS + - mips64 + - mips64le + - mips + - mipsle goamd64: ["v1", "v2", "v3"] - goarm: ["7"] + goarm: ["6", "7"] + gomips: ["hardfloat", "softfloat"] mod_timestamp: "{{ .CommitTimestamp }}" archives: - format: binary diff --git a/cmd/access/main.go b/cmd/access/main.go index 1d5bf4a..02a1afa 100644 --- a/cmd/access/main.go +++ b/cmd/access/main.go @@ -1,10 +1,170 @@ package main +import ( + "context" + "net/http" + + "github.com/kelseyhightower/envconfig" + echo "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" + log "github.com/sirupsen/logrus" + "golang.org/x/sync/errgroup" + + htmlPresenter "github.com/teran/archived/presenter/access/html" + "github.com/teran/archived/service" +) + var ( appVersion = "n/a (dev build)" buildTimestamp = "undefined" ) +type config struct { + Addr string `envconfig:"ADDR" default:":8080"` + LogLevel log.Level `envconfig:"LOG_LEVEL" default:"info"` + HTMLTemplateDir string `envconfig:"HTML_TEMPLATE_DIR"` +} + func main() { - panic("not implemented") + var cfg config + envconfig.MustProcess("", &cfg) + + log.SetLevel(cfg.LogLevel) + + lf := new(log.TextFormatter) + lf.FullTimestamp = true + log.SetFormatter(lf) + + log.Infof("Initializing archived-access (%s @ %s) ...", appVersion, buildTimestamp) + + g, _ := errgroup.WithContext(context.Background()) + + e := echo.New() + e.Use(middleware.Logger()) + e.Use(middleware.Recover()) + + // svc := service.NewAccessService(nil, nil) + svc := service.NewMock() + svc.On("ListContainers").Return([]string{"test-container-1", "test-container-2"}, nil) + svc.On("ListVersions", "test-container-1").Return([]string{"20240706101013", "202407061101314"}, nil) + svc.On("ListObjects", "test-container-1", "20240706101013").Return([]string{ + "rockylinux/9/appstream/Packages/r/rocky-indexhtml-9.0-2.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rocky-logos-ipa-90.15-2.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rocky-logos-httpd-90.15-2.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rocky-backgrounds-90.15-2.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-srpm-macros-17-4.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/realtime-tests-2.6-5.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpmdevtools-9.5-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rpmlint-1.11-19.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redhat-text-fonts-4.0.3-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redhat-mono-fonts-4.0.3-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redhat-display-fonts-4.0.3-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rpm-mpi-hooks-8-3.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rhel-system-roles-1.23.0-2.21.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rtkit-0.11-28.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rshim-2.0.8-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rdma-core-devel-48.0-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/redhat-rpm-config-207-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/regexp-1.5-37.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redland-1.0.17-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-plugin-systemd-inhibit-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-plugin-syslog-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-plugin-ima-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-plugin-fapolicyd-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-devel-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-cron-4.16.1.3-29.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rpm-build-4.16.1.3-29.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-apidocs-4.16.1.3-29.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redfish-finder-0.4-9.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rig-1.1-6.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/runc-1.1.12-2.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/redis-doc-6.2.7-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/redis-devel-6.2.7-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/redis-6.2.7-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygems-devel-3.2.33-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygems-3.2.33-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-typeprof-0.15.2-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-test-unit-3.3.7-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-rss-0.2.9-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-rexml-3.2.5-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-rdoc-6.3.4.1-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-rbs-1.4.0-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-rake-13.0.3-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-power_assert-1.2.1-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-minitest-5.14.2-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-irb-1.3.5-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-bundler-2.2.33-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/ruby-default-gems-3.0.7-162.el9_4.noarch.rpm", + "rockylinux/9/appstream/Packages/r/radvd-2.19-5.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rasdaemon-0.6.7-9.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rrdtool-perl-1.7.2-21.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rrdtool-1.7.2-21.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/raptor2-2.0.15-30.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rear-2.6-24.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rustfmt-1.75.0-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rust-std-static-wasm32-wasi-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-std-static-wasm32-unknown-unknown-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-std-static-1.75.0-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rust-doc-1.75.0-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rust-1.75.0-1.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rust-src-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-lldb-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-gdb-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rust-debugger-common-1.75.0-1.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-udpspoof-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-snmp-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-relp-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-pgsql-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-openssl-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-omamqp1-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mysql-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmsnmptrapd-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmnormalize-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmkubernetes-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmjsonparse-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmfields-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-mmaudit-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-logrotate-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-kafka-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-gssapi-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-gnutls-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-elasticsearch-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-doc-8.2310.0-4.el9.noarch.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-crypto-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rsyslog-8.2310.0-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rest-0.8.1-11.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rasqal-0.9.33-18.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-mysql2-0.5.3-11.el9_0.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-ostree-libs-2024.3-4.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpm-ostree-2024.3-4.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/readline-devel-8.1-4.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-psych-3.3.2-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-json-2.5.1-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-io-console-0.5.7-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-bigdecimal-3.0.0-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/ruby-libs-3.0.7-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/ruby-devel-3.0.7-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/ruby-3.0.7-162.el9_4.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rpcgen-1.4-9.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rubygem-pg-1.2.3-7.el9.x86_64.rpm", + "rockylinux/9/appstream/Packages/r/rocky-logos-90.15-2.el9.x86_64.rpm", + }, nil) + + svc.On("GetObjectURL", "test-container-1", "20240706101013", "rockylinux/9/appstream/Packages/r/rocky-logos-90.15-2.el9.x86_64.rpm").Return("http://wikipedia.org", nil) + + p := htmlPresenter.New(svc, cfg.HTMLTemplateDir) + p.Register(e) + + g.Go(func() error { + srv := &http.Server{ + Addr: cfg.Addr, + Handler: e, + } + + return srv.ListenAndServe() + }) + + if err := g.Wait(); err != nil { + panic(err) + } } diff --git a/go.mod b/go.mod index 60e6005..b813fa5 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,16 @@ go 1.22.5 require ( github.com/Masterminds/squirrel v1.5.4 github.com/golang-migrate/migrate/v4 v4.17.1 + github.com/kelseyhightower/envconfig v1.4.0 + github.com/labstack/echo/v4 v4.12.0 github.com/lib/pq v1.10.9 github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 github.com/teran/go-docker-testsuite v0.0.6 github.com/teran/go-ptr v1.1.0 github.com/teran/go-time v0.0.2 + golang.org/x/sync v0.7.0 ) require ( @@ -30,6 +34,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect @@ -40,17 +45,21 @@ require ( github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/pgx/v4 v4.18.3 // indirect + github.com/labstack/gommon v0.4.2 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/sys/mountinfo v0.7.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect github.com/opencontainers/runtime-spec v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/teran/go-random v0.0.1 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect go.opentelemetry.io/otel v1.26.0 // indirect go.opentelemetry.io/otel/metric v1.26.0 // indirect @@ -59,8 +68,10 @@ require ( golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect golang.org/x/mod v0.11.0 // indirect + golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.10.0 // indirect google.golang.org/protobuf v1.34.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index e4223bc..fcf413b 100644 --- a/go.sum +++ b/go.sum @@ -55,6 +55,8 @@ github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPh github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4= github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= @@ -114,6 +116,8 @@ github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= +github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 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= @@ -126,6 +130,10 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= +github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= @@ -138,9 +146,14 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g= @@ -196,6 +209,10 @@ github.com/teran/go-random v0.0.1 h1:WQ3cF7UUQb/Q0oGAKcYeLeUIcMzD4vSs18oU1pkU/Mo github.com/teran/go-random v0.0.1/go.mod h1:t6Ns4GZsg/L9whg4u4EVXAj9k2lJiRHmJ7p1intLO0g= github.com/teran/go-time v0.0.2 h1:9g/+j3gAeMwtFETEh8ggWm1GFj8EFWwL/UqoM3ZYuiA= github.com/teran/go-time v0.0.2/go.mod h1:fsTuk1e6n6eukMXxmyqY7kG6n5PJUMjUjHA4Ved/enE= +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 v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= @@ -262,8 +279,8 @@ golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -279,6 +296,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= diff --git a/presenter/access/html/handlers.go b/presenter/access/html/handlers.go new file mode 100644 index 0000000..93f4d3d --- /dev/null +++ b/presenter/access/html/handlers.go @@ -0,0 +1,108 @@ +package html + +import ( + "html/template" + "net/http" + "path" + + echo "github.com/labstack/echo/v4" + + "github.com/teran/archived/service" +) + +type Handlers interface { + ContainerIndex(c echo.Context) error + VersionIndex(c echo.Context) error + Ping(c echo.Context) error + + Register(e *echo.Echo) +} + +type handlers struct { + svc service.AccessService + templateDir string +} + +func New(svc service.AccessService, templateDir string) Handlers { + return &handlers{ + svc: svc, + templateDir: templateDir, + } +} + +func (h *handlers) ContainerIndex(c echo.Context) error { + containers, err := h.svc.ListContainers(c.Request().Context()) + if err != nil { + return err + } + + return c.Render(http.StatusOK, "container-list.html", containers) +} + +func (h *handlers) VersionIndex(c echo.Context) error { + container := c.Param("container") + versions, err := h.svc.ListVersions(c.Request().Context(), container) + if err != nil { + return err + } + + type data struct { + Container string + Versions []string + } + + return c.Render(http.StatusOK, "version-list.html", &data{ + Container: container, + Versions: versions, + }) +} + +func (h *handlers) ObjectIndex(c echo.Context) error { + container := c.Param("container") + version := c.Param("version") + + objects, err := h.svc.ListObjects(c.Request().Context(), container, version) + if err != nil { + return err + } + + type data struct { + Container string + Version string + Objects []string + } + return c.Render(http.StatusOK, "object-list.html", &data{ + Container: container, + Version: version, + Objects: objects, + }) +} + +func (h *handlers) GetObject(c echo.Context) error { + container := c.Param("container") + version := c.Param("version") + object := c.Param("object") + + url, err := h.svc.GetObjectURL(c.Request().Context(), container, version, object) + if err != nil { + return err + } + + return c.Redirect(http.StatusFound, url) +} + +func (h *handlers) Ping(c echo.Context) error { + return c.Blob(http.StatusOK, "text/plain", []byte("pong\n")) +} + +func (h *handlers) Register(e *echo.Echo) { + e.Renderer = &renderer{ + templates: template.Must(template.ParseGlob(path.Join(h.templateDir, "*.html"))), + } + + e.GET("/", h.ContainerIndex) + e.GET("/:container/", h.VersionIndex) + e.GET("/:container/:version/", h.ObjectIndex) + e.GET("/:container/:version/:object", h.GetObject) + e.GET("/ping", h.Ping) +} diff --git a/presenter/access/html/renderer.go b/presenter/access/html/renderer.go new file mode 100644 index 0000000..bbcbc73 --- /dev/null +++ b/presenter/access/html/renderer.go @@ -0,0 +1,16 @@ +package html + +import ( + "html/template" + "io" + + echo "github.com/labstack/echo/v4" +) + +type renderer struct { + templates *template.Template +} + +func (r *renderer) Render(w io.Writer, name string, data any, c echo.Context) error { + return r.templates.ExecuteTemplate(w, name, data) +} diff --git a/presenter/access/html/templates/container-list.html b/presenter/access/html/templates/container-list.html new file mode 100644 index 0000000..86c33ca --- /dev/null +++ b/presenter/access/html/templates/container-list.html @@ -0,0 +1,14 @@ + + + Container Index + + +

Container index

+
+ {{ range $container := . }} + {{ $container }}
+ {{- end }} +
+ Powered by archived + + diff --git a/presenter/access/html/templates/object-list.html b/presenter/access/html/templates/object-list.html new file mode 100644 index 0000000..32935b1 --- /dev/null +++ b/presenter/access/html/templates/object-list.html @@ -0,0 +1,17 @@ +{{ $container := .Container }} +{{ $version := .Version }} + + + Object Index ({{ $container }}/{{ $version }}) + + +

Object Index ({{ $container }}/{{ $version }})

+
+ ..
+ {{- range $object := .Objects }} + {{ $object }}
+ {{- end }} +
+ Powered by archived + + diff --git a/presenter/access/html/templates/version-list.html b/presenter/access/html/templates/version-list.html new file mode 100644 index 0000000..55104cb --- /dev/null +++ b/presenter/access/html/templates/version-list.html @@ -0,0 +1,16 @@ +{{ $container := .Container }} + + + Version Index ({{ $container }}) + + +

Version Index ({{ $container }})

+
+ ..
+ {{- range $version := .Versions }} + {{ $version }}
+ {{- end }} +
+ Powered by archived + +