Skip to content

Commit

Permalink
[FIX] update outdated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fguisso committed May 14, 2023
1 parent b732730 commit 1f8eecd
Show file tree
Hide file tree
Showing 12 changed files with 1,213 additions and 193 deletions.
5 changes: 2 additions & 3 deletions api/auth/pbkdf2caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package auth

import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"hash"
"io"
Expand All @@ -30,9 +31,7 @@ func (pC *Pbkdf2Caller) DecodeSaltValue(salt string) ([]byte, error) {

// GenHashValue returns the hash value given all pbkdf2 parameters.
func (pC *Pbkdf2Caller) GenHashValue(value, salt []byte, iter, keyLen int, h hash.Hash) string {
return base64.StdEncoding.EncodeToString(pbkdf2.Key(value, salt, iter, keyLen, func() hash.Hash {
return h
}))
return base64.StdEncoding.EncodeToString(pbkdf2.Key(value, salt, iter, keyLen, sha256.New))
}

// GenerateSalt returns a random salt and en error.
Expand Down
22 changes: 14 additions & 8 deletions api/dockers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d Docker) CreateContainer(image, cmd string) (string, error) {
Image: image,
Tty: true,
Cmd: []string{"/bin/sh", "-c", cmd},
}, nil, nil, "")
}, nil, nil, nil, "")

if err != nil {
log.Error("CreateContainer", logInfoAPI, 3005, err)
Expand All @@ -99,19 +99,26 @@ func (d Docker) StartContainer() error {
// WaitContainer returns when container finishes executing cmd.
func (d Docker) WaitContainer(timeOutInSeconds int) error {
ctx := goContext.Background()
statusCode, err := d.client.ContainerWait(ctx, d.CID)
containerWaitC, errC := d.client.ContainerWait(ctx, d.CID, container.WaitConditionNotRunning)

if statusCode != 0 {
return fmt.Errorf("Error in POST to wait the container with statusCode %d", statusCode)
select {
case err := <-errC:
if err != nil {
return err
}
case containerWait := <-containerWaitC:
if containerWait.StatusCode != 0 {
return fmt.Errorf("Error in POST to wait the container with statusCode %d", containerWait.StatusCode)
}
}

return err
return nil
}

// StopContainer stops an active container by it's CID
func (d Docker) StopContainer() error {
ctx := goContext.Background()
err := d.client.ContainerStop(ctx, d.CID, nil)
err := d.client.ContainerStop(ctx, d.CID, container.StopOptions{})
if err != nil {
log.Error("StopContainer", logInfoAPI, 3022, err)
}
Expand All @@ -135,7 +142,6 @@ func (d Docker) ListStoppedContainers() ([]Docker, error) {
dockerFilters := filters.NewArgs()
dockerFilters.Add("status", "exited")
options := dockerTypes.ContainerListOptions{
Quiet: true,
All: true,
Filters: dockerFilters,
}
Expand Down Expand Up @@ -246,7 +252,7 @@ func (d Docker) ListImages() ([]dockerTypes.ImageSummary, error) {
}

// RemoveImage removes an image.
func (d Docker) RemoveImage(imageID string) ([]dockerTypes.ImageDelete, error) {
func (d Docker) RemoveImage(imageID string) ([]dockerTypes.ImageDeleteResponseItem, error) {
ctx := goContext.Background()
return d.client.ImageRemove(ctx, imageID, dockerTypes.ImageRemoveOptions{Force: true})
}
Expand Down
13 changes: 8 additions & 5 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ go 1.14

require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v23.0.6+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/globocom/glbgelf v0.0.0-20190310030100-36e52796d86a
github.com/google/uuid v1.1.2
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/lib/pq v1.5.2
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/viper v1.7.0
github.com/valyala/fasttemplate v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/crypto v0.9.0
golang.org/x/net v0.10.0
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gopkg.in/Graylog2/go-gelf.v2 v2.0.0-20191017102106-1550ee647df0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gotest.tools/v3 v3.4.0 // indirect
k8s.io/api v0.20.4
k8s.io/apimachinery v0.20.4
k8s.io/client-go v0.20.4
Expand Down
72 changes: 55 additions & 17 deletions api/go.sum

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions api/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package token

import (
"crypto/sha256"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -41,14 +42,9 @@ func (tH *THandler) GenerateAccessToken(repo types.TokenRequest) (string, error)
if err != nil {
return "", err
}
hashFunction := tH.HashGen.GetHashName()
keyLength := tH.HashGen.GetKeyLength()
iterations := tH.HashGen.GetIterations()
h, isOk := auth.GetValidHashFunction(hashFunction)
if !isOk {
return "", errors.New("Invalid hash function")
}
accessToken.HuskyToken = tH.HashGen.GenHashValue([]byte(token), bSalt, iterations, keyLength, h)
accessToken.HuskyToken = tH.HashGen.GenHashValue([]byte(token), bSalt, iterations, keyLength, sha256.New())
accessToken.URL = validatedURL
accessToken.IsValid = true
accessToken.CreatedAt = tH.External.GetTimeNow()
Expand Down Expand Up @@ -76,7 +72,7 @@ func (tH *THandler) GetSplitted(rcvToken string) (string, string, error) {
return parsed[0], parsed[1], nil
}

//ValidateRandomData will calculate the hash from the
// ValidateRandomData will calculate the hash from the
// received data and compare with hashdata passed in
// the argument. The hash calculated uses the salt
// passed in the argument.
Expand Down
13 changes: 3 additions & 10 deletions api/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
package user

import (
"io"
"os"

"crypto/rand"
"crypto/sha256"
"encoding/base64"
"errors"
"hash"
"io"

"github.com/globocom/huskyCI/api/auth"
apiContext "github.com/globocom/huskyCI/api/context"
Expand Down Expand Up @@ -40,10 +39,6 @@ func InsertDefaultUser() error {
keyLength := pbkdf2Caller.GetKeyLength()
iterations := pbkdf2Caller.GetIterations()

hashFunction, isValid := auth.GetValidHashFunction(defaultHashFunction)
if !isValid {
return errors.New("Invalid hash function")
}
salt := make([]byte, 64)
_, err := io.ReadFull(rand.Reader, salt)
if err != nil {
Expand All @@ -55,9 +50,7 @@ func InsertDefaultUser() error {
newUser.Iterations = iterations
newUser.KeyLen = keyLength
newUser.Salt = base64.StdEncoding.EncodeToString(salt)
hashedPass := pbkdf2.Key([]byte(DefaultAPIPassword), salt, iterations, keyLength, func() hash.Hash {
return hashFunction
})
hashedPass := pbkdf2.Key([]byte(DefaultAPIPassword), salt, iterations, keyLength, sha256.New)
newUser.Password = base64.StdEncoding.EncodeToString(hashedPass)
return apiContext.APIConfiguration.DBInstance.InsertDBUser(newUser)
}
21 changes: 12 additions & 9 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ go 1.14

require (
github.com/dsnet/compress v0.0.1 // indirect
github.com/frankban/quicktest v1.10.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.1.1
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0
github.com/mholt/archiver v3.1.1+incompatible
github.com/mitchellh/go-homedir v1.1.0
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/src-d/enry/v2 v2.1.0
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
)
Loading

0 comments on commit 1f8eecd

Please sign in to comment.