mirror of https://github.com/docker/docs.git
set logrus to stderr and refactor list/lookup
This commit is contained in:
parent
91c1380070
commit
0ce1572c20
|
@ -24,9 +24,11 @@ const privDir string = configPath + "private/"
|
||||||
const tufDir string = configPath + "tuf/"
|
const tufDir string = configPath + "tuf/"
|
||||||
|
|
||||||
var caStore trustmanager.X509Store
|
var caStore trustmanager.X509Store
|
||||||
|
var rawOutput bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logrus.SetLevel(logrus.ErrorLevel)
|
logrus.SetLevel(logrus.ErrorLevel)
|
||||||
|
logrus.SetOutput(os.Stderr)
|
||||||
// Retrieve current user to get home directory
|
// Retrieve current user to get home directory
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,11 +95,13 @@ func main() {
|
||||||
NotaryCmd.AddCommand(cmdKeys)
|
NotaryCmd.AddCommand(cmdKeys)
|
||||||
NotaryCmd.AddCommand(cmdTufInit)
|
NotaryCmd.AddCommand(cmdTufInit)
|
||||||
NotaryCmd.AddCommand(cmdTufList)
|
NotaryCmd.AddCommand(cmdTufList)
|
||||||
|
cmdTufList.Flags().BoolVarP(&rawOutput, "raw", "", false, "Instructs notary list to output a non-pretty printed version of the targets list. Useful if you need to parse the list.")
|
||||||
NotaryCmd.AddCommand(cmdTufAdd)
|
NotaryCmd.AddCommand(cmdTufAdd)
|
||||||
NotaryCmd.AddCommand(cmdTufRemove)
|
NotaryCmd.AddCommand(cmdTufRemove)
|
||||||
NotaryCmd.AddCommand(cmdTufPublish)
|
NotaryCmd.AddCommand(cmdTufPublish)
|
||||||
cmdTufPublish.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location")
|
cmdTufPublish.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location")
|
||||||
NotaryCmd.AddCommand(cmdTufLookup)
|
NotaryCmd.AddCommand(cmdTufLookup)
|
||||||
|
cmdTufLookup.Flags().BoolVarP(&rawOutput, "raw", "", false, "Instructs notary lookup to output a non-pretty printed version of the targets list. Useful if you need to parse the list.")
|
||||||
cmdTufLookup.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location")
|
cmdTufLookup.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location")
|
||||||
|
|
||||||
NotaryCmd.Execute()
|
NotaryCmd.Execute()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/endophage/gotuf"
|
"github.com/endophage/gotuf"
|
||||||
"github.com/endophage/gotuf/client"
|
"github.com/endophage/gotuf/client"
|
||||||
"github.com/endophage/gotuf/data"
|
"github.com/endophage/gotuf/data"
|
||||||
|
@ -209,36 +210,24 @@ func tufList(cmd *cobra.Command, args []string) {
|
||||||
"json",
|
"json",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
rootJSON, err := remote.GetMeta("root", 5<<20)
|
c, err := bootstrapClient(remote, repo, kdb)
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Couldn't get initial root")
|
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
|
||||||
root := &data.Signed{}
|
|
||||||
err = json.Unmarshal(rootJSON, root)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Couldn't parse initial root")
|
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
|
||||||
// TODO: Validate the root file against the key store
|
|
||||||
err = repo.SetRoot(root)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error setting root")
|
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
c := client.NewClient(
|
|
||||||
repo,
|
|
||||||
remote,
|
|
||||||
kdb,
|
|
||||||
)
|
|
||||||
|
|
||||||
err = c.Update()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for name, meta := range repo.Targets["targets"].Signed.Targets {
|
err = c.Update()
|
||||||
fmt.Println(name, " ", meta.Hashes["sha256"], " ", meta.Length)
|
if err != nil {
|
||||||
|
logrus.Error("Error updating client: ", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if rawOutput {
|
||||||
|
for name, meta := range repo.Targets["targets"].Signed.Targets {
|
||||||
|
fmt.Println(name, " ", meta.Hashes["sha256"], " ", meta.Length)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for name, meta := range repo.Targets["targets"].Signed.Targets {
|
||||||
|
fmt.Println(name, " ", meta.Hashes["sha256"], " ", meta.Length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,39 +247,25 @@ func tufLookup(cmd *cobra.Command, args []string) {
|
||||||
"json",
|
"json",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
rootJSON, err := remote.GetMeta("root", 5<<20)
|
c, err := bootstrapClient(remote, repo, kdb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Couldn't get initial root")
|
return
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
}
|
||||||
root := &data.Signed{}
|
|
||||||
err = json.Unmarshal(rootJSON, root)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Couldn't parse initial root")
|
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
|
||||||
// TODO: Validate the root file against the key store
|
|
||||||
err = repo.SetRoot(root)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error setting root")
|
|
||||||
fatalf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
c := client.NewClient(
|
|
||||||
repo,
|
|
||||||
remote,
|
|
||||||
kdb,
|
|
||||||
)
|
|
||||||
|
|
||||||
err = c.Update()
|
err = c.Update()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Error("Error updating client: ", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
meta := c.TargetMeta(targetName)
|
meta := c.TargetMeta(targetName)
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
|
logrus.Infof("Target %s not found in %s.", targetName, gun)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(targetName, fmt.Sprintf("sha256:%s", meta.Hashes["sha256"]), meta.Length)
|
if rawOutput {
|
||||||
|
fmt.Println(targetName, fmt.Sprintf("sha256:%s", meta.Hashes["sha256"]), meta.Length)
|
||||||
|
} else {
|
||||||
|
fmt.Println(targetName, fmt.Sprintf("sha256:%s", meta.Hashes["sha256"]), meta.Length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tufPublish(cmd *cobra.Command, args []string) {
|
func tufPublish(cmd *cobra.Command, args []string) {
|
||||||
|
@ -392,3 +367,25 @@ func saveRepo(repo *tuf.TufRepo, filestore store.MetadataStore) error {
|
||||||
filestore.SetMeta("timestamp", timestampJSON)
|
filestore.SetMeta("timestamp", timestampJSON)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bootstrapClient(remote store.RemoteStore, repo *tuf.TufRepo, kdb *keys.KeyDB) (*client.Client, error) {
|
||||||
|
rootJSON, err := remote.GetMeta("root", 5<<20)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
root := &data.Signed{}
|
||||||
|
err = json.Unmarshal(rootJSON, root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// TODO: Validate the root file against the key store
|
||||||
|
err = repo.SetRoot(root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return client.NewClient(
|
||||||
|
repo,
|
||||||
|
remote,
|
||||||
|
kdb,
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue