5
5
"fmt"
6
6
"io"
7
7
"net/http"
8
+ "strconv"
9
+ "strings"
8
10
9
11
"gopkg.in/yaml.v3"
10
12
)
@@ -49,6 +51,36 @@ func getGitHubSourceFile(endpoint string) (response FileAPIResponse, err error)
49
51
return
50
52
}
51
53
54
+ func parseVersion (version string ) (major int , minor int , patch int ) {
55
+ splitVersion := strings .Split (version , "." )
56
+ if len (splitVersion ) == 3 {
57
+ major , _ = strconv .Atoi (splitVersion [0 ])
58
+ minor , _ = strconv .Atoi (splitVersion [1 ])
59
+ patch , _ = strconv .Atoi (splitVersion [2 ])
60
+ return
61
+ }
62
+ if len (splitVersion ) == 2 {
63
+ major , _ = strconv .Atoi (splitVersion [0 ])
64
+ minor , _ = strconv .Atoi (splitVersion [1 ])
65
+ return
66
+ }
67
+ if len (splitVersion ) == 1 {
68
+ major , _ = strconv .Atoi (splitVersion [0 ])
69
+ return
70
+ }
71
+ return
72
+ }
73
+
74
+ func checkVersion (version string ) error {
75
+ // This is a placeholder to determine behavior for different schema versions
76
+ // but currently only v2.0.0 is supported
77
+ major , minor , patch := parseVersion (version )
78
+ if major != 2 || minor + patch != 0 {
79
+ return fmt .Errorf ("unsupported schema version specified by target: %s" , version )
80
+ }
81
+ return nil
82
+ }
83
+
52
84
func Read (owner , repo , path string ) (si SecurityInsights , err error ) {
53
85
var builder SIBuilder
54
86
// Get Target SI
@@ -64,6 +96,11 @@ func Read(owner, repo, path string) (si SecurityInsights, err error) {
64
96
return
65
97
}
66
98
99
+ err = checkVersion (builder .TargetSI .Header .SchemaVersion )
100
+ if err != nil {
101
+ return
102
+ }
103
+
67
104
// check for parent SI, read if exists
68
105
if builder .TargetSI .Header .ProjectSISource != "" {
69
106
response , err = getGitHubSourceFile (builder .TargetSI .Header .ProjectSISource )
0 commit comments