Skip to content

Commit

Permalink
staticcheck: fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sontags committed Jan 4, 2020
1 parent c282e3e commit 4176fd1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ func (a App) rotateCmd(cmd *cobra.Command, args []string) {
exitOnErr(err)

err = b.Write(p.Name(), p.Type(), newEncrypted)
exitOnErr(err)

fmt.Printf("done!\n")
}
}
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func NewConfig(path string) (config, error) {
c := defaults()
data, err := ioutil.ReadFile(path)
if err != nil {
return c, fmt.Errorf("Could not read file %s: %s", path, err.Error())
return c, fmt.Errorf("could not read file %s: %s", path, err.Error())
}
err = yaml.Unmarshal(data, &c)
if err != nil {
return c, fmt.Errorf("Could not read data from config file %s: %s", path, err.Error())
return c, fmt.Errorf("could not read data from config file %s: %s", path, err.Error())
}

c.BagPath = tidyPath(c.BagPath)
Expand Down
15 changes: 9 additions & 6 deletions crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewCrypt(pubFile, privFile string) (Crypt, error) {

pubData, err := ioutil.ReadFile(pubFile)
if err != nil {
return c, fmt.Errorf("Error while reading public key file %s: %s", pubFile, err.Error())
return c, fmt.Errorf("error while reading public key file %s: %s", pubFile, err.Error())
}
err = c.bytesToPublicKey(pubData)
if err != nil {
Expand All @@ -34,7 +34,7 @@ func NewCrypt(pubFile, privFile string) (Crypt, error) {

privData, err := ioutil.ReadFile(privFile)
if err != nil {
return c, fmt.Errorf("Error while reading private key file %s: %s", privFile, err.Error())
return c, fmt.Errorf("error while reading private key file %s: %s", privFile, err.Error())
}
err = c.bytesToPrivateKeyBlock(privData)
if err != nil {
Expand All @@ -59,7 +59,7 @@ func (c Crypt) Decrypt(data, pass []byte) ([]byte, error) {
func (c *Crypt) bytesToPrivateKeyBlock(priv []byte) error {
block, _ := pem.Decode(priv)
if block == nil {
return fmt.Errorf("Private key could not be decoded")
return fmt.Errorf("private key could not be decoded")
}
c.privateKeyBlock = block
return nil
Expand All @@ -86,7 +86,7 @@ func (c *Crypt) bytesToPublicKey(pub []byte) error {
tokens := strings.Split(string(pub), " ")

if len(tokens) < 2 {
return fmt.Errorf("Invalid key format; must contain at least two fields (keytype data [comment])")
return fmt.Errorf("invalid key format; must contain at least two fields (keytype data [comment])")
}

key_type := tokens[0]
Expand All @@ -96,9 +96,12 @@ func (c *Crypt) bytesToPublicKey(pub []byte) error {
}

format, e, n, err := c.getRSAValues(data)
if err != nil {
return err
}

if format != key_type {
return fmt.Errorf("Key type said %s, but encoded format said %s. These should match!", key_type, format)
return fmt.Errorf("key type said %s, but encoded format said %s. these should match", key_type, format)
}

c.publicKey = &rsa.PublicKey{
Expand Down Expand Up @@ -154,7 +157,7 @@ func (c Crypt) getRSAValues(data []byte) (format string, e *big.Int, n *big.Int,
return
}

data, n, err = c.readBigInt(data, length)
_, n, err = c.readBigInt(data, length)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion profile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewProfile(kind string) (Profile, error) {
empty, ok := ptr[kind]
if !ok {
kinds := []string{}
for k, _ := range ptr {
for k := range ptr {
kinds = append(kinds, k)
}
return nil, fmt.Errorf("Profile type '%s' does not exist, must be one of the following: %s", kind, strings.Join(kinds, ", "))
Expand Down
8 changes: 4 additions & 4 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func NewBag(path string) (Bag, error) {
b := Bag{}
stat, err := os.Stat(path)
if err != nil {
return b, fmt.Errorf("Scum Bag '%s' could not be openend: %s", path, err.Error())
return b, fmt.Errorf("scum bag '%s' could not be openend: %s", path, err.Error())
}

if !stat.IsDir() {
return b, fmt.Errorf("Scum Bag '%s' is not a Directory", path)
return b, fmt.Errorf("scum bag '%s' is not a Directory", path)
}

b.Base = path
Expand All @@ -38,7 +38,7 @@ func (b Bag) List(filters []string) (map[string]string, error) {

files, err := ioutil.ReadDir(b.Base)
if err != nil {
return out, fmt.Errorf("Scum Bag '%s' could not be listed: %s", b.Base, err.Error())
return out, fmt.Errorf("scum bag '%s' could not be listed: %s", b.Base, err.Error())
}

for _, file := range files {
Expand All @@ -48,7 +48,7 @@ func (b Bag) List(filters []string) (map[string]string, error) {

seg := strings.SplitN(file.Name(), bagNameSeparator, 2)
if len(seg) < 2 {
return out, fmt.Errorf("Scum Bag '%s' contains malformed file: %s", b.Base, file.Name())
return out, fmt.Errorf("scum bag '%s' contains malformed file: %s", b.Base, file.Name())
}

kind := seg[0]
Expand Down
5 changes: 4 additions & 1 deletion type_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func (p *AWSProfile) MountSnippet() (string, string) {

func (p *AWSProfile) RotateCredentials() ([]byte, error) {
sess, _, err := p.getSession()
if err != nil {
return []byte{}, err
}

iamClient := iam.New(sess)
respListAccessKeys, err := iamClient.ListAccessKeys(&iam.ListAccessKeysInput{})
Expand Down Expand Up @@ -166,7 +169,7 @@ func (p *AWSProfile) getSession() (*session.Session, string, error) {
stsClient := sts.New(sess)
respGetCallerIdentity, err := stsClient.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err != nil {
return sess, "", fmt.Errorf("Error getting caller identity: %s. Is the key disabled?", err.Error())
return sess, "", fmt.Errorf("error getting caller identity: %s. Is the key disabled?", err.Error())
}
return sess, fmt.Sprintf("Your user ARN is: %s", *respGetCallerIdentity.Arn), nil
}

0 comments on commit 4176fd1

Please sign in to comment.