mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
more golint renaming
This commit is contained in:
parent
19dc8ca900
commit
d5e8fc7394
@ -72,7 +72,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
fingerprint := hex.EncodeToString(hash[:])
|
||||
|
||||
// create path for account data
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + fingerprint
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + fingerprint
|
||||
if err := os.Mkdir(path, os.ModePerm); err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
@ -121,7 +121,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
Image: detail.Image,
|
||||
Revision: account.ProfileRevision,
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
}
|
||||
|
||||
// send response
|
||||
|
@ -37,7 +37,7 @@ func AddAccountApp(w http.ResponseWriter, r *http.Request) {
|
||||
Name: appData.Name,
|
||||
Description: appData.Description,
|
||||
Image: appData.Image,
|
||||
Url: appData.Url,
|
||||
URL: appData.URL,
|
||||
Token: access,
|
||||
};
|
||||
|
||||
|
@ -70,7 +70,7 @@ func AddChannelTopicAsset(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// save new file
|
||||
id := uuid.New().String()
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + channelSlot.Account.GUID + "/" + id
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + channelSlot.Account.GUID + "/" + id
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||
ErrResponse(w, http.StatusBadRequest, err)
|
||||
return
|
||||
@ -172,7 +172,7 @@ func AddChannelTopicAsset(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func isStorageFull(act *store.Account) (full bool, err error) {
|
||||
|
||||
storage := getNumConfigValue(CONFIG_STORAGE, 0);
|
||||
storage := getNumConfigValue(CNFStorage, 0);
|
||||
if storage == 0 {
|
||||
return
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func ClearCardNotes(w http.ResponseWriter, r *http.Request) {
|
||||
// save and update contact revision
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
slot.Card.Notes = ""
|
||||
slot.Card.DetailRevision += 1
|
||||
slot.Card.DetailRevision++
|
||||
if res := tx.Save(&slot.Card).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ func GetAccountAvailable(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func getAvailableAccounts() (available int64, err error) {
|
||||
|
||||
open := getBoolConfigValue(CONFIG_OPENACCESS, true)
|
||||
limit := getNumConfigValue(CONFIG_ACCOUNTLIMIT, 16)
|
||||
open := getBoolConfigValue(CNFOpenAccess, true)
|
||||
limit := getNumConfigValue(CNFAccountLimit, 16)
|
||||
|
||||
var count int64
|
||||
if err = store.DB.Model(&store.Account{}).Count(&count).Error; err != nil {
|
||||
|
@ -23,7 +23,7 @@ func GetAccountListing(w http.ResponseWriter, r *http.Request) {
|
||||
Location: account.AccountDetail.Location,
|
||||
ImageSet: account.AccountDetail.Image != "",
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ func GetAccountListingMessage(w http.ResponseWriter, r *http.Request) {
|
||||
Location: detail.Location,
|
||||
Image: detail.Image,
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
}
|
||||
msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||
APPSignPKCS1V15, account.GUID, APPMsgIdentity, &identity)
|
||||
|
@ -21,7 +21,7 @@ func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// construct response
|
||||
status := &AccountStatus{}
|
||||
status.StorageAvailable = getNumConfigValue(CONFIG_STORAGE, 0);
|
||||
status.StorageAvailable = getNumConfigValue(CNFStorage, 0);
|
||||
for _, asset := range assets {
|
||||
status.StorageUsed += asset.Size
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func GetChannelTopicAsset(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// construct file path
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + act.GUID + "/" + asset.AssetID
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + act.GUID + "/" + asset.AssetID
|
||||
http.ServeFile(w, r, path)
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,10 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// get node config fields
|
||||
var config NodeConfig;
|
||||
config.Domain = getStrConfigValue(CONFIG_DOMAIN, "");
|
||||
config.AccountLimit = getNumConfigValue(CONFIG_ACCOUNTLIMIT, 16);
|
||||
config.OpenAccess = getBoolConfigValue(CONFIG_OPENACCESS, true);
|
||||
config.AccountStorage = getNumConfigValue(CONFIG_STORAGE, 0);
|
||||
config.Domain = getStrConfigValue(CNFDomain, "");
|
||||
config.AccountLimit = getNumConfigValue(CNFAccountLimit, 16);
|
||||
config.OpenAccess = getBoolConfigValue(CNFOpenAccess, true);
|
||||
config.AccountStorage = getNumConfigValue(CNFStorage, 0);
|
||||
|
||||
WriteResponse(w, config);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
func GetNodeStatus(w http.ResponseWriter, r *http.Request) {
|
||||
var config store.Config
|
||||
err := store.DB.Where("config_id = ?", CONFIG_CONFIGURED).First(&config).Error
|
||||
err := store.DB.Where("config_id = ?", CNFConfigured).First(&config).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
WriteResponse(w, true)
|
||||
|
@ -50,7 +50,7 @@ func GetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
Location: detail.Location,
|
||||
Image: detail.Image,
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
}
|
||||
|
||||
msg, err := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||
|
@ -40,7 +40,7 @@ func GetProfileMessage(w http.ResponseWriter, r *http.Request) {
|
||||
Location: detail.Location,
|
||||
Image: detail.Image,
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
}
|
||||
msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||
APPSignPKCS1V15, account.GUID, APPMsgIdentity, &identity)
|
||||
|
@ -78,7 +78,7 @@ func RemoveAccount(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// delete asset files
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + account.GUID
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + account.GUID
|
||||
if err = os.RemoveAll(path); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func RemoveNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// delete asset files
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + account.GUID
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + account.GUID
|
||||
if err = os.RemoveAll(path); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func SetAccountAccess(w http.ResponseWriter, r *http.Request) {
|
||||
Name: appData.Name,
|
||||
Description: appData.Description,
|
||||
Image: appData.Image,
|
||||
Url: appData.Url,
|
||||
URL: appData.URL,
|
||||
Token: access,
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ func SetCardNotes(w http.ResponseWriter, r *http.Request) {
|
||||
// save and update contact revision
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
slot.Card.Notes = notes
|
||||
slot.Card.DetailRevision += 1
|
||||
slot.Card.DetailRevision++
|
||||
if res := tx.Save(&slot.Card).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func SetCardStatus(w http.ResponseWriter, r *http.Request) {
|
||||
slot.Card.NotifiedArticle = articleRevision
|
||||
slot.Card.NotifiedChannel = channelRevision
|
||||
slot.Card.NotifiedProfile = profileRevision
|
||||
slot.Card.DetailRevision += 1
|
||||
slot.Card.DetailRevision++
|
||||
|
||||
// save and update contact revision
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
|
@ -29,7 +29,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "config_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"str_value"}),
|
||||
}).Create(&store.Config{ConfigID: CONFIG_DOMAIN, StrValue: config.Domain}).Error; res != nil {
|
||||
}).Create(&store.Config{ConfigID: CNFDomain, StrValue: config.Domain}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "config_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"num_value"}),
|
||||
}).Create(&store.Config{ConfigID: CONFIG_ACCOUNTLIMIT, NumValue: config.AccountLimit}).Error; res != nil {
|
||||
}).Create(&store.Config{ConfigID: CNFAccountLimit, NumValue: config.AccountLimit}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "config_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
|
||||
}).Create(&store.Config{ConfigID: CONFIG_ACCOUNTLIMIT, BoolValue: config.OpenAccess}).Error; res != nil {
|
||||
}).Create(&store.Config{ConfigID: CNFAccountLimit, BoolValue: config.OpenAccess}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "config_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"num_value"}),
|
||||
}).Create(&store.Config{ConfigID: CONFIG_STORAGE, NumValue: config.AccountStorage}).Error; res != nil {
|
||||
}).Create(&store.Config{ConfigID: CNFStorage, NumValue: config.AccountStorage}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
func SetNodeStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var config store.Config
|
||||
err := store.DB.Where("config_id = ?", CONFIG_CONFIGURED).First(&config).Error
|
||||
err := store.DB.Where("config_id = ?", CNFConfigured).First(&config).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
@ -27,10 +27,10 @@ func SetNodeStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if res := tx.Create(&store.Config{ConfigID: CONFIG_TOKEN, StrValue: token}).Error; res != nil {
|
||||
if res := tx.Create(&store.Config{ConfigID: CNFToken, StrValue: token}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Create(&store.Config{ConfigID: CONFIG_CONFIGURED, BoolValue: true}).Error; res != nil {
|
||||
if res := tx.Create(&store.Config{ConfigID: CNFConfigured, BoolValue: true}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
return nil;
|
||||
|
@ -78,12 +78,12 @@ func ParamAdminToken(r *http.Request) (int, error) {
|
||||
}
|
||||
|
||||
// nothing to do if not configured
|
||||
if !getBoolConfigValue(CONFIG_CONFIGURED, false) {
|
||||
if !getBoolConfigValue(CNFConfigured, false) {
|
||||
return http.StatusUnauthorized, errors.New("node not configured")
|
||||
}
|
||||
|
||||
// compare password
|
||||
value := getStrConfigValue(CONFIG_TOKEN, "");
|
||||
value := getStrConfigValue(CNFToken, "");
|
||||
if (value != token) {
|
||||
return http.StatusUnauthorized, errors.New("invalid admin token")
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import (
|
||||
"databag/internal/store"
|
||||
)
|
||||
|
||||
const CONFIG_OPENACCESS = "open_access"
|
||||
const CONFIG_ACCOUNTLIMIT = "account_limit"
|
||||
const CONFIG_CONFIGURED = "configured"
|
||||
const CONFIG_TOKEN = "token"
|
||||
const CONFIG_DOMAIN = "domain"
|
||||
const CONFIG_STORAGE = "storage"
|
||||
const CONFIG_ASSETPATH = "asset_path"
|
||||
const CONFIG_SCRIPTPATH = "script_path"
|
||||
const CNFOpenAccess = "open_access"
|
||||
const CNFAccountLimit = "account_limit"
|
||||
const CNFConfigured = "configured"
|
||||
const CNFToken = "token"
|
||||
const CNFDomain = "domain"
|
||||
const CNFStorage = "storage"
|
||||
const CNFAssetPath = "asset_path"
|
||||
const CNFScriptPath = "script_path"
|
||||
|
||||
func getStrConfigValue(configID string, empty string) string {
|
||||
var config store.Config
|
||||
|
@ -13,7 +13,7 @@ func garbageCollect(act *store.Account) {
|
||||
defer garbageSync.Unlock()
|
||||
|
||||
// get all asset files
|
||||
dir := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath) + "/" + act.GUID
|
||||
dir := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + act.GUID
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
ErrMsg(err)
|
||||
|
@ -26,14 +26,14 @@ func GenerateRsaKeyPair() (*rsa.PrivateKey, *rsa.PublicKey, string, error) {
|
||||
}
|
||||
|
||||
func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string {
|
||||
privkey_bytes := x509.MarshalPKCS1PrivateKey(privkey)
|
||||
privkey_pem := pem.EncodeToMemory(
|
||||
privkeyBytes := x509.MarshalPKCS1PrivateKey(privkey)
|
||||
privkeyPEM := pem.EncodeToMemory(
|
||||
&pem.Block{
|
||||
Type: "RSA PRIVATE KEY",
|
||||
Bytes: privkey_bytes,
|
||||
Bytes: privkeyBytes,
|
||||
},
|
||||
)
|
||||
return string(privkey_pem)
|
||||
return string(privkeyPEM)
|
||||
}
|
||||
|
||||
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) {
|
||||
@ -51,18 +51,18 @@ func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error) {
|
||||
}
|
||||
|
||||
func ExportRsaPublicKeyAsPemStr(pubkey *rsa.PublicKey) (string, error) {
|
||||
pubkey_bytes, err := x509.MarshalPKIXPublicKey(pubkey)
|
||||
pubkeyBytes, err := x509.MarshalPKIXPublicKey(pubkey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
pubkey_pem := pem.EncodeToMemory(
|
||||
pubkeyPEM := pem.EncodeToMemory(
|
||||
&pem.Block{
|
||||
Type: "RSA PUBLIC KEY",
|
||||
Bytes: pubkey_bytes,
|
||||
Bytes: pubkeyBytes,
|
||||
},
|
||||
)
|
||||
|
||||
return string(pubkey_pem), nil
|
||||
return string(pubkeyPEM), nil
|
||||
}
|
||||
|
||||
func ParseRsaPublicKeyFromPemStr(pubPEM string) (*rsa.PublicKey, error) {
|
||||
|
@ -41,13 +41,13 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
// config data path
|
||||
scripts := &store.Config{ ConfigID: CONFIG_SCRIPTPATH, StrValue: "./testscripts" }
|
||||
scripts := &store.Config{ ConfigID: CNFScriptPath, StrValue: "./testscripts" }
|
||||
if err := store.DB.Save(scripts).Error; err != nil {
|
||||
panic("failed to configure scripts path")
|
||||
}
|
||||
|
||||
// config data path
|
||||
path := &store.Config{ ConfigID: CONFIG_ASSETPATH, StrValue: "./testdata" }
|
||||
path := &store.Config{ ConfigID: CNFAssetPath, StrValue: "./testdata" }
|
||||
if err := store.DB.Save(path).Error; err != nil {
|
||||
panic("failed to configure data path")
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ func getProfileModel(account *store.Account) *Profile {
|
||||
Image: account.AccountDetail.Image,
|
||||
Revision: account.ProfileRevision,
|
||||
Version: APPVersion,
|
||||
Node: getStrConfigValue(CONFIG_DOMAIN, ""),
|
||||
Node: getStrConfigValue(CNFDomain, ""),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ type AppData struct {
|
||||
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
Url string `json:"url,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
Image string `json:"image,omitempty"`
|
||||
|
||||
|
@ -31,7 +31,7 @@ func SendNotifications() {
|
||||
for {
|
||||
select {
|
||||
case notification := <-notify:
|
||||
node := getStrConfigValue(CONFIG_DOMAIN, "")
|
||||
node := getStrConfigValue(CNFDomain, "")
|
||||
if notification.Node == node {
|
||||
SendLocalNotification(notification)
|
||||
} else {
|
||||
|
@ -91,7 +91,7 @@ type App struct {
|
||||
Name string
|
||||
Description string
|
||||
Image string
|
||||
Url string
|
||||
URL string
|
||||
Token string `gorm:"not null;index:appguid,unique"`
|
||||
Created int64 `gorm:"autoCreateTime"`
|
||||
Account Account `gorm:"references:GUID"`
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const TEST_TIMEOUT = 5
|
||||
const testTimeout = 5
|
||||
|
||||
type TestCondition struct {
|
||||
check func(*TestApp) bool
|
||||
@ -810,7 +810,7 @@ func (a *TestApp) WaitFor(check func(*TestApp) bool) error {
|
||||
var wake = make(chan bool, 1)
|
||||
a.setCondition(&TestCondition{channel: done, check: check, })
|
||||
go func(){
|
||||
time.Sleep(TEST_TIMEOUT * time.Second)
|
||||
time.Sleep(testTimeout * time.Second)
|
||||
wake <- true
|
||||
}()
|
||||
select {
|
||||
|
@ -612,7 +612,7 @@ func AddTestAccount(username string) (guid string, token string, err error) {
|
||||
app := AppData{
|
||||
Name: "Appy",
|
||||
Description: "A test app",
|
||||
Url: "http://app.coredb.org",
|
||||
URL: "http://app.coredb.org",
|
||||
};
|
||||
var claim Claim
|
||||
var msg DataMessage
|
||||
|
@ -88,8 +88,8 @@ func transcodeDefault() {
|
||||
func transcodeAsset(asset *store.Asset) {
|
||||
|
||||
// prepare script path
|
||||
data := getStrConfigValue(CONFIG_ASSETPATH, APPDefaultPath)
|
||||
script := getStrConfigValue(CONFIG_SCRIPTPATH, ".")
|
||||
data := getStrConfigValue(CNFAssetPath, APPDefaultPath)
|
||||
script := getStrConfigValue(CNFScriptPath, ".")
|
||||
re := regexp.MustCompile("^[a-zA-Z0-9_]*$")
|
||||
|
||||
if !re.MatchString(asset.Transform) {
|
||||
|
Loading…
Reference in New Issue
Block a user