Skip to content

Commit

Permalink
chore: formatted using gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Aug 3, 2023
1 parent cd0ae73 commit 5529afb
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 55 deletions.
18 changes: 8 additions & 10 deletions clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
"bytes"
"context"
"fmt"
"io"
"log"
neturl "net/url"
"os"
"os/exec"
"strings"

"github.com/binxio/gcloudconfig"
sshconfig "github.com/kevinburke/ssh_config"
"github.com/mitchellh/go-homedir"
Expand All @@ -16,12 +23,6 @@ import (
githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"gopkg.in/src-d/go-git.v4/storage/memory"
"io"
"log"
neturl "net/url"
"os"
"os/exec"
"strings"
)

func getCredentialHelper(url *neturl.URL) string {
Expand Down Expand Up @@ -50,7 +51,6 @@ func getCredentialHelper(url *neturl.URL) string {
}

func getPassword(repositoryUrl *neturl.URL) (transport.AuthMethod, error) {

if os.Getenv("GIT_ASKPASS") == "" && getCredentialHelper(repositoryUrl) == "" {
// No credential helper specified, not passing in credentials
return nil, nil
Expand Down Expand Up @@ -122,8 +122,7 @@ func getGoogleCredentials(url *neturl.URL) (transport.AuthMethod, error) {
}

func identityFileAuthentication(user string, host string) (auth transport.AuthMethod, err error) {

var keyFile = sshconfig.Get(host, "IdentityFile")
keyFile := sshconfig.Get(host, "IdentityFile")
if keyFile, err = homedir.Expand(keyFile); err != nil {
return nil, fmt.Errorf("ERROR: failed to expand home directory of IdentityFile %s, %s",
sshconfig.Get(host, "IdentityFile"), err)
Expand Down Expand Up @@ -192,7 +191,6 @@ func sshAgentAuthentication(user, host, keyFile string, key ssh.PublicKey) (auth
}

func GetAuth(url string) (auth transport.AuthMethod, plainOpen bool, err error) {

if MatchesScheme(url) {
repositoryUrl, err := neturl.Parse(url)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"testing"

"golang.org/x/crypto/ssh"
"gopkg.in/src-d/go-billy.v4/memfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
go_git_ssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"gopkg.in/src-d/go-git.v4/storage/memory"
"io/ioutil"
"os"
"testing"
)

func TestClone(t *testing.T) {

s := fmt.Sprintf("%s/.ssh/id_rsa", os.Getenv("HOME"))
sshKey, err := ioutil.ReadFile(s)
signer, err := ssh.ParsePrivateKey([]byte(sshKey))
Expand Down
8 changes: 4 additions & 4 deletions committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"bytes"
"fmt"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"io"
"log"
"os"
"time"

"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)

func (c *Cru) Commit() (hash plumbing.Hash, err error) {
Expand Down Expand Up @@ -52,7 +53,6 @@ func (c *Cru) Commit() (hash plumbing.Hash, err error) {
}

func (c *Cru) Push() error {

if !c.DryRun {
var progress io.Writer = os.Stderr
if !c.Verbose {
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/binxio/cru/ref"
"github.com/docopt/docopt-go"
"gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
)

type Cru struct {
Expand Down Expand Up @@ -88,7 +89,6 @@ func (c *Cru) WriteFile(filename string, content []byte, perm os.FileMode) error
}

func List(c *Cru, filename string) error {

content, err := c.ReadFile(filename)
if err != nil {
return fmt.Errorf("could not read %s, %s", filename, err)
Expand All @@ -114,7 +114,7 @@ func Update(c *Cru, filename string) error {
content, updated := ref.UpdateReferences(content, c.imageRefs, c.RelPath(filename), c.MatchingTag, c.Verbose)
if updated {
if !c.DryRun {
err := c.WriteFile(filename, content, 0644)
err := c.WriteFile(filename, content, 0o644)
if err != nil {
return fmt.Errorf("failed to overwrite %s with updated references, %s", c.RelPath(filename), err)
}
Expand Down Expand Up @@ -249,7 +249,7 @@ Options:
log.Fatalf("%s\n", err)
}
if !cru.MatchingTag {
for i, _ := range cru.imageRefs {
for i := range cru.imageRefs {
cru.imageRefs[i].SetTag("latest")
}
}
Expand Down
6 changes: 4 additions & 2 deletions ref/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ func TestListReferenceMultiple(t *testing.T) {
and this is another mvanholsteijn/paas-monitor:3.1.0
and this is just a directory Name mvanholsteijn/paas-monitor, which should
not be changed`)
expect := []ContainerImageReference{*MustNewContainerImageReference(`eu.gcr.io/binxio/paas-monitor:v0.3.1`),
*MustNewContainerImageReference(`mvanholsteijn/paas-monitor:3.1.0`)}
expect := []ContainerImageReference{
*MustNewContainerImageReference(`eu.gcr.io/binxio/paas-monitor:v0.3.1`),
*MustNewContainerImageReference(`mvanholsteijn/paas-monitor:3.1.0`),
}

result := FindAllContainerImageReference(input)
for i, ref := range result {
Expand Down
14 changes: 8 additions & 6 deletions ref/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package ref
import (
"bytes"
"fmt"
"log"
"regexp"
"sort"
"strings"

"github.com/docker/distribution/reference"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"log"
"regexp"
"sort"
"strings"
)

var (
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewContainerImageReference(imageReference string) (*ContainerImageReference

return &result, nil
}

func MustNewContainerImageReference(imageReference string) *ContainerImageReference {
r, err := NewContainerImageReference(imageReference)
if err != nil {
Expand All @@ -78,7 +80,7 @@ func (r ContainerImageReference) String() string {
}

func FindAllContainerImageReference(content []byte) []ContainerImageReference {
var result = make(ContainerImageReferences, 0)
result := make(ContainerImageReferences, 0)
allMatches := imageReferencePattern.FindAllIndex(content, -1)
for _, match := range allMatches {
s := string(content[match[0]:match[1]])
Expand Down Expand Up @@ -149,7 +151,7 @@ func UpdateReference(content []byte, reference ContainerImageReference, filename
}
}
if previous < len(content) {
result.Write(content[previous:len(content)])
result.Write(content[previous:])
}

return result.Bytes(), updated
Expand Down
4 changes: 2 additions & 2 deletions ref/resolve_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ref

import (
"testing"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"testing"
)

func TestImageResolve(t *testing.T) {
Expand Down Expand Up @@ -35,7 +36,6 @@ func TestImageResolve(t *testing.T) {
if digest.String() == rr.Digest {
t.Fatalf("expected different Digest than %s, got %s", digest, rr.Digest)
}

}

func TestImageResolves(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions ref/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ not be changed.
And how about a digest like gcr.io/binx-io-public/paas-monitor:v1.0.0?
does that work?
`)
references := []ContainerImageReference{*MustNewContainerImageReference(`gcr.io/binx-io-public/paas-monitor:v1.0.0`),
*MustNewContainerImageReference(`mvanholsteijn/paas-monitor:3.1.0`)}
references := []ContainerImageReference{
*MustNewContainerImageReference(`gcr.io/binx-io-public/paas-monitor:v1.0.0`),
*MustNewContainerImageReference(`mvanholsteijn/paas-monitor:3.1.0`),
}

result, updated := UpdateReferences(input, references, "myfile.txt", false, true)
if !updated {
Expand Down
6 changes: 3 additions & 3 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"encoding/json"
"github.com/binxio/cru/ref"
"gopkg.in/src-d/go-git.v4/plumbing"
"log"
"net/http"
"os"

"github.com/binxio/cru/ref"
"gopkg.in/src-d/go-git.v4/plumbing"
)

type ContainerReferenceUpdateRequest struct {
Expand All @@ -22,7 +23,6 @@ type ContainerReferenceUpdateResponse struct {
}

func (c Cru) ServeHTTP(w http.ResponseWriter, r *http.Request) {

var hash plumbing.Hash
var request ContainerReferenceUpdateRequest
var response ContainerReferenceUpdateResponse
Expand Down
17 changes: 10 additions & 7 deletions tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package tag

import (
"fmt"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"regexp"
"sort"
"strconv"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
)

type Tag struct {
Expand All @@ -25,7 +26,7 @@ var (
)

func MakeTag(tag string) Tag {
var result = Tag{
result := Tag{
Literal: tag,
Version: make([]int, 0, 3),
}
Expand Down Expand Up @@ -66,6 +67,7 @@ func compareInt(a int, b int) int {
}
return 0
}

func compareVersion(a []int, b []int) int {
var result int
for i, v := range a {
Expand Down Expand Up @@ -97,7 +99,6 @@ func (a Tag) Equals(b Tag) bool {
}

func ListAllTags(reference name.Reference) ([]Tag, error) {

tags, err := crane.ListTags(reference.Context().String())
if err != nil {
return nil, fmt.Errorf("could not retrieve tags for %s", reference)
Expand All @@ -111,8 +112,10 @@ func ListAllTags(reference name.Reference) ([]Tag, error) {
return result, nil
}

type TagList []Tag
type TagCategories map[string]TagList
type (
TagList []Tag
TagCategories map[string]TagList
)

func (l TagList) FindGreaterThan(tag Tag) TagList {
result := make(TagList, 0)
Expand All @@ -129,7 +132,7 @@ func (a TagList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a TagList) Less(i, j int) bool { return (a[i]).Compare(a[j]) < 0 }

func MakeTagCategories(tags TagList) TagCategories {
var result = make(map[string]TagList)
result := make(map[string]TagList)
for _, tag := range tags {
if list, ok := result[tag.Category]; ok {
result[tag.Category] = append(list, tag)
Expand Down
5 changes: 3 additions & 2 deletions tag/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package tag

import (
"fmt"
"github.com/google/go-containerregistry/pkg/name"
"testing"

"github.com/google/go-containerregistry/pkg/name"
)

func TestMakeTag(t *testing.T) {
var outputs = []Tag{
outputs := []Tag{
{Literal: "1.15", Version: []int{1, 15}},
{Literal: "1.15.2", Version: []int{1, 15, 2}},
{Literal: "v1.15.2", Version: []int{1, 15, 2}, Prefix: "v", Category: "v|"},
Expand Down
10 changes: 5 additions & 5 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"fmt"
"golang.org/x/tools/godoc/util"
"golang.org/x/tools/godoc/vfs"
"gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-git.v4/plumbing/format/gitignore"
"os"
"path"
"path/filepath"
"strings"

"golang.org/x/tools/godoc/util"
"golang.org/x/tools/godoc/vfs"
"gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-git.v4/plumbing/format/gitignore"
)

type Visitor func(cru *Cru, path string) error
Expand All @@ -36,7 +37,6 @@ func (this BillyVFS) Open(name string) (vfs.ReadSeekCloser, error) {
}

func (c *Cru) walkFn(visitor Visitor, filename string, info os.FileInfo) error {

if info.IsDir() {
var patterns GitIgnorePatterns
patterns, err := gitignore.ReadPatterns(*c.filesystem, strings.Split(filename, "/"))
Expand Down

0 comments on commit 5529afb

Please sign in to comment.