mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 00:50:03 +00:00
updating app config
This commit is contained in:
parent
1c3518424a
commit
cb71ff8b94
@ -66,7 +66,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
Location: account.Location,
|
||||
Image: account.Image,
|
||||
Revision: account.ProfileRevision,
|
||||
Version: CONFIG_VERSION,
|
||||
Version: APP_VERSION,
|
||||
Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func TestAccount(t *testing.T) {
|
||||
dec = json.NewDecoder(resp.Body)
|
||||
var profile Profile
|
||||
dec.Decode(&profile)
|
||||
if profile.Guid == nil {
|
||||
if profile.Guid == "" {
|
||||
t.Errorf("invalid profile")
|
||||
return
|
||||
}
|
||||
|
5
net/server/internal/appValues.go
Normal file
5
net/server/internal/appValues.go
Normal file
@ -0,0 +1,5 @@
|
||||
package databag
|
||||
|
||||
const APP_BODYLIMIT = 1048576
|
||||
const APP_VERSION = "0.0.1"
|
||||
|
@ -6,6 +6,13 @@ import (
|
||||
"databag/internal/store"
|
||||
)
|
||||
|
||||
const CONFIG_CONFIGURED = "configured"
|
||||
const CONFIG_USERNAME = "username"
|
||||
const CONFIG_PASSWORD = "password"
|
||||
const CONFIG_DOMAIN = "domain"
|
||||
const CONFIG_PUBLICLIMIT = "public_limit"
|
||||
const CONFIG_STORAGE = "storage"
|
||||
|
||||
func getStrConfigValue(configId string, empty string) string {
|
||||
var config store.Config
|
||||
err := store.DB.Where("config_id = ?", configId).First(&config).Error
|
||||
|
@ -1,11 +0,0 @@
|
||||
package databag
|
||||
|
||||
const CONFIG_BODYLIMIT = 1048576
|
||||
const CONFIG_VERSION = "0.0.1"
|
||||
|
||||
const CONFIG_CONFIGURED = "configured"
|
||||
const CONFIG_USERNAME = "username"
|
||||
const CONFIG_PASSWORD = "password"
|
||||
const CONFIG_DOMAIN = "domain"
|
||||
const CONFIG_PUBLICLIMIT = "public_limit"
|
||||
const CONFIG_STORAGE = "storage"
|
74
net/server/internal/keys.go
Normal file
74
net/server/internal/keys.go
Normal file
@ -0,0 +1,74 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func GenerateRsaKeyPair() (*rsa.PrivateKey, *rsa.PublicKey) {
|
||||
privkey, _ := rsa.GenerateKey(rand.Reader, 4096)
|
||||
return privkey, &privkey.PublicKey
|
||||
}
|
||||
|
||||
func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string {
|
||||
privkey_bytes := x509.MarshalPKCS1PrivateKey(privkey)
|
||||
privkey_pem := pem.EncodeToMemory(
|
||||
&pem.Block{
|
||||
Type: "RSA PRIVATE KEY",
|
||||
Bytes: privkey_bytes,
|
||||
},
|
||||
)
|
||||
return string(privkey_pem)
|
||||
}
|
||||
|
||||
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) {
|
||||
block, _ := pem.Decode([]byte(privPEM))
|
||||
if block == nil {
|
||||
return nil, errors.New("failed to parse PEM block containing the key")
|
||||
}
|
||||
|
||||
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return priv, nil
|
||||
}
|
||||
|
||||
func ExportRsaPublicKeyAsPemStr(pubkey *rsa.PublicKey) (string, error) {
|
||||
pubkey_bytes, err := x509.MarshalPKIXPublicKey(pubkey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
pubkey_pem := pem.EncodeToMemory(
|
||||
&pem.Block{
|
||||
Type: "RSA PUBLIC KEY",
|
||||
Bytes: pubkey_bytes,
|
||||
},
|
||||
)
|
||||
|
||||
return string(pubkey_pem), nil
|
||||
}
|
||||
|
||||
func ParseRsaPublicKeyFromPemStr(pubPEM string) (*rsa.PublicKey, error) {
|
||||
block, _ := pem.Decode([]byte(pubPEM))
|
||||
if block == nil {
|
||||
return nil, errors.New("failed to parse PEM block containing the key")
|
||||
}
|
||||
|
||||
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch pub := pub.(type) {
|
||||
case *rsa.PublicKey:
|
||||
return pub, nil
|
||||
default:
|
||||
break // fall through
|
||||
}
|
||||
return nil, errors.New("Key type is not RSA")
|
||||
}
|
@ -19,7 +19,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// parse node config
|
||||
r.Body = http.MaxBytesReader(w, r.Body, CONFIG_BODYLIMIT)
|
||||
r.Body = http.MaxBytesReader(w, r.Body, APP_BODYLIMIT)
|
||||
dec := json.NewDecoder(r.Body)
|
||||
dec.DisallowUnknownFields()
|
||||
var config NodeConfig;
|
||||
|
Loading…
Reference in New Issue
Block a user