-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes incorrect filepath reporting in sarif output & added e2e tests for sarif output #863
Changes from all commits
c544b1a
599beda
f6b03f4
83a4c53
418d01b
acab923
8d11516
33bf96a
72638fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright (C) 2020 Accurics, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"os" | ||
) | ||
|
||
// GetFileMode fetches the filemode from a file path | ||
func GetFileMode(path string) *os.FileMode { | ||
fi, err := os.Stat(path) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
zap.S().Errorf("file %s does not exist.", path) | ||
} else { | ||
zap.S().Errorf("unable to fetch file info for path %s.", path) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method may panic. os.Stat() returns nil file info on an error and we are just logging the error and not returning. |
||
return nil | ||
} | ||
mode := fi.Mode() | ||
return &mode | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
/* | ||
Copyright (C) 2020 Accurics, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
|
@@ -56,19 +72,24 @@ func LoadJSON(filePath string) ([]*IacDocument, error) { | |
|
||
// AreEqualJSON validate if two json strings are equal | ||
func AreEqualJSON(s1, s2 string) (bool, error) { | ||
return AreEqualJSONBytes([]byte(s1), []byte(s2)) | ||
} | ||
|
||
// AreEqualJSONBytes validate if two json byte arrays are equal | ||
func AreEqualJSONBytes(b1, b2 []byte) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use |
||
var o1 interface{} | ||
var o2 interface{} | ||
|
||
errmsg := "error json unmarshalling string: %s. error: %v" | ||
errmsg := "error json unmarshalling bytes: %s. error: %v" | ||
|
||
var err error | ||
err = json.Unmarshal([]byte(s1), &o1) | ||
err = json.Unmarshal(b1, &o1) | ||
if err != nil { | ||
return false, fmt.Errorf(errmsg, s1, err.Error()) | ||
return false, fmt.Errorf(errmsg, b1, err.Error()) | ||
} | ||
err = json.Unmarshal([]byte(s2), &o2) | ||
err = json.Unmarshal(b2, &o2) | ||
if err != nil { | ||
return false, fmt.Errorf(errmsg, s2, err.Error()) | ||
return false, fmt.Errorf(errmsg, b2, err.Error()) | ||
} | ||
|
||
return reflect.DeepEqual(o1, o2), nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing copyright header?