chaning code layout

This commit is contained in:
Roland Osborne 2022-01-15 13:28:28 -08:00
parent c3b142fcba
commit 660d83e3bd
6 changed files with 56 additions and 73 deletions

View File

@ -0,0 +1,41 @@
package databag
import (
"log"
"encoding/json"
"net/http"
"databag/internal/store"
"github.com/theckman/go-securerandom"
)
func AddNodeAccount(w http.ResponseWriter, r *http.Request) {
// validate login
if !adminLogin(r) {
log.Printf("AddNodeAccount - invalid admin credentials");
w.WriteHeader(http.StatusUnauthorized);
return
}
data, err := securerandom.Base64OfBytes(32)
if err != nil {
log.Println("AddNodeAccount - failed to generate token");
w.WriteHeader(http.StatusInternalServerError);
return
}
token := store.AccountToken{TokenType: "create", Token: data };
if res := store.DB.Create(&token).Error; res != nil {
log.Println("AddNodeAccount - failed to store token");
return
}
body, err := json.Marshal(data);
if err != nil {
log.Println("GetNodeConfig - failed to marshal response");
}
w.Write(body)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}

View File

@ -16,7 +16,6 @@ import (
"gorm.io/gorm"
"golang.org/x/crypto/bcrypt"
"databag/internal/store"
"github.com/theckman/go-securerandom"
)
func adminLogin(r *http.Request) bool {
@ -46,37 +45,6 @@ func adminLogin(r *http.Request) bool {
return true;
}
func AddNodeAccount(w http.ResponseWriter, r *http.Request) {
// validate login
if !adminLogin(r) {
log.Printf("AddNodeAccount - invalid admin credentials");
w.WriteHeader(http.StatusUnauthorized);
return
}
data, err := securerandom.Base64OfBytes(32)
if err != nil {
log.Println("AddNodeAccount - failed to generate token");
w.WriteHeader(http.StatusInternalServerError);
return
}
token := store.AccountToken{TokenType: "create", Token: data };
if res := store.DB.Create(&token).Error; res != nil {
log.Println("AddNodeAccount - failed to store token");
return
}
body, err := json.Marshal(data);
if err != nil {
log.Println("GetNodeConfig - failed to marshal response");
}
w.Write(body)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func GetNodeAccountImage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)

View File

@ -1,19 +0,0 @@
/*
* DataBag
*
* DataBag provides storage for decentralized identity based self-hosting apps. It is intended to support sharing of personal data and hosting group conversations.
*
* API version: 0.0.1
* Contact: roland.osborne@gmail.com
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package databag
type Account struct {
AccountId string `json:"accountId"`
Profile *Profile `json:"profile"`
Disabled bool `json:"disabled"`
}

View File

@ -1,22 +0,0 @@
/*
* DataBag
*
* DataBag provides storage for decentralized identity based self-hosting apps. It is intended to support sharing of personal data and hosting group conversations.
*
* API version: 0.0.1
* Contact: roland.osborne@gmail.com
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package databag
type AccountStatus struct {
Disabled bool `json:"disabled"`
StorageUsed float64 `json:"storageUsed"`
StorageAvailable float64 `json:"storageAvailable"`
ForwardingAddress string `json:"forwardingAddress"`
}

View File

@ -0,0 +1,15 @@
package databag
type Account struct {
AccountId string `json:"accountId"`
Profile *Profile `json:"profile"`
Disabled bool `json:"disabled"`
}
type AccountStatus struct {
Disabled bool `json:"disabled"`
StorageUsed float64 `json:"storageUsed"`
StorageAvailable float64 `json:"storageAvailable"`
ForwardingAddress string `json:"forwardingAddress"`
}