Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ version.go
# Ignore deb build directory and related stuff
*.deb
deb/
!deb/DEBIAN/control
!deb/DEBIAN/control.in
!deb/DEBIAN/postinst
!deb/DEBIAN/postrm

# Ignore built stuff
out/
103 changes: 53 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,68 +1,71 @@
PROG:=dnstapir-cli
# -----
VERSION:=`cat ./VERSION`
COMMIT:=`git describe --dirty=+WiP --always`
APPDATE=`date +"%Y-%m-%d-%H:%M"`
GOFLAGS:=-v -ldflags "-X app.version=$(VERSION)-$(COMMIT)"
#######################################
# VERSION SOURCE OF TRUTH FOR PROJECT #
#######################################
VERSION:=0.0.0

PROG:=dnstapir-cli
OUT:=$$(pwd)/out
COMMIT:=$$(cat COMMIT 2> /dev/null || git describe --dirty=+WiP --always 2> /dev/null)
GOFLAGS:=-v -ldflags "-X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.name=$(PROG)'"
GOOS ?= $(shell uname -s | tr A-Z a-z)
GO:=GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go
INSTALL:=install -b -c -s -p -m 0755

GO:=GOOS=$(GOOS) CGO_ENABLED=0 go
# GO:=GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go
# For version snapshots of packages
RPM_VERSION:=$(VERSION)
DEB_VERSION:=$(VERSION)
ifeq ($(VERSION), 0.0.0)
RPM_VERSION=$(VERSION)^$$(date +%Y%m%d).$(COMMIT)
DEB_VERSION=$(VERSION)+local$$(date +%Y%m%d).$(COMMIT)
endif

SPECFILE:=rpm/SPECS/dnstapir-cli.spec
all: default

default: ${PROG}
default: $(PROG)

${PROG}: build
$(PROG): build

build:
/bin/sh make-version.sh $(VERSION)-$(COMMIT) $(APPDATE) $(PROG)
$(GO) build $(GOFLAGS) -o ${PROG}
build: outdir
$(GO) build $(GOFLAGS) -o $(OUT)/$(PROG)

linux:
/bin/sh make-version.sh $(VERSION)-$(COMMIT) $(APPDATE) $(PROG)
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o ${PROG}.linux
outdir:
@mkdir -p $(OUT)

netbsd:
/bin/sh make-version.sh $(VERSION)-$(COMMIT) $(APPDATE) $(PROG)
GOOS=netbsd GOARCH=amd64 go build $(GOFLAGS) -o ${PROG}.netbsd
install:
test -z "$(DESTDIR)" && $(INSTALL) $(OUT)/$(PROG) /usr/bin/ || $(INSTALL) $(OUT)/$(PROG) $(DESTDIR)$(prefix)

test:
$(GO) test -v -cover
lint:
go fmt ./...
go vet ./...
staticcheck ./...
gosec ./...
golangci-lint run

clean: SHELL:=/bin/bash
clean:
@rm -f $(PROG) *~ cmd/*~
@rm -f *.tar.gz
@rm -f rpm/SOURCES/*.tar.gz
@rm -rf rpm/{BUILD,BUILDROOT,SRPMS,RPMS}
@rm -rf deb/usr
@rm -rf deb/etc
@rm -rf deb/var
@rm -f *.deb
@rm -rf $(OUT)

install:
install -b -c -s ${PROG} /usr/local/bin/

tarball:
git archive --format=tar.gz --prefix=$(PROG)/ -o $(PROG)-$(VERSION).tar.gz HEAD
tarball: outdir
@echo "$(COMMIT)" > $(OUT)/COMMIT
@test -z "$$(git status --porcelain)" && git archive --format=tar.gz --prefix=$(PROG)/ -o $(OUT)/$(PROG).tar.gz --add-file $(OUT)/COMMIT HEAD || echo "won't make tarball from dirty history"

srpm: SHELL:=/bin/bash
srpm: tarball
test $$(rpmspec -q --qf '%{version}' $(SPECFILE) 2>/dev/null || grep '^Version:' $(SPECFILE) | awk '{print $$2}') == $(VERSION)
mkdir -p rpm/{BUILD,RPMS,SRPMS}
cp $(PROG)-$(VERSION).tar.gz rpm/SOURCES/
rpmbuild -bs --define "%_topdir ./rpm" --undefine=dist $(SPECFILE)
test -z "$(outdir)" || cp rpm/SRPMS/*.src.rpm "$(outdir)"
cp -r rpm $(OUT)
sed -e "s/@@VERSION@@/$(RPM_VERSION)/g" $(OUT)/rpm/SPECS/dnstapir-cli.spec.in > $(OUT)/rpm/SPECS/dnstapir-cli.spec
cp $(OUT)/$(PROG).tar.gz $(OUT)/rpm/SOURCES/
rpmbuild -bs --define "%_topdir $(OUT)/rpm" --undefine=dist $(OUT)/rpm/SPECS/dnstapir-cli.spec
cp $(OUT)/rpm/SRPMS/$(PROG)-$(RPM_VERSION)-*.src.rpm $(OUT)
test -z "$(outdir)" || cp $(OUT)/$(PROG)-$(RPM_VERSION)-*.src.rpm "$(outdir)"

rpm: srpm
rpmbuild --recompile --define "%_topdir $(OUT)/rpm" --undefine=dist $(OUT)/$(PROG)-$(RPM_VERSION)-*.src.rpm

deb: build
mkdir -p deb/usr/bin
mkdir -p deb/etc/dnstapir/certs
mkdir -p deb/usr/lib/systemd/system
cp dnstapir-cli deb/usr/bin
cp rpm/SOURCES/dnstapir-renew.service deb/usr/lib/systemd/system
cp rpm/SOURCES/dnstapir-renew.timer deb/usr/lib/systemd/system
dpkg-deb -b deb/ $(PROG)-$(VERSION).deb
cp -r deb $(OUT)
mkdir -p $(OUT)/deb/usr/bin
mkdir -p $(OUT)/deb/etc/dnstapir/certs
mkdir -p $(OUT)/deb/usr/lib/systemd/system
cp $(OUT)/$(PROG) $(OUT)/deb/usr/bin
sed -e "s/@@VERSION@@/$(DEB_VERSION)/g" $(OUT)/deb/DEBIAN/control.in > $(OUT)/deb/DEBIAN/control
dpkg-deb -b $(OUT)/deb/ $(OUT)/$(PROG)-$(DEB_VERSION).deb

.PHONY: build clean
.PHONY: all default build install lint tarball srpm rpm deb clean
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
# tapir-cli
# dnstapir-cli

CLI utility primarily to interact with other DNS TAPIR components.
For this the config details needed to connect to eg. TAPIR-POP are
For this the config details needed to connect to eg. dnstapir-pop are
located in the config files in the /etc/dnstapir/ directory.

For some uses, though, `tapir-cli` is used in "standalone" mode. One
example of this is the creation anad manipulation of DAWG files
For some uses, though, `dnstapir-cli` is used in "standalone" mode. One
example of this is the creation and manipulation of DAWG files
containing large lists of domain names in a compact format. To run
`tapir-cli` in standalone mode, without the need for any config files,
`dnstapir-cli` in standalone mode, without the need for any config files,
use the command flag `--standalone`.

`tapir-cli` has a large number of commands and subcommands. The entire
`dnstapir-cli` has a large number of commands and subcommands. The entire
set of commands is structured as a tree with the root in the
`tapi-cli` command. All commands, regardless of where in the tree of
Comment thread
coderabbitai[bot] marked this conversation as resolved.
commands they are located, have online help via the flag `-h`. I.e. to
get help on the `tapir-cli pop ping` command, run:
get help on the `dnstapir-cli pop ping` command, run:

```
tapir-cli pop ping -h
Send an API ping request to TAPIR-POP and present the response
dnstapir-cli pop ping -h
Send an API ping request to dnstapir-pop and present the response

Usage:
tapir-cli pop ping [flags]
dnstapir-cli pop ping [flags]

Flags:
-c, --count int #pings to send
-h, --help help for ping
-n, --newapi use new api client

Global Flags:
--config string config file (default is /etc/dnstapir/tapir-pop.yaml)
--config string config file (default is /etc/dnstapir/dnstapir-pop.yaml)
-d, --debug Debugging output
-H, --headers Show column headers
--tls Use a TLS connection to TAPIR-POP (default true)
--tls Use a TLS connection to dnstapir-pop (default true)
-v, --verbose Verbose mode
```

The flag `-h` also lists all subcommands underneath the command in question.

The `tapir-cli` command has a number of subcommands, each of which is a command group. The command groups are:
The `dnstapir-cli` command has a number of subcommands, each of which is a command group. The command groups are:

```
tapir-cli -h
CLI utility used to interact with TAPIR-POP, i.e. the TAPIR Policy Processor
dnstapir-cli -h
CLI utility used to interact with dnstapir-pop, i.e. the DNS TAPIR Policy Processor

Usage:
tapir-cli [command]
dnstapir-cli [command]

Available Commands:
api request a TAPIR-POP api summary
bump Instruct TAPIR-POP to bump the SOA serial of the RPZ zone
api request a dnstapir-pop api summary
bump Instruct dnstapir-pop to bump the SOA serial of the RPZ zone
completion Generate the autocompletion script for the specified shell
dawg Generate or interact with data stored in a DAWG file; only useable via sub-commands
debug A brief description of your command
help Help about any command
pop Prefix command, only usable via sub-commands
rpz Instruct TAPIR-POP to modify the RPZ zone; must use sub-command
rpz Instruct dnstapir-pop to modify the RPZ zone; must use sub-command

Flags:
--config string config file (default is /etc/dnstapir/tapir-pop.yaml)
--config string config file (default is /etc/dnstapir/dnstapir-pop.yaml)
-d, --debug Debugging output
-H, --headers Show column headers
-h, --help help for tapir-cli
--tls Use a TLS connection to TAPIR-POP (default true)
-h, --help help for dnstapir-cli
--tls Use a TLS connection to dnstapir-pop (default true)
-v, --verbose Verbose mode

Use "tapir-cli [command] --help" for more information about a command.
Use "dnstapir-cli [command] --help" for more information about a command.
```

Many of the commands are only there as debugging tools. They are not intended for use in production.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

2 changes: 1 addition & 1 deletion deb/DEBIAN/control → deb/DEBIAN/control.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dnstapir-cli
Architecture: all
Version: 0.3
Version: @@VERSION@@
Section: misc
Maintainer: Leon Fernandez <leon.fernandez@internetstiftelsen.se>
Priority: optional
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
package main

import (
"fmt"
"dnstapir-cli/cmd"
)

var name = "BAD-BUILD"
var version = "BAD-BUILD"
var commit = "BAD-BUILD"

func main() {
fmt.Printf("%s, version %s, commit %s\n", name, version, commit)
cmd.Execute()
}
23 changes: 0 additions & 23 deletions make-version.sh

This file was deleted.

15 changes: 6 additions & 9 deletions rpm/SPECS/dnstapir-cli.spec → rpm/SPECS/dnstapir-cli.spec.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Disable building of debug packages
%global debug_package %{nil}

Name: dnstapir-cli
# NOTE: Version must match VERSION file - validated by Makefile srpm target
Version: v0.3
Version: @@VERSION@@
Release: 1%{?dist}
Group: dnstapir/edge
Summary: DNS TAPIR EDGE Cli Tool
License: BSD
URL: https://www.github.com/dnstapir/cli
Source0: %{name}-%{version}.tar.gz
Source0: %{name}.tar.gz
Source1: dnstapir-renew.service
Source2: dnstapir-renew.timer
BuildRequires: git
Expand All @@ -15,11 +17,6 @@ BuildRequires: golang
%description
DNS TAPIR EDGE ClI Tool for managing an EDGE deployment

# Disable building of debug packages for RHEL (we include symbols per default)
%if 0%{?rhel} >= 9
%global debug_package %{nil}
%endif

%{!?_unitdir: %define _unitdir /usr/lib/systemd/system/}
%{!?_sysusersdir: %define _sysusersdir /usr/lib/sysusers.d/}

Expand All @@ -34,7 +31,7 @@ mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{_sysconfdir}/dnstapir/certs

install -p -m 0755 %{name} %{buildroot}%{_bindir}/%{name}
DESTDIR=%{buildroot}%{_bindir} make install
install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}
install -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}

Expand Down
Loading