Skip to content

Commit

Permalink
Merge pull request #528 from sundowndev/patch/refact
Browse files Browse the repository at this point in the history
Refactor file structure
  • Loading branch information
sundowndev authored Oct 19, 2020
2 parents a9086c3 + aab86fc commit 52af4bc
Show file tree
Hide file tree
Showing 40 changed files with 150 additions and 183 deletions.
5 changes: 5 additions & 0 deletions .deploy/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ metadata:
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-passthrough: "false"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/configuration-snippet: |
add_header Content-Security-Policy "default-src 'self';frame-ancestors 'self';style-src 'self';script-src 'self';img-src 'self';font-src 'self'";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy no-referrer;
spec:
rules:
- host: demo.phoneinfoga.crvx.fr
Expand Down
6 changes: 0 additions & 6 deletions .dockerignore

This file was deleted.

15 changes: 5 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
name: Build

on: [push]
on: [ push ]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.14
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.15
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 12.16.x
node-version: 12.18.x

- name: Building static assets
run: (cd client && yarn && yarn build)

- name: Build
run: |
go get -v github.com/jessevdk/go-assets-builder
go generate ./...
go build -v .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
coverage
coverage.*
.idea
api/assets.go
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ builds:
- amd64
- arm
- arm64
ldflags: -s -w -X gopkg.in/sundowndev/phoneinfoga.v2/config.Version={{.Version}} -X gopkg.in/sundowndev/phoneinfoga.v2/config.Commit={{.ShortCommit}}
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ RUN go get -v github.com/jessevdk/go-assets-builder

RUN go generate ./...

RUN go build -v -o phoneinfoga .
RUN apk add git
RUN GIT_COMMIT=$(git rev-parse HEAD)
RUN GIT_RELEASE=$(git describe --abbrev=0 --tags)

RUN go build -v -ldflags "-s -w -X gopkg.in/sundowndev/phoneinfoga.v2/config.Version=$GIT_RELEASE -X gopkg.in/sundowndev/phoneinfoga.v2/config.Commit=$GIT_COMMIT" -v -o phoneinfoga .

FROM golang:1.15-alpine

Expand Down
5 changes: 3 additions & 2 deletions api/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package api

import (
"github.com/gin-gonic/gin"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/config"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/scanners"
"gopkg.in/sundowndev/phoneinfoga.v2/config"
"gopkg.in/sundowndev/phoneinfoga.v2/scanners"
)

type scanResultResponse struct {
Expand Down Expand Up @@ -83,5 +83,6 @@ func healthHandler(c *gin.Context) {
c.JSON(200, gin.H{
"success": true,
"version": config.Version,
"commit": config.Commit,
})
}
4 changes: 2 additions & 2 deletions api/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package api
import (
"testing"

"github.com/stretchr/testify/assert"
assertion "github.com/stretchr/testify/assert"
)

func TestResponse(t *testing.T) {
assert := assert.New(t)
assert := assertion.New(t)

t.Run("successResponse", func(t *testing.T) {
t.Run("should return success response", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package api is about the REST API of PhoneInfoga
//go:generate $GOPATH/bin/go-assets-builder ../client/dist -o ./assets.go -p api
//go:generate go run github.com/jessevdk/go-assets-builder ../client/dist -o ./assets.go -p api
package api

import (
Expand Down
9 changes: 4 additions & 5 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
"github.com/gin-gonic/gin"
assertTest "github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/config"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/scanners"
"gopkg.in/sundowndev/phoneinfoga.v2/scanners"
)

var r *gin.Engine
Expand Down Expand Up @@ -208,20 +207,20 @@ func TestApi(t *testing.T) {

t.Run("healthHandler - /api/", func(t *testing.T) {
res, err := performRequest(r, "GET", "/api/")
assert.Equal(nil, err, "should be equal")

body, _ := ioutil.ReadAll(res.Body)

assert.Equal(nil, err, "should be equal")
assert.Equal(200, res.Result().StatusCode, "should be equal")
assert.Equal("{\"success\":true,\"version\":\""+config.Version+"\"}", string(body), "should be equal")
assert.Equal("{\"commit\":\"unknown\",\"success\":true,\"version\":\"unknown\"}", string(body), "should be equal")
})

t.Run("404 error - /api/notfound", func(t *testing.T) {
res, err := performRequest(r, "GET", "/api/notfound")
assert.Equal(err, nil, "should be equal")

body, _ := ioutil.ReadAll(res.Body)

assert.Equal(err, nil, "should be equal")
assert.Equal(res.Result().StatusCode, 404, "should be equal")
assert.Equal(string(body), "{\"success\":false,\"error\":\"Resource not found\"}", "should be equal")
})
Expand Down
2 changes: 1 addition & 1 deletion api/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/scanners"
"gopkg.in/sundowndev/phoneinfoga.v2/scanners"
)

// JSONResponse is the default API response type
Expand Down
2 changes: 1 addition & 1 deletion cmd/recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"github.com/spf13/cobra"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/utils"
"gopkg.in/sundowndev/phoneinfoga.v2/utils"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"

"github.com/spf13/cobra"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/scanners"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/utils"
"gopkg.in/sundowndev/phoneinfoga.v2/scanners"
"gopkg.in/sundowndev/phoneinfoga.v2/utils"
)

func init() {
Expand Down
10 changes: 5 additions & 5 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/config"
"gopkg.in/sundowndev/phoneinfoga.v2/pkg/utils"
"gopkg.in/sundowndev/phoneinfoga.v2/config"
"gopkg.in/sundowndev/phoneinfoga.v2/utils"
)

func init() {
// Register command
rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print current version of the tool",
Run: func(cmd *cobra.Command, args []string) {
utils.LoggerService.Infoln("PhoneInfoga", config.Version)
utils.LoggerService.Infoln("Coded by Sundowndev https://github.com/sundowndev/PhoneInfoga")
utils.LoggerService.Infoln("PhoneInfoga", config.Version, fmt.Sprintf("(%s)", config.Commit))
utils.LoggerService.Infoln("Maintained by sundowndev https://github.com/sundowndev/PhoneInfoga")
},
}
18 changes: 18 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"testing"

assertion "github.com/stretchr/testify/assert"
)

func TestConfig(t *testing.T) {
assert := assertion.New(t)

t.Run("Version", func(t *testing.T) {
t.Run("version should be unknown by default", func(t *testing.T) {
assert.Equal("unknown", Version)
assert.Equal("unknown", Commit)
})
})
}
9 changes: 9 additions & 0 deletions config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

const unknown = "unknown"

// Version is the corresponding release tag
var Version = unknown

// Commit is the corresponding Git commit
var Commit = unknown
34 changes: 0 additions & 34 deletions docker-compose.traefik.yml

This file was deleted.

13 changes: 0 additions & 13 deletions docker-compose.yml

This file was deleted.

Loading

0 comments on commit 52af4bc

Please sign in to comment.