Skip to content
Snippets Groups Projects
Commit 7d1979fe authored by rahix's avatar rahix
Browse files

api: Add a flow3r seed which can be used for app installation

The flow3r seed is a code that can be entered on the badge to install an
app.  This means it needs to be unique and stable for each app.

The idea is that we generate this by hashing the repository slug.  From
the hash, we extract 8 numbers between 0 and 4.  Collision handling is
not yet implemented.
parent 2692df79
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"context" "context"
"crypto/md5"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
...@@ -39,6 +40,7 @@ type appInfo struct { ...@@ -39,6 +40,7 @@ type appInfo struct {
version int version int
commit string commit string
stars int stars int
flow3rSeed string
commitObj *object.Commit commitObj *object.Commit
zip []byte zip []byte
...@@ -358,6 +360,16 @@ func (s *server) getAppInfo(ctx context.Context, pathInRepo, repo string) (*appI ...@@ -358,6 +360,16 @@ func (s *server) getAppInfo(ctx context.Context, pathInRepo, repo string) (*appI
return nil, fmt.Errorf("targzing failed: %w", err) return nil, fmt.Errorf("targzing failed: %w", err)
} }
app.targz = tbytes app.targz = tbytes
// Calculate an 8 digit flow3r seed which can be used to install the
// app. This is based on md5 so ambitious hack3rs can force a certain
// app seed :)
flow3rSeedMd5 := md5.Sum([]byte(repo))
app.flow3rSeed = "";
for i := 0; i < 8; i++ {
app.flow3rSeed += string(flow3rSeedMd5[i] % 5 + byte('0'))
}
return app, nil return app, nil
} }
...@@ -473,6 +485,7 @@ func (s *server) handleApps(w http.ResponseWriter, r *http.Request) { ...@@ -473,6 +485,7 @@ func (s *server) handleApps(w http.ResponseWriter, r *http.Request) {
Description string `json:"description"` Description string `json:"description"`
Version int `json:"version"` Version int `json:"version"`
Stars int `json:"stars"` Stars int `json:"stars"`
Flow3rSeed string `json:"flow3rSeed"`
} }
type res struct { type res struct {
...@@ -499,6 +512,7 @@ func (s *server) handleApps(w http.ResponseWriter, r *http.Request) { ...@@ -499,6 +512,7 @@ func (s *server) handleApps(w http.ResponseWriter, r *http.Request) {
Description: a.appInfo.description, Description: a.appInfo.description,
Version: a.appInfo.version, Version: a.appInfo.version,
Stars: a.appInfo.stars, Stars: a.appInfo.stars,
Flow3rSeed: a.appInfo.flow3rSeed,
}) })
} }
w.Header().Add("Access-Control-Allow-Origin", "*") w.Header().Add("Access-Control-Allow-Origin", "*")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment