···
···
func (h *Handle) RepoIndex(w http.ResponseWriter, r *http.Request) {
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, "")
···
writeMsg(w, "repo empty")
···
commits, err := gr.Commits()
writeError(w, err.Error(), http.StatusInternalServerError)
···
-
log.Printf("no readme found for %s", path)
mainBranch, err := gr.FindMainBranch(h.c.Repo.MainBranch)
writeError(w, err.Error(), http.StatusInternalServerError)
···
treePath := chi.URLParam(r, "*")
ref := chi.URLParam(r, "ref")
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
files, err := gr.FileTree(treePath)
writeError(w, err.Error(), http.StatusInternalServerError)
···
treePath := chi.URLParam(r, "*")
ref := chi.URLParam(r, "ref")
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
h.showRaw(string(safe), w)
-
h.showFile(string(safe), data, w)
func (h *Handle) Archive(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
file := chi.URLParam(r, "file")
// TODO: extend this to add more files compression (e.g.: xz)
if !strings.HasSuffix(file, ".tar.gz") {
···
// once we start writing to the body we can't report error anymore
// so we are only left with printing the error.
···
// once we start writing to the body we can't report error anymore
// so we are only left with printing the error.
func (h *Handle) Log(w http.ResponseWriter, r *http.Request) {
-
fmt.Println(r.URL.Path)
ref := chi.URLParam(r, "ref")
-
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
commits, err := gr.Commits()
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Diff(w http.ResponseWriter, r *http.Request) {
ref := chi.URLParam(r, "ref")
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Refs(w http.ResponseWriter, r *http.Request) {
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, "")
···
// Non-fatal, we *should* have at least one branch to show.
branches, err := gr.Branches()
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Keys(w http.ResponseWriter, r *http.Request) {
keys, err := h.db.GetAllPublicKeys()
writeError(w, err.Error(), http.StatusInternalServerError)
···
if err := h.db.AddPublicKey(pk); err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
-
log.Printf("adding public key: %s", err)
···
func (h *Handle) NewRepo(w http.ResponseWriter, r *http.Request) {
Name string `json:"name"`
···
repoPath := filepath.Join(h.c.Repo.ScanPath, relativeRepoPath)
err := git.InitBare(repoPath)
writeError(w, err.Error(), http.StatusInternalServerError)
···
// add perms for this user to access the repo
err = h.e.AddRepo(did, ThisServer, relativeRepoPath)
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) AddMember(w http.ResponseWriter, r *http.Request) {
PublicKeys []string `json:"keys"`
···
h.js.UpdateDids([]string{did})
if err := h.e.AddMember(ThisServer, did); err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Init(w http.ResponseWriter, r *http.Request) {
writeError(w, "knot already initialized", http.StatusConflict)
···
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
writeError(w, "invalid request body", http.StatusBadRequest)
writeError(w, "did is empty", http.StatusBadRequest)
···
err := h.db.AddPublicKey(pk)
writeError(w, err.Error(), http.StatusInternalServerError)
writeError(w, err.Error(), http.StatusInternalServerError)
h.js.UpdateDids([]string{data.Did})
if err := h.e.AddOwner(ThisServer, data.Did); err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
-
// Signal that the knot is ready
mac := hmac.New(sha256.New, []byte(h.c.Server.Secret))
···
···
func (h *Handle) RepoIndex(w http.ResponseWriter, r *http.Request) {
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
+
l := h.l.With("path", path, "handler", "RepoIndex")
gr, err := git.Open(path, "")
···
writeMsg(w, "repo empty")
+
l.Error("opening repo", "error", err.Error())
···
commits, err := gr.Commits()
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("fetching commits", "error", err.Error())
···
+
l.Warn("no readme found")
mainBranch, err := gr.FindMainBranch(h.c.Repo.MainBranch)
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("finding main branch", "error", err.Error())
···
treePath := chi.URLParam(r, "*")
ref := chi.URLParam(r, "ref")
+
l := h.l.With("handler", "RepoTree", "ref", ref, "treePath", treePath)
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
files, err := gr.FileTree(treePath)
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("file tree", "error", err.Error())
···
treePath := chi.URLParam(r, "*")
ref := chi.URLParam(r, "ref")
+
l := h.l.With("handler", "FileContent", "ref", ref, "treePath", treePath)
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
h.showRaw(string(safe), w)
+
h.showFile(string(safe), data, w, l)
func (h *Handle) Archive(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
file := chi.URLParam(r, "file")
+
l := h.l.With("handler", "Archive", "name", name, "file", file)
// TODO: extend this to add more files compression (e.g.: xz)
if !strings.HasSuffix(file, ".tar.gz") {
···
// once we start writing to the body we can't report error anymore
// so we are only left with printing the error.
+
l.Error("writing tar file", "error", err.Error())
···
// once we start writing to the body we can't report error anymore
// so we are only left with printing the error.
+
l.Error("flushing?", "error", err.Error())
func (h *Handle) Log(w http.ResponseWriter, r *http.Request) {
ref := chi.URLParam(r, "ref")
+
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
+
l := h.l.With("handler", "Log", "ref", ref, "path", path)
gr, err := git.Open(path, ref)
···
commits, err := gr.Commits()
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("fetching commits", "error", err.Error())
···
func (h *Handle) Diff(w http.ResponseWriter, r *http.Request) {
ref := chi.URLParam(r, "ref")
+
l := h.l.With("handler", "Diff", "ref", ref)
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
gr, err := git.Open(path, ref)
···
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("getting diff", "error", err.Error())
···
func (h *Handle) Refs(w http.ResponseWriter, r *http.Request) {
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
+
l := h.l.With("handler", "Refs")
gr, err := git.Open(path, "")
···
// Non-fatal, we *should* have at least one branch to show.
+
l.Error("getting tags", "error", err.Error())
branches, err := gr.Branches()
+
l.Error("getting branches", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Keys(w http.ResponseWriter, r *http.Request) {
+
l := h.l.With("handler", "Keys")
keys, err := h.db.GetAllPublicKeys()
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("getting public keys", "error", err.Error())
···
if err := h.db.AddPublicKey(pk); err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("adding public key", "error", err.Error())
···
func (h *Handle) NewRepo(w http.ResponseWriter, r *http.Request) {
+
l := h.l.With("handler", "NewRepo")
Name string `json:"name"`
···
repoPath := filepath.Join(h.c.Repo.ScanPath, relativeRepoPath)
err := git.InitBare(repoPath)
+
l.Error("initializing bare repo", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
···
// add perms for this user to access the repo
err = h.e.AddRepo(did, ThisServer, relativeRepoPath)
+
l.Error("adding repo permissions", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) AddMember(w http.ResponseWriter, r *http.Request) {
+
l := h.l.With("handler", "AddMember")
PublicKeys []string `json:"keys"`
···
h.js.UpdateDids([]string{did})
if err := h.e.AddMember(ThisServer, did); err != nil {
+
l.Error("adding member", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
···
func (h *Handle) Init(w http.ResponseWriter, r *http.Request) {
+
l := h.l.With("handler", "Init")
writeError(w, "knot already initialized", http.StatusConflict)
···
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
+
l.Error("failed to decode request body", "error", err.Error())
writeError(w, "invalid request body", http.StatusBadRequest)
+
l.Error("empty DID in request")
writeError(w, "did is empty", http.StatusBadRequest)
···
err := h.db.AddPublicKey(pk)
+
l.Error("failed to add public key", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
+
l.Error("failed to add DID", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
h.js.UpdateDids([]string{data.Did})
if err := h.e.AddOwner(ThisServer, data.Did); err != nil {
+
l.Error("adding owner", "error", err.Error())
writeError(w, err.Error(), http.StatusInternalServerError)
mac := hmac.New(sha256.New, []byte(h.c.Server.Secret))