Skip to content

Commit

Permalink
Fix gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Mar 5, 2023
1 parent 904bb13 commit e6d112d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
16 changes: 8 additions & 8 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func makeBashCompletionFileIfNeeded(cmd *cobra.Command) error {
}

if !file.IsDir(path) {
if err := os.MkdirAll(filepath.Dir(path), 0775); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
return fmt.Errorf("can not create bash-completion file: %w", err)
}
}
fp, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0664)
fp, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return fmt.Errorf("can not open .bash_completion: %w", err)
}
Expand All @@ -84,7 +84,7 @@ func makeFishCompletionFileIfNeeded(cmd *cobra.Command) error {
}

path := fishCompletionFilePath()
if err := os.MkdirAll(filepath.Dir(path), 0775); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
return fmt.Errorf("can not create fish-completion file: %w", err)
}

Expand All @@ -103,7 +103,7 @@ func makeZshCompletionFileIfNeeded(cmd *cobra.Command) error {
}

path := zshCompletionFilePath()
if err := os.MkdirAll(filepath.Dir(path), 0775); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
return fmt.Errorf("can not create zsh-completion file: %w", err)
}

Expand All @@ -128,7 +128,7 @@ autoload -Uz compinit && compinit -i
`
zshrcPath := zshrcPath()
if !file.IsFile(zshrcPath) {
fp, err := os.OpenFile(zshrcPath, os.O_RDWR|os.O_CREATE, 0664)
fp, err := os.OpenFile(zshrcPath, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return fmt.Errorf("can not open .zshrc: %w", err)
}
Expand All @@ -152,7 +152,7 @@ autoload -Uz compinit && compinit -i
return nil
}

fp, err := os.OpenFile(zshrcPath, os.O_RDWR|os.O_APPEND, 0664)
fp, err := os.OpenFile(zshrcPath, os.O_RDWR|os.O_APPEND, 0600)
if err != nil {
return fmt.Errorf("can not open .zshrc: %w", err)
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func isSameFishCompletionFile(cmd *cobra.Command) bool {
return false
}

if bytes.Compare(currentFishCompletion.Bytes(), fishCompletionInLocal) != 0 {
if !bytes.Equal(currentFishCompletion.Bytes(), fishCompletionInLocal) {
return false
}
return true
Expand All @@ -229,7 +229,7 @@ func isSameZshCompletionFile(cmd *cobra.Command) bool {
return false
}

if bytes.Compare(currentZshCompletion.Bytes(), zshCompletionInLocal) != 0 {
if !bytes.Equal(currentZshCompletion.Bytes(), zshCompletionInLocal) {
return false
}
return true
Expand Down
13 changes: 1 addition & 12 deletions cmd/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,6 @@ type LeadTimeStat struct {
LeadTimeMedian float64 `json:"lead_time_median,omitempty"`
}

func (lts *LeadTimeStat) json(w io.Writer) error {
bytes, err := json.Marshal(lts)
if err != nil {
return err
}

fmt.Fprintln(w, string(bytes))

return nil
}

type DetailLeadTimeStat struct {
LeadTimeStatistics *LeadTimeStat `json:"lead_time_statistics,omitempty"`
PullRequests []*usecase.PullRequest `json:"pull_requests,omitempty"`
Expand All @@ -295,7 +284,7 @@ func newDetailLeadTimeStat(lt *usecase.LeadTime) *DetailLeadTimeStat {
}

func (dlts *DetailLeadTimeStat) json(w io.Writer, all bool) error {
bytes := []byte{}
var bytes []byte
var err error
if all {
bytes, err = json.Marshal(dlts)
Expand Down

0 comments on commit e6d112d

Please # to comment.