@@ -15,7 +15,7 @@ import ( |
15 | 15 | "github.com/spf13/viper" |
16 | 16 | ) |
17 | 17 |
|
18 | | -func Create(w http.ResponseWriter, r *http.Request) { |
| 18 | +func SQLCreate(w http.ResponseWriter, r *http.Request) { |
19 | 19 | metaTableAddress := viper.GetString(`DROPKIT.METATABLE`) |
20 | 20 | authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
21 | 21 |
|
@@ -26,25 +26,25 @@ func Create(w http.ResponseWriter, r *http.Request) { |
26 | 26 | var newStatement constants.DB_Statement |
27 | 27 | _ = json.Unmarshal(body, &newStatement) |
28 | 28 | sqlCommand := newStatement.Statement |
29 | | - privatekeyHex := newStatement.PrivateKey |
30 | | - callerAddress := account.PrivateKeyToPublicKey(privatekeyHex) |
| 29 | + callerPriavteKey := newStatement.PrivateKey |
| 30 | + callerAddress := account.PrivateKeyToPublicKey(callerPriavteKey) |
31 | 31 |
|
32 | 32 | tableName := parser.GetTableName(sqlCommand) |
33 | 33 | _, tableAddress := account.GenerateWallet() |
34 | 34 |
|
35 | | - services.AddMetaTable(tableName, tableAddress, metaTableAddress, privatekeyHex) |
36 | | - services.GrantAuthority(authorityAddr, privatekeyHex, tableName, callerAddress) |
| 35 | + services.AddMetaTable(tableName, tableAddress, metaTableAddress, callerPriavteKey) |
| 36 | + services.GrantAuthority(authorityAddr, callerPriavteKey, tableName, callerAddress) |
37 | 37 | services.Exec(sqlCommand) |
38 | 38 |
|
39 | | - aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, privatekeyHex) |
| 39 | + aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, callerPriavteKey) |
40 | 40 |
|
41 | 41 | defer r.Body.Close() |
42 | 42 | response := constants.Exec_Response{"200", aduitTransactionHash} |
43 | 43 |
|
44 | 44 | services.ResponseWithJson(w, http.StatusOK, response) |
45 | 45 | } |
46 | 46 |
|
47 | | -func Insert(w http.ResponseWriter, r *http.Request) { |
| 47 | +func SQLInsert(w http.ResponseWriter, r *http.Request) { |
48 | 48 | metaTableAddress := viper.GetString(`DROPKIT.METATABLE`) |
49 | 49 | authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
50 | 50 |
|
@@ -56,17 +56,17 @@ func Insert(w http.ResponseWriter, r *http.Request) { |
56 | 56 | var newStatement constants.DB_Statement |
57 | 57 | _ = json.Unmarshal(body, &newStatement) |
58 | 58 | sqlCommand := newStatement.Statement |
59 | | - privatekeyHex := newStatement.PrivateKey |
60 | | - callerAddress := account.PrivateKeyToPublicKey(privatekeyHex) |
| 59 | + callerPriavteKey := newStatement.PrivateKey |
| 60 | + callerAddress := account.PrivateKeyToPublicKey(callerPriavteKey) |
61 | 61 |
|
62 | 62 | tableName := parser.GetTableName(sqlCommand) |
63 | 63 | tableAddress := services.GetMetaTable(tableName, metaTableAddress) |
64 | | - authority := services.VerifyAuthority(authorityAddr, privatekeyHex, tableName, callerAddress) |
| 64 | + authority := services.VerifyAuthority(authorityAddr, callerPriavteKey, tableName, callerAddress) |
65 | 65 |
|
66 | 66 | switch authority { |
67 | 67 | case true: |
68 | 68 | services.Exec(sqlCommand) |
69 | | - aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, privatekeyHex) |
| 69 | + aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, callerPriavteKey) |
70 | 70 | defer r.Body.Close() |
71 | 71 | response := constants.Exec_Response{"200", aduitTransactionHash} |
72 | 72 | services.ResponseWithJson(w, http.StatusOK, response) |
@@ -77,7 +77,7 @@ func Insert(w http.ResponseWriter, r *http.Request) { |
77 | 77 | } |
78 | 78 | } |
79 | 79 |
|
80 | | -func Select(w http.ResponseWriter, r *http.Request) { |
| 80 | +func SQLSelect(w http.ResponseWriter, r *http.Request) { |
81 | 81 | metaTableAddress := viper.GetString(`DROPKIT.METATABLE`) |
82 | 82 | authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
83 | 83 |
|
@@ -89,17 +89,17 @@ func Select(w http.ResponseWriter, r *http.Request) { |
89 | 89 | var newStatement constants.DB_Statement |
90 | 90 | _ = json.Unmarshal(body, &newStatement) |
91 | 91 | sqlCommand := newStatement.Statement |
92 | | - privatekeyHex := newStatement.PrivateKey |
93 | | - callerAddress := account.PrivateKeyToPublicKey(privatekeyHex) |
| 92 | + callerPriavteKey := newStatement.PrivateKey |
| 93 | + callerAddress := account.PrivateKeyToPublicKey(callerPriavteKey) |
94 | 94 |
|
95 | 95 | tableName := parser.GetTableName(sqlCommand) |
96 | 96 | tableAddress := services.GetMetaTable(tableName, metaTableAddress) |
97 | | - authority := services.VerifyAuthority(authorityAddr, privatekeyHex, tableName, callerAddress) |
| 97 | + authority := services.VerifyAuthority(authorityAddr, callerPriavteKey, tableName, callerAddress) |
98 | 98 |
|
99 | 99 | switch authority { |
100 | 100 | case true: |
101 | 101 | metadata, _ := services.Query(sqlCommand) |
102 | | - aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, privatekeyHex) |
| 102 | + aduitTransactionHash := transaction.SendRawTransaction(tableAddress, sqlCommand, 0, callerPriavteKey) |
103 | 103 | defer r.Body.Close() |
104 | 104 | response := constants.Query_Response{"200", metadata, aduitTransactionHash} |
105 | 105 | services.ResponseWithJson(w, http.StatusOK, response) |
@@ -109,3 +109,73 @@ func Select(w http.ResponseWriter, r *http.Request) { |
109 | 109 | services.ResponseWithJson(w, http.StatusUnauthorized, response) |
110 | 110 | } |
111 | 111 | } |
| 112 | + |
| 113 | +func AuthGrant(w http.ResponseWriter, r *http.Request) { |
| 114 | + authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
| 115 | + |
| 116 | + body, err := ioutil.ReadAll(r.Body) |
| 117 | + if err != nil { |
| 118 | + fmt.Println(err) |
| 119 | + } |
| 120 | + |
| 121 | + var newStatement constants.Auth_Statement |
| 122 | + _ = json.Unmarshal(body, &newStatement) |
| 123 | + callerPriavteKey := newStatement.PrivateKey |
| 124 | + grantUser := newStatement.UserName |
| 125 | + grantTable := newStatement.TableName |
| 126 | + |
| 127 | + services.GrantAuthority(authorityAddr, callerPriavteKey, grantTable, grantUser) |
| 128 | + |
| 129 | + defer r.Body.Close() |
| 130 | + response := constants.Auth_Response{"200"} |
| 131 | + services.ResponseWithJson(w, http.StatusOK, response) |
| 132 | +} |
| 133 | + |
| 134 | +func AuthRevoke(w http.ResponseWriter, r *http.Request) { |
| 135 | + authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
| 136 | + |
| 137 | + body, err := ioutil.ReadAll(r.Body) |
| 138 | + if err != nil { |
| 139 | + fmt.Println(err) |
| 140 | + } |
| 141 | + |
| 142 | + var newStatement constants.Auth_Statement |
| 143 | + _ = json.Unmarshal(body, &newStatement) |
| 144 | + callerPriavteKey := newStatement.PrivateKey |
| 145 | + revokeUser := newStatement.UserName |
| 146 | + revokeTable := newStatement.TableName |
| 147 | + |
| 148 | + services.RevokeAuthority(authorityAddr, callerPriavteKey, revokeTable, revokeUser) |
| 149 | + |
| 150 | + defer r.Body.Close() |
| 151 | + response := constants.Auth_Response{"200"} |
| 152 | + services.ResponseWithJson(w, http.StatusOK, response) |
| 153 | +} |
| 154 | + |
| 155 | +func AuthVerify(w http.ResponseWriter, r *http.Request) { |
| 156 | + authorityAddr := viper.GetString(`DROPKIT.AUTHORITY`) |
| 157 | + |
| 158 | + body, err := ioutil.ReadAll(r.Body) |
| 159 | + if err != nil { |
| 160 | + fmt.Println(err) |
| 161 | + } |
| 162 | + |
| 163 | + var newStatement constants.Auth_Statement |
| 164 | + _ = json.Unmarshal(body, &newStatement) |
| 165 | + callerPriavteKey := newStatement.PrivateKey |
| 166 | + checkUser := newStatement.UserName |
| 167 | + checkTable := newStatement.TableName |
| 168 | + |
| 169 | + authority := services.VerifyAuthority(authorityAddr, callerPriavteKey, checkTable, checkUser) |
| 170 | + |
| 171 | + switch authority { |
| 172 | + case true: |
| 173 | + defer r.Body.Close() |
| 174 | + response := constants.Auth_Response{"200"} |
| 175 | + services.ResponseWithJson(w, http.StatusOK, response) |
| 176 | + case false: |
| 177 | + defer r.Body.Close() |
| 178 | + response := constants.Auth_Response{"401"} |
| 179 | + services.ResponseWithJson(w, http.StatusUnauthorized, response) |
| 180 | + } |
| 181 | +} |