-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: config outdated-api result filtered by k8s version
Signed-off-by: chenk <hen.keinan@gmail.com>
- Loading branch information
1 parent
d856595
commit 8be3acf
Showing
5 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package artifact | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/aquasecurity/trivy/pkg/log" | ||
) | ||
|
||
const k8sDataFile = "k8s_data" | ||
const K8sRegoDataSubFolder = "k8sData" | ||
|
||
type K8s struct { | ||
K8s Data `json:"k8s"` | ||
} | ||
|
||
type Data struct { | ||
Version string `json:"version"` | ||
} | ||
|
||
func createTempK8sRegoDataFile(version string, regoDataFolder string) error { | ||
k8sData := K8s{Data{Version: version}} | ||
b, err := json.Marshal(&k8sData) | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := os.Stat(regoDataFolder); errors.Is(err, os.ErrNotExist) { | ||
err := os.Mkdir(regoDataFolder, os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return os.WriteFile(filepath.Join(regoDataFolder, fmt.Sprintf("%s-*.json", k8sDataFile)), b, 0600) | ||
} | ||
|
||
func removeK8sDataFolder(filename string) { | ||
if err := os.RemoveAll(filename); err != nil { | ||
log.Logger.Errorf("failed to remove temp file %s: %s:", filename, err) | ||
} | ||
} | ||
|
||
func getTempk8sRegoDataFolder() string { | ||
return filepath.Join(os.TempDir(), K8sRegoDataSubFolder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters