Skip to content

Commit

Permalink
add username to keys
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Aug 22, 2024
1 parent 163defa commit eff4e49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions cmd/http/oraclebuilder/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type AddWalletInput struct {
WalletPublicKeys []string `form:"wallet_public_keys[]"`
Creator string `form:"creator"`
AccessLevel string `form:"access_level" binding:"required,oneof=read read_write"`
UserName string `form:"username"`
}
type RemoveWalletInput struct {
WalletPublicKeys []string `form:"wallet_public_keys[]"`
Creator string `form:"creator"`
}
type UpdateAccessInput struct {
WalletPublicKey string `form:"wallet_public_key"`
Expand Down Expand Up @@ -104,17 +109,19 @@ func (ob *Env) UpdateAccess(context *gin.Context) {
}

func (ob *Env) RemoveWallet(context *gin.Context) {
var input AddWalletInput
requestId := context.GetString(REQUEST_ID)

var input RemoveWalletInput
if err := context.ShouldBind(&input); err != nil {
log.Errorln("ShouldBind", err)
log.Errorf("Request ID: %s, ShouldBind err %v ", requestId, err)

context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
//TODO check permission, remove self key
err := ob.RelDB.RemoveWalletKeys(input.WalletPublicKeys)
if err != nil {
log.Errorln("RemoveWalletKeys", err)

log.Errorf("Request ID: %s, RemoveWalletKeys err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ func (datastore *DB) GetOracleConfigCache(key string) (dia.OracleConfig, error)
return oc, err
}

func (reldb *RelDB) AddWalletKeys(owner, accessLevel string, publicKey []string) error {
func (reldb *RelDB) AddWalletKeys(owner, username, accessLevel string, publicKey []string) error {
var err error

customerID, err := reldb.GetCustomerIDByWalletPublicKey(owner)
Expand All @@ -1149,9 +1149,9 @@ func (reldb *RelDB) AddWalletKeys(owner, accessLevel string, publicKey []string)

for _, publicKey := range publicKey {
_, err = tx.Exec(context.Background(), `
INSERT INTO wallet_public_keys (customer_id, public_key, access_level)
INSERT INTO wallet_public_keys (customer_id, public_key, access_level,username)
VALUES ($1, $2,$3)
`, customerID, publicKey, accessLevel)
`, customerID, publicKey, accessLevel, username)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/relDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type RelDatastore interface {
DeleteAssetList(sheetName string) error

CreateCustomer(email string, customerPlan int, paymentStatus string, paymentSource string, numberOfDataFeeds int, walletPublicKeys []string) error
AddWalletKeys(owner, accessLevel string, publicKey []string) error
AddWalletKeys(owner, username, accessLevel string, publicKey []string) error
UpdateAccessLevel(accessLevel, publicKey string) error
RemoveWalletKeys(publicKey []string) error
GetCustomerIDByWalletPublicKey(publicKey string) (int, error)
Expand Down

0 comments on commit eff4e49

Please sign in to comment.