chore: rename api-key-macaroon

This commit is contained in:
Eneko Illarramendi 2020-04-16 17:27:36 +02:00
parent a834a64319
commit fd4dddda6e
8 changed files with 33 additions and 33 deletions

View File

@ -9,7 +9,7 @@
<q-card-section>
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
<code>{"api_key": "<i>{{ wallet.inkey }}</i>"}</code><br />
<code>{"X-Api-Key": "<i>{{ wallet.inkey }}</i>"}</code><br />
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
<code>{"out": false, "amount": &lt;int&gt;, "memo": &lt;string&gt;}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
@ -24,7 +24,7 @@
<q-card-section>
<code><span class="text-light-green">POST</span> /api/v1/payments</code>
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
<code>{"api_key": "{{ wallet.adminkey }}"}</code>
<code>{"X-Api-Key": "{{ wallet.adminkey }}"}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Body (application/json)</h5>
<code>{"out": true, "bolt11": &lt;string&gt;}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Returns 201 CREATED (application/json)</h5>
@ -40,7 +40,7 @@
<q-card-section>
<code><span class="text-light-blue">GET</span> /api/v1/payments/&lt;checking_id&gt;</code>
<h5 class="text-caption q-mt-sm q-mb-none">Headers</h5>
<code>{"api_key": "{{ wallet.inkey }}"}</code>
<code>{"X-Api-Key": "{{ wallet.inkey }}"}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Returns 200 OK (application/json)</h5>
<code>{"paid": &lt;bool&gt;}</code>
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>

View File

@ -1,7 +1,7 @@
from flask import g, jsonify, request
from lnbits.core import core_app
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.helpers import Status
from lnbits.settings import WALLET
@ -9,7 +9,7 @@ from ..services import create_invoice, pay_invoice
@core_app.route("/api/v1/payments", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_payments():
if "check_pending" in request.args:
for payment in g.wallet.get_payments(include_all_pending=True):
@ -21,7 +21,7 @@ def api_payments():
return jsonify(g.wallet.get_payments()), Status.OK
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"amount": {"type": "integer", "min": 1, "required": True},
@ -39,7 +39,7 @@ def api_payments_create_invoice():
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.CREATED
@api_check_wallet_macaroon(key_type="admin")
@api_check_wallet_key("admin")
@api_validate_post_request(schema={"bolt11": {"type": "string", "empty": False, "required": True}})
def api_payments_pay_invoice():
try:
@ -63,7 +63,7 @@ def api_payments_create():
@core_app.route("/api/v1/payments/<checking_id>", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_payment(checking_id):
payment = g.wallet.get_payment(checking_id)

View File

@ -8,14 +8,14 @@ from lnbits.core.crud import get_user, get_wallet_for_key
from .helpers import Status
def api_check_wallet_macaroon(*, key_type: str = "invoice"):
def api_check_wallet_key(key_type: str = "invoice"):
def wrap(view):
@wraps(view)
def wrapped_view(**kwargs):
try:
g.wallet = get_wallet_for_key(request.headers["api_key"], key_type)
g.wallet = get_wallet_for_key(request.headers["X-Api-Key"], key_type)
except KeyError:
return jsonify({"message": "`api_key` header missing."}), Status.BAD_REQUEST
return jsonify({"message": "`X-Api-Key` header missing."}), Status.BAD_REQUEST
if not g.wallet:
return jsonify({"message": "Wrong keys."}), Status.UNAUTHORIZED

View File

@ -1,7 +1,7 @@
from flask import g, jsonify, request
from lnbits.core.crud import get_user
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.helpers import Status
from lnbits.extensions.amilk import amilk_ext
@ -9,7 +9,7 @@ from .crud import create_amilk, get_amilk, get_amilks, delete_amilk
@amilk_ext.route("/api/v1/amilk", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_amilks():
wallet_ids = [g.wallet.id]
@ -20,7 +20,7 @@ def api_amilks():
@amilk_ext.route("/api/v1/amilk", methods=["POST"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
@api_validate_post_request(schema={
"url": {"type": "string", "empty": False, "required": True},
"memo": {"type": "string", "empty": False, "required": True},
@ -33,7 +33,7 @@ def api_amilk_create():
@amilk_ext.route("/api/v1/amilk/<amilk_id>", methods=["DELETE"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_amilk_delete(amilk_id):
amilk = get_amilk(amilk_id)

View File

@ -1,7 +1,7 @@
from flask import g, jsonify, request
from lnbits.core.crud import get_user
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.helpers import Status
from lnbits.extensions.paywall import paywall_ext
@ -9,7 +9,7 @@ from .crud import create_paywall, get_paywall, get_paywalls, delete_paywall
@paywall_ext.route("/api/v1/paywalls", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_paywalls():
wallet_ids = [g.wallet.id]
@ -20,7 +20,7 @@ def api_paywalls():
@paywall_ext.route("/api/v1/paywalls", methods=["POST"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
@api_validate_post_request(schema={
"url": {"type": "string", "empty": False, "required": True},
"memo": {"type": "string", "empty": False, "required": True},
@ -33,7 +33,7 @@ def api_paywall_create():
@paywall_ext.route("/api/v1/paywalls/<paywall_id>", methods=["DELETE"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_paywall_delete(paywall_id):
paywall = get_paywall(paywall_id)

View File

@ -2,7 +2,7 @@ from flask import g, jsonify, request
from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.helpers import Status
from lnbits.settings import WALLET
@ -11,7 +11,7 @@ from .crud import create_tpos, get_tpos, get_tposs, delete_tpos
@tpos_ext.route("/api/v1/tposs", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_tposs():
wallet_ids = [g.wallet.id]
@ -22,7 +22,7 @@ def api_tposs():
@tpos_ext.route("/api/v1/tposs", methods=["POST"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"name": {"type": "string", "empty": False, "required": True},
@ -38,7 +38,7 @@ def api_tpos_create():
@tpos_ext.route("/api/v1/tposs/<tpos_id>", methods=["DELETE"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_tpos_delete(tpos_id):
tpos = get_tpos(tpos_id)
@ -58,13 +58,13 @@ def api_tpos_delete(tpos_id):
def api_tpos_create_invoice(tpos_id):
tpos = get_tpos(tpos_id)
if not tpos:
return jsonify({"message": "TPoS does not exist."}), Status.NOT_FOUND
try:
memo = f"TPoS {tpos_id}"
checking_id, payment_request = create_invoice(wallet_id=tpos.wallet, amount=g.data["amount"], memo=memo)
except Exception as e:
return jsonify({"message": str(e)}), Status.INTERNAL_SERVER_ERROR
@ -74,7 +74,7 @@ def api_tpos_create_invoice(tpos_id):
def api_tpos_check_invoice(checking_id):
print(checking_id)
PAID = WALLET.get_invoice_status(checking_id).paid
if PAID == True:
return jsonify({"PAID": True}), Status.OK
return jsonify({"PAID": False}), Status.OK

View File

@ -3,7 +3,7 @@ from flask import g, jsonify, request
from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import pay_invoice
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
from lnbits.helpers import urlsafe_short_hash, Status
from lnbits.extensions.withdraw import withdraw_ext
@ -18,7 +18,7 @@ from .crud import (
@withdraw_ext.route("/api/v1/links", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_links():
wallet_ids = [g.wallet.id]
@ -29,7 +29,7 @@ def api_links():
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["GET"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_link_retrieve(link_id):
link = get_withdraw_link(link_id)
@ -44,7 +44,7 @@ def api_link_retrieve(link_id):
@withdraw_ext.route("/api/v1/links", methods=["POST"])
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["PUT"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"title": {"type": "string", "empty": False, "required": True},
@ -79,7 +79,7 @@ def api_link_create(link_id=None):
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["DELETE"])
@api_check_wallet_macaroon(key_type="invoice")
@api_check_wallet_key("invoice")
def api_link_delete(link_id):
link = get_withdraw_link(link_id)

View File

@ -4,12 +4,12 @@ var EventHub = new Vue();
var LNbits = {
api: {
request: function (method, url, macaroon, data) {
request: function (method, url, apiKey, data) {
return axios({
method: method,
url: url,
headers: {
'api_key': macaroon
'X-Api-Key': apiKey
},
data: data
});