func AddTarget(role string, r *tuf.TufRepo) (name string, meta data.FileMeta, content []byte, err error) { randness := fuzz.Continue{} content = RandomByteSlice(1024) name = randness.RandString() t := data.FileMeta{ Length: int64(len(content)), Hashes: data.Hashes{ "sha256": utils.DoHash("sha256", content), "sha512": utils.DoHash("sha512", content), }, } files := data.Files{name: t} _, err = r.AddTargets(role, files) return }
func applyTargetsChange(repo *tuf.TufRepo, c changelist.Change) error { var err error switch c.Action() { case changelist.ActionCreate: logrus.Debug("changelist add: ", c.Path()) meta := &data.FileMeta{} err = json.Unmarshal(c.Content(), meta) if err != nil { return err } files := data.Files{c.Path(): *meta} _, err = repo.AddTargets(c.Scope(), files) case changelist.ActionDelete: logrus.Debug("changelist remove: ", c.Path()) err = repo.RemoveTargets(c.Scope(), c.Path()) default: logrus.Debug("action not yet supported: ", c.Action()) } if err != nil { return err } return nil }