Skip to content

Commit

Permalink
fix: remove snap support.
Browse files Browse the repository at this point in the history
  • Loading branch information
guumaster committed Jul 20, 2020
1 parent 9df25f1 commit 63361c9
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 67 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
with:
go-version: 1.14.x

- name: Add Snapcraft
uses: samuelmeuli/action-snapcraft@v1
with:
snapcraft_token: ${{ secrets.snapcraft_token }}

- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
Expand Down
28 changes: 0 additions & 28 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ builds:
ldflags:
- -s -w -X github.com/guumaster/hostctl/cmd/hostctl/actions.version={{.Version}}

- id: hostctl-snap
binary: hostctl-snap
main: cmd/hostctl/main.go
env:
- GO111MODULE=on
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
ldflags:
- -s -w -X github.com/guumaster/hostctl/cmd/hostctl/actions.version={{.Version}}-snap -X github.com/guumaster/hostctl/cmd/hostctl/actions.snapBuild=yes

changelog:
sort: desc
filters:
Expand Down Expand Up @@ -92,18 +79,3 @@ scoop:
homepage: https://github.com/guumaster/hostctl
description: Your dev tool to manage /etc/hosts like a pro
license: MIT

snapcrafts:
- id: hostctl-snap
name: hostctl
builds:
- hostctl-snap
summary: Your dev tool to manage /etc/hosts like a pro
description: Your dev tool to manage /etc/hosts like a pro.
grade: stable
confinement: strict
license: MIT
publish: true
apps:
hostctl:
plugs: ["network-control"]
22 changes: 2 additions & 20 deletions cmd/hostctl/actions/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ func containsDefault(args []string) error {
return nil
}

func getDefaultHostFile(snapBuild bool) string {
// Snap confinement doesn't allow to read other than
if runtime.GOOS == "linux" && snapBuild {
func getDefaultHostFile() string {
if runtime.GOOS == "linux" {
return "/etc/hosts"
}

Expand All @@ -98,23 +97,6 @@ func getDefaultHostFile(snapBuild bool) string {
return "/etc/hosts"
}

func checkSnapRestrictions(cmd *cobra.Command, isSnap bool) error {
from, _ := cmd.Flags().GetString("from")
src, _ := cmd.Flags().GetString("host-file")

defaultSrc := getDefaultHostFile(isSnap)

if !isSnap {
return nil
}

if from != "" || src != defaultSrc && !isValidURL(from) {
return types.ErrSnapConfinement
}

return nil
}

// isValidURL tests a string to determine if it is a well-structured url or not.
func isValidURL(s string) bool {
_, err := url.ParseRequestURI(s)
Expand Down
13 changes: 3 additions & 10 deletions cmd/hostctl/actions/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

// nolint:gochecknoglobals
var (
version = "dev"
snapBuild string
version = "dev"
)

// NewRootCmd creates the base command for hostctl
Expand All @@ -34,14 +33,9 @@ you need each time with a simple interface.
cligger.DisableColor()
}
cligger.SetWriter(cmd.OutOrStdout())
isSnapBuild := snapBuild == "yes"
err := checkSnapRestrictions(cmd, isSnapBuild)
if err != nil {
return err
}
host, _ := cmd.Flags().GetString("host-file")

showHostFile := host != getDefaultHostFile(isSnapBuild) || os.Getenv("HOSTCTL_FILE") != ""
showHostFile := host != getDefaultHostFile() || os.Getenv("HOSTCTL_FILE") != ""

quiet := needsQuietOutput(cmd)
isHelper := isHelperCmd(cmd)
Expand All @@ -56,10 +50,9 @@ you need each time with a simple interface.

// set CLI version
rootCmd.Version = version
isSnapBuild := snapBuild == "yes"

// rootCmd
rootCmd.PersistentFlags().String("host-file", getDefaultHostFile(isSnapBuild), "Hosts file path")
rootCmd.PersistentFlags().String("host-file", getDefaultHostFile(), "Hosts file path")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Run command without output")
rootCmd.PersistentFlags().Bool("raw", false, "Output without borders (same as -o raw)")
rootCmd.PersistentFlags().StringP("out", "o", "table", "Output type (table|raw|markdown|json)")
Expand Down
4 changes: 0 additions & 4 deletions pkg/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ var (

// ErrInvalidProfileHeader when the profile header is invalid
ErrInvalidProfileHeader = errors.New("invalid format for profile header")

// ErrSnapConfinement when trying to read files on snap installation
ErrSnapConfinement = errors.New("can't use --from or --host-file. " +
"Snap confinement restrictions doesn't allow to read other than /etc/hosts file")
)

0 comments on commit 63361c9

Please sign in to comment.