]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Add global config
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 9 May 2017 14:51:55 +0000 (15:51 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 9 May 2017 14:51:55 +0000 (15:51 +0100)
Modify global metadata to be a map (for easier readability).

Modify per-version metadata to include most recent full version and
XSAs since that point.

Add 'global update' command which will create a metadata file if not
there, and update it if there.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
global.go [new file with mode: 0644]
main.go
meta.go

diff --git a/global.go b/global.go
new file mode 100644 (file)
index 0000000..10a30bb
--- /dev/null
+++ b/global.go
@@ -0,0 +1,88 @@
+package main
+
+import (
+       "fmt"
+       "os"
+       "bufio"
+       "strings"
+)
+
+func MainGlobalUpdate(xsanum int, args []string) (int) {
+       err := OpenRepos()
+       if err != nil {
+               fmt.Printf("Error opening repos: %v\n", err)
+               return 1
+       }
+
+       var limit XenVersion
+       init := false
+       
+       var sm SecurityMeta
+
+       err = sm.Load()
+       if err != nil {
+               if !os.IsNotExist(err) {
+                       fmt.Printf("Error: %v\n", err)
+                       return 1
+               }
+
+               fmt.Printf("Creating new global metadata\nOldest security-supported xen release: ")
+               input := bufio.NewScanner(os.Stdin)
+               if !input.Scan() {
+                       fmt.Printf("Input error\n")
+                       return 1
+               }
+               s := input.Text()
+               // Get rid of newline at the end
+               s = strings.NewReplacer("\n", "").Replace(s)
+               
+               limit = XenVersion(s)
+               if !limit.Check() {
+                       fmt.Printf("Invalid Xen version: %s\n", limit)
+                       return 1
+               }
+
+               sm.Versions = make(map[XenVersion]*VersionMeta)
+               init = true
+       }
+
+       fmt.Printf("Getting Xen releases from treee...\n")
+       versions, err := repos.XenRepos[TreeXen].GetVersions()
+       if err != nil {
+               fmt.Printf("Error getting Xen releases: %v\n", err)
+               return 1
+       }
+
+       for _, fv := range versions {
+               vm, prs := sm.Versions[fv.XenVersion()]
+               if prs {
+                       if fv.Point() > vm.Latest.Point() {
+                               fmt.Printf("New version %v supercedes %v, discarding XSAs\n",
+                                       fv, vm.Latest)
+                               vm.Latest = fv
+                               vm.XSAs = []int{}
+                       }
+               } else if init && fv.XenVersion().IsGreaterEqualThan(limit) {
+                       sm.Versions[fv.XenVersion()] = &VersionMeta{ Latest: fv, XSAs: []int{} }
+               } else {
+                       fmt.Printf("Skipping version %v\n", fv)
+               }
+       }
+
+       if init {
+               fmt.Printf("New global.meta created.  You probably need to"+
+                       "manually enter outstanding XSAs for each version.")
+       }
+
+       err = sm.Save()
+       if err != nil {
+               fmt.Printf("Error saving global metadata: %v\n", err)
+               return 1
+       }
+       
+       return 0
+}
+
+func MainGlobalInfo(xsanum int, args []string) (int) {
+       return 0
+}
diff --git a/main.go b/main.go
index 0d775128382f540643dcfaa99debef32e1b01c7a..c76b0331070daa8b07064959141a9d0717e5c115 100644 (file)
--- a/main.go
+++ b/main.go
@@ -126,6 +126,17 @@ func main() {
                        fmt.Printf("Unknown command: %s\n", cmd)
                        os.Exit(1)
                }
+       } else if tgt == "global" {
+               switch cmd {
+               case "update":
+                       main = MainGlobalUpdate
+                       loadConfig = true
+               case "info":
+                       main = MainGlobalInfo
+               default:
+                       fmt.Printf("Unknown command: %s\n", cmd)
+                       os.Exit(1)
+               }
        }
        
        if loadConfig {
diff --git a/meta.go b/meta.go
index c166fbf58a00eb0dd3685dc650647cd8cb48d4ca..b307b3b4d8158e909f9268d48a7d9d28d99aeb31 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -6,7 +6,6 @@ import (
        "io/ioutil"
        "os"
        "fmt"
-       "time"
 )
 
 type Tree string
@@ -140,16 +139,13 @@ func (tc ToolConfig) GetPath(t Tree) (s string) {
        return
 }
 
-// FIXME: Need to figure out a good way to serialize time in a
-// human-readable way
 type VersionMeta struct {
-       XenVersion
-       ReleaseDate     time.Time
-       SecurityEndDate time.Time
+       Latest XenVersionFull
+       XSAs []int
 }
 
 type SecurityMeta struct {
-       Versions []VersionMeta
+       Versions map[XenVersion]*VersionMeta
 }
 
 const GlobalMetaFilename = "global.meta"