Skip to content

Commit

Permalink
Merge pull request #112 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.3.1
  • Loading branch information
andyone committed Apr 1, 2024
2 parents c33398e + 452a5cc commit 594d648
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
go: [ '1.20.x', '1.21.x' ]
go: [ '1.21.x', '1.22.x' ]

steps:
- name: Checkout
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20.x'
go-version: '1.21.x'

- name: Download dependencies
run: make deps
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
fetch-depth: 2

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
9 changes: 7 additions & 2 deletions common/updown-badge-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

Summary: Service for generating badges for updown.io checks
Name: updown-badge-server
Version: 1.3.0
Version: 1.3.1
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand All @@ -26,7 +26,7 @@ Source100: checksum.sha512

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires: golang >= 1.20
BuildRequires: golang >= 1.21

Requires: systemd

Expand Down Expand Up @@ -98,6 +98,11 @@ exit 0
################################################################################

%changelog
* Sat Mar 30 2024 Anton Novojilov <andy@essentialkaos.com> - 1.3.1-0
- Improved support information gathering
- Code refactoring
- Dependencies update

* Fri Dec 08 2023 Anton Novojilov <andy@essentialkaos.com> - 1.3.0-0
- Change service user name from 'updownbs' to 'updown'
- Dependencies update
Expand Down
71 changes: 36 additions & 35 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package daemon

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -19,6 +19,9 @@ import (
"github.com/essentialkaos/ek/v12/log"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/signal"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"

knfv "github.com/essentialkaos/ek/v12/knf/validators"
Expand All @@ -38,10 +41,12 @@ import (
// Basic service info
const (
APP = "UpDownBadgeServer"
VER = "1.3.0"
VER = "1.3.1"
DESC = "Service for generating badges for updown.io checks"
)

// ////////////////////////////////////////////////////////////////////////////////// //

const (
MIN_PORT = 1025
MAX_PORT = 65535
Expand All @@ -56,7 +61,9 @@ const (
OPT_CONFIG = "c:config"
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VERSION = "v:version"
OPT_VER = "v:version"

OPT_VERB_VER = "vv:verbose-version"
)

// Configuration file properties
Expand All @@ -75,20 +82,16 @@ const (
LOG_LEVEL = "log:level"
)

// Pid file info
const (
PID_DIR = "/var/run/updown-badge-server"
PID_FILE = "updown-badge-server.pid"
)

// ////////////////////////////////////////////////////////////////////////////////// //

// optMap contains information about all supported options
var optMap = options.Map{
OPT_CONFIG: {Value: "/etc/updown-badge-server.knf"},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VERSION: {Type: options.BOOL, Alias: "ver"},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_VERB_VER: {Type: options.BOOL},
}

var udAPI *api.API
Expand All @@ -100,7 +103,8 @@ var redirectURL string

// ////////////////////////////////////////////////////////////////////////////////// //

func Init() {
// Run is main utility function
func Run(gomod []byte) {
preConfigureUI()

_, errs := options.Parse(optMap)
Expand All @@ -115,12 +119,18 @@ func Init() {

configureUI()

if options.GetB(OPT_VERSION) {
os.Exit(showAbout())
}

if options.GetB(OPT_HELP) {
os.Exit(showUsage())
switch {
case options.GetB(OPT_VER):
genAbout().Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.Collect(APP, VER).
WithDeps(deps.Extract(gomod)).
Print()
os.Exit(0)
case options.GetB(OPT_HELP):
genUsage().Print()
os.Exit(0)
}

loadConfig()
Expand All @@ -137,10 +147,7 @@ func Init() {

// preConfigureUI preconfigures user interface
func preConfigureUI() {
switch {
case os.Getenv("INVOCATION_ID") != "",
os.Getenv("SYSTEMCTL_IGNORE_DEPENDENCIES") != "",
os.Getenv("NO_COLOR") != "":
if !tty.IsTTY() || tty.IsSystemd() {
fmtc.DisableColors = true
}
}
Expand Down Expand Up @@ -305,32 +312,26 @@ func shutdown(code int) {

// ////////////////////////////////////////////////////////////////////////////////// //

// showUsage prints usage info
func showUsage() int {
// genUsage generates usage info
func genUsage() *usage.Info {
info := usage.NewInfo()

info.AddOption(OPT_CONFIG, "Path to configuration file", "file")
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VERSION, "Show version")
info.AddOption(OPT_VER, "Show version")

info.Print()

return 0
return info
}

// showAbout prints info about version
func showAbout() int {
usage := &usage.About{
// genAbout generates info about version
func genAbout() *usage.About {
return &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Year: 2009,
Owner: "ESSENTIAL KAOS",
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
}

usage.Print()

return 0
}
6 changes: 3 additions & 3 deletions daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package daemon

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -238,8 +238,8 @@ func getColorForStatus(p float64) string {

// parsePath parses request path
func parsePath(path string) (string, uint8) {
token := strutil.ReadField(path, 0, false, "/")
badge := strutil.ReadField(path, 1, false, "/")
token := strutil.ReadField(path, 0, false, '/')
badge := strutil.ReadField(path, 1, false, '/')

switch badge {
case "status.svg":
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module github.com/essentialkaos/updown-badge-server
go 1.18

require (
github.com/essentialkaos/ek/v12 v12.90.1
github.com/essentialkaos/ek/v12 v12.113.1
github.com/essentialkaos/go-badge v1.3.3
github.com/valyala/fasthttp v1.51.0
github.com/valyala/fasthttp v1.52.0
)

require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/essentialkaos/depsy v1.1.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/image v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
)
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/ek/v12 v12.90.1 h1:ID950cnz4xgpqqFzhleP5xaVoLnPwuiykdH3FrogD/E=
github.com/essentialkaos/ek/v12 v12.90.1/go.mod h1:9efMqo1S8EtYhmeelOSTmMQDGC2vRgPkjkKKfvUD2eU=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg=
github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U=
github.com/essentialkaos/go-badge v1.3.3 h1:mp2UyD8FpAUiYunHJ/lRfbNTSJNgMqb1+gRV0dDHZZk=
github.com/essentialkaos/go-badge v1.3.3/go.mod h1:3BFjchqLk51N66eG5zrOugKKFS00nh2H2tnKm2Hyw9o=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
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/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0=
github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11 changes: 9 additions & 2 deletions updown-badge-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ package main

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2022 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
_ "embed"

DAEMON "github.com/essentialkaos/updown-badge-server/daemon"
)

// ////////////////////////////////////////////////////////////////////////////////// //

//go:embed go.mod
var gomod []byte

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
DAEMON.Init()
DAEMON.Run(gomod)
}

// ////////////////////////////////////////////////////////////////////////////////// //

0 comments on commit 594d648

Please sign in to comment.