mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 11:37:11 +00:00
Initial commit
This commit is contained in:
commit
ea84b92091
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.swp
|
||||
__pycache__/
|
||||
|
||||
apimanager/apimanager/local_settings.py
|
||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
25
NOTICE
Normal file
25
NOTICE
Normal file
@ -0,0 +1,25 @@
|
||||
Open Bank Project API Manager
|
||||
Copyright (C) 2011-2016, TESOBE Ltd
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Email: contact@tesobe.com
|
||||
TESOBE Ltd
|
||||
Osloerstrasse 16/17
|
||||
Berlin 13359, Germany
|
||||
|
||||
This product includes software developed at
|
||||
TESOBE (http://www.tesobe.com/)
|
||||
by
|
||||
Sebastian Henschel <sebastian@tesobe.com>
|
||||
103
README.md
Normal file
103
README.md
Normal file
@ -0,0 +1,103 @@
|
||||
# API Manager
|
||||
|
||||
A Django project to manage the Open Bank Project API via API Calls
|
||||
|
||||
|
||||
## Installation (development)
|
||||
|
||||
Paths are relative to this README.
|
||||
|
||||
### Install dependencies
|
||||
|
||||
```bash
|
||||
$ virtualenv --python=python3 venv
|
||||
$ source venv/bin/activate
|
||||
$ pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Configure settings
|
||||
|
||||
Edit `apimanager/apimanager/local_settings.py`:
|
||||
|
||||
```python
|
||||
SECRET_KEY = '<random string>'
|
||||
OAUTH_API = '<your API root, e.g. https://api.openbankproject.com>'
|
||||
OAUTH_CLIENT_KEY = 'key you got from the API'
|
||||
OAUTH_CLIENT_SECRET = 'secret you got from the API'
|
||||
DATABASES['default']['NAME'] = '<Filename to use for database>' # default is 'db.sqlite3' in parent directory of git checkout
|
||||
```
|
||||
|
||||
The application's authentication is API-driven. However, to make use of Django's authentication framework and sessions, there is a minimal requirement of a database. Per default, sqlite is used, but you can configure any Django-supported backend you want. Please lookup the appropriate documentation.
|
||||
|
||||
|
||||
### Initialise database
|
||||
|
||||
```bash
|
||||
$ ./apimanager/manage.py migrate
|
||||
```
|
||||
|
||||
|
||||
### Run the app
|
||||
|
||||
```bash
|
||||
$ ./apimanager/manage.py runserver
|
||||
```
|
||||
|
||||
The application should be available at `http://localhost:8000`
|
||||
|
||||
|
||||
## Installation (production)
|
||||
|
||||
Execute the same steps as for development, but do not run the app.
|
||||
|
||||
### Settings
|
||||
|
||||
Edit `apimanager/apimanager/local_settings.py` for additional changes:
|
||||
|
||||
```python
|
||||
DEBUG = False
|
||||
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '<your hostname here>']
|
||||
STATIC_ROOT = '<Directory to place static files in>'
|
||||
```
|
||||
|
||||
### Static files
|
||||
|
||||
The app's static files, e.g. Javasript, CSS and images need to be collected and made available to a webserver. Run
|
||||
|
||||
```bash
|
||||
$ ./apimanager/manage.py collectstatic
|
||||
```
|
||||
|
||||
### Web application server
|
||||
|
||||
Instead of Django's built-in runserver, you need a proper web application server to run the app, e.g. `gunicorn`. It should have been installed already as a dependency and you use the provided `gunicorn.conf.py`. Run it like
|
||||
|
||||
```bash
|
||||
$ cd apimanager/ && gunicorn --config ../gunicorn.conf.py apimanager.wsgi
|
||||
```
|
||||
|
||||
For some reason, the process does not start successfully when omitting the directory change and using `apimanager.apimanager.wsgi` as program.
|
||||
|
||||
### Process control
|
||||
|
||||
If you do not want to start the web application server manually, but automatically at boot and also want to restart automatically if it dies, a process control system like `supervisor` comes in handy. Stick the provided file `supervisor.apimanager.conf` into `/etc/supervisor/conf.d/`, edit it and reload supervisor (probably as root):
|
||||
|
||||
```bash
|
||||
# /bin/systemctl restart supervisor
|
||||
```
|
||||
|
||||
### Webserver
|
||||
|
||||
Finally, use a webserver like `nginx` or `apache` as a frontend. It serves static files from the directory where `collectstatic` puts them and acts as a reverse proxy for gunicorn. Stick the provided `nginx.apimanager.conf` into `/etc/nginx/sites-enabled/`, edit it and reload the webserver (probably as root):
|
||||
|
||||
```bash
|
||||
# /bin/systemctl reload nginx
|
||||
```
|
||||
|
||||
|
||||
## Final words
|
||||
|
||||
As usual, be aware of file permission issues!
|
||||
|
||||
Have fun,
|
||||
TESOBE
|
||||
0
apimanager/api_calls/__init__.py
Normal file
0
apimanager/api_calls/__init__.py
Normal file
5
apimanager/api_calls/apps.py
Normal file
5
apimanager/api_calls/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiCallsConfig(AppConfig):
|
||||
name = 'api_calls'
|
||||
3
apimanager/api_calls/static/api_calls/css/api_calls.css
Normal file
3
apimanager/api_calls/static/api_calls/css/api_calls.css
Normal file
@ -0,0 +1,3 @@
|
||||
.api-calls #call-list, .api-calls #call-graph {
|
||||
margin-top: 20px;
|
||||
}
|
||||
42
apimanager/api_calls/static/api_calls/js/grouped.js
Normal file
42
apimanager/api_calls/static/api_calls/js/grouped.js
Normal file
@ -0,0 +1,42 @@
|
||||
$(document).ready(function($) {
|
||||
var ctx = $("#call-graph");
|
||||
var randomColor = function(alpha) {
|
||||
};
|
||||
var backgroundColors = [];
|
||||
var borderColors = [];
|
||||
$.each(CALLS_VALUES, function(idx, val) {
|
||||
var red = Math.floor((Math.random() * 255) + 1);
|
||||
var green = Math.floor((Math.random() * 255) + 1);
|
||||
var blue = Math.floor((Math.random() * 255) + 1);
|
||||
var backgroundColor = 'rgba(' + red + ', ' + green + ', ' + blue + ', 0.2)';
|
||||
backgroundColors.push(backgroundColor);
|
||||
var borderColor = 'rgba(' + red + ', ' + green + ', ' + blue + ', 1)';
|
||||
borderColors.push(borderColor);
|
||||
});
|
||||
var myChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
maintainAspectRation: false,
|
||||
data: {
|
||||
labels: CALLS_LABELS,
|
||||
datasets: [{
|
||||
data: CALLS_VALUES,
|
||||
backgroundColor: backgroundColors,
|
||||
borderColor: borderColors,
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero: true,
|
||||
fixedStepSize: 1
|
||||
}
|
||||
}]
|
||||
},
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
41
apimanager/api_calls/templates/api_calls/grouped.html
Normal file
41
apimanager/api_calls/templates/api_calls/grouped.html
Normal file
@ -0,0 +1,41 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="api-calls">
|
||||
<h1>API Calls grouped by Scala Function</h1>
|
||||
|
||||
|
||||
<div class="alert alert-warning">
|
||||
There is no live data here!
|
||||
</div>
|
||||
|
||||
|
||||
<div class="btn-group" role="group" id="filter-time" aria-label="filter-time">
|
||||
<a href="?time=minute" class="btn btn-default{% if active_time_minute %} active{% endif %}">Last Minute</a>
|
||||
<a href="?time=hour" class="btn btn-default{% if active_time_hour %} active{% endif %}">Last Hour</a>
|
||||
<a href="?time=day" class="btn btn-default{% if active_time_day %} active{% endif %}">Last Day</a>
|
||||
<a href="?time=week" class="btn btn-default{% if active_time_week %} active{% endif %}">Last Week</a>
|
||||
<a href="?time=month" class="btn btn-default{% if active_time_month %} active{% endif %}">Last Month</a>
|
||||
<a href="?time=year" class="btn btn-default{% if active_time_year %} active{% endif %}">Last Year</a>
|
||||
<a href="?time=all" class="btn btn-default{% if active_time_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
<canvas id="call-graph"></canvas>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'js/Chart.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'api_calls/js/grouped.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
CALLS_LABELS = {{ calls.labels|safe }};
|
||||
CALLS_VALUES = {{ calls.values|safe }};
|
||||
</script>
|
||||
{% endblock extrajs %}
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'api_calls/css/api_calls.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
60
apimanager/api_calls/templates/api_calls/list.html
Normal file
60
apimanager/api_calls/templates/api_calls/list.html
Normal file
@ -0,0 +1,60 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load humanize static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="api-calls">
|
||||
<h1>API Calls List</h1>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
There is no live data here!
|
||||
</div>
|
||||
|
||||
|
||||
<div class="btn-group" role="group" id="filter-time" aria-label="filter-time">
|
||||
<a href="?time=minute&code={{ request.GET.code }}" class="btn btn-default{% if active_time_minute %} active{% endif %}">Last Minute</a>
|
||||
<a href="?time=hour&code={{ request.GET.code }}" class="btn btn-default{% if active_time_hour %} active{% endif %}">Last Hour</a>
|
||||
<a href="?time=day&code={{ request.GET.code }}" class="btn btn-default{% if active_time_day %} active{% endif %}">Last Day</a>
|
||||
<a href="?time=week&code={{ request.GET.code }}" class="btn btn-default{% if active_time_week %} active{% endif %}">Last Week</a>
|
||||
<a href="?time=month&code={{ request.GET.code }}" class="btn btn-default{% if active_time_month %} active{% endif %}">Last Month</a>
|
||||
<a href="?time=year&code={{ request.GET.code }}" class="btn btn-default{% if active_time_year %} active{% endif %}">Last Year</a>
|
||||
<a href="?time=all&code={{ request.GET.code }}" class="btn btn-default{% if active_time_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="btn-group pull-right">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" id="filter-code" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
{{ active_code }} <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="?code=all&time={{ request.GET.time }}">All</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
{% for code in codes %}
|
||||
<li><a href="?code={{ code }}&time={{ request.GET.time }}">{{ code }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<table class="table table-striped" id="call-list">
|
||||
<thead>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for call in calls %}
|
||||
<tr>
|
||||
<td>{{ call.method }}</td>
|
||||
<td>{{ call.url }}</td>
|
||||
<td>{{ call.code }}</td>
|
||||
<td>{{ call.user }}</td>
|
||||
<td>{{ call.when|naturaltime }}</td>
|
||||
<td>took {{ call.duration }}ms</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'api_calls/css/api_calls.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
8
apimanager/api_calls/urls.py
Normal file
8
apimanager/api_calls/urls.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import GroupedView, ListView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^grouped$', GroupedView.as_view(), name='api-calls-grouped'),
|
||||
url(r'^list$', ListView.as_view(), name='api-calls-list'),
|
||||
]
|
||||
144
apimanager/api_calls/views.py
Normal file
144
apimanager/api_calls/views.py
Normal file
@ -0,0 +1,144 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from base.filters import filter_time
|
||||
|
||||
|
||||
CALLS = [
|
||||
{
|
||||
'method': 'GET',
|
||||
'url': '/obp/v2.1.0/banks',
|
||||
'code': '200',
|
||||
'user': 'Anonymous',
|
||||
'when': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'duration': '10',
|
||||
'function': 'getBanks',
|
||||
},
|
||||
{
|
||||
'method': 'GET',
|
||||
'url': '/obp/v2.1.0/banks',
|
||||
'code': '200',
|
||||
'user': 'Anonymous',
|
||||
'when': '2016-07-03 12:00:00',
|
||||
'duration': '10',
|
||||
'function': 'getBanks',
|
||||
},
|
||||
{
|
||||
'method': 'GET',
|
||||
'url': '/unknown',
|
||||
'code': '404',
|
||||
'user': 'Anonymous',
|
||||
'when': '2015-09-02 10:34:00',
|
||||
'duration': '1',
|
||||
'function': '',
|
||||
},
|
||||
{
|
||||
'method': 'GET',
|
||||
'url': '/obp/v2.1.0/banks',
|
||||
'code': '200',
|
||||
'user': 'Anonymous',
|
||||
'when': '2016-09-12 07:34:00',
|
||||
'duration': '10',
|
||||
'function': 'getBanks',
|
||||
},
|
||||
{
|
||||
'method': 'GET',
|
||||
'url': '/users/current',
|
||||
'code': '404',
|
||||
'user': 'Anonymous',
|
||||
'when': '2016-09-02 10:34:00',
|
||||
'duration': '5',
|
||||
'function': 'getCurrentUser',
|
||||
},
|
||||
{
|
||||
'method': 'POST',
|
||||
'url': '/users/ff3f94f9-bbd6-4cd9-ab78-3701e961eb58/entitlements',
|
||||
'code': '500',
|
||||
'user': 'shensche',
|
||||
'when': '2016-08-10 15:34:00',
|
||||
'duration': '23',
|
||||
'function': 'getEntitlements',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
class GroupedView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "api_calls/grouped.html"
|
||||
|
||||
def group_functions(self, data):
|
||||
functions = {}
|
||||
for call in data:
|
||||
name = call['function']
|
||||
if not name:
|
||||
continue
|
||||
if not name in functions:
|
||||
functions[name] = 1
|
||||
else:
|
||||
functions[name] += 1
|
||||
labels = []
|
||||
values = []
|
||||
for k in sorted(functions, key=functions.get, reverse=True):
|
||||
labels.append(k)
|
||||
values.append(functions[k])
|
||||
return {'labels': labels, 'values': values}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(GroupedView, self).get_context_data(**kwargs)
|
||||
filtered = deepcopy(CALLS)
|
||||
|
||||
filtered = filter_time(self.request, context, filtered, 'when')
|
||||
grouped = self.group_functions(filtered)
|
||||
|
||||
context.update({
|
||||
'calls': grouped,
|
||||
'calls_json': json.dumps(grouped),
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class ListView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "api_calls/list.html"
|
||||
|
||||
def filter_code(self, context, data):
|
||||
context['active_code'] = 'All'
|
||||
if not 'code' in self.request.GET:
|
||||
return data
|
||||
|
||||
code = self.request.GET['code'].lower()
|
||||
if not code or code.lower() == 'all':
|
||||
return data
|
||||
|
||||
filtered = [x for x in data if x['code'] == code]
|
||||
if filtered:
|
||||
context['active_code'] = code
|
||||
return filtered
|
||||
|
||||
def scrub(self, data):
|
||||
for call in data:
|
||||
# to make it work for humanize
|
||||
call['when'] = datetime.strptime(call['when'], '%Y-%m-%d %H:%M:%S')
|
||||
return data
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ListView, self).get_context_data(**kwargs)
|
||||
filtered = deepcopy(CALLS)
|
||||
|
||||
codes = list(set([x['code'] for x in CALLS]))
|
||||
codes.sort()
|
||||
|
||||
filtered = self.filter_code(context, filtered)
|
||||
filtered = filter_time(self.request, context, filtered, 'when')
|
||||
filtered = self.scrub(filtered)
|
||||
|
||||
context.update({
|
||||
'codes': codes,
|
||||
'calls': filtered,
|
||||
})
|
||||
return context
|
||||
0
apimanager/api_config/__init__.py
Normal file
0
apimanager/api_config/__init__.py
Normal file
5
apimanager/api_config/apps.py
Normal file
5
apimanager/api_config/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfigConfig(AppConfig):
|
||||
name = 'api_config'
|
||||
0
apimanager/api_config/migrations/__init__.py
Normal file
0
apimanager/api_config/migrations/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
.api-config input[type="text"] {
|
||||
width: 100%;
|
||||
}
|
||||
35
apimanager/api_config/templates/api_config/index.html
Normal file
35
apimanager/api_config/templates/api_config/index.html
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="api-config">
|
||||
<h1>API Config</h1>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
There is no live data here!
|
||||
</div>
|
||||
|
||||
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="config-versions-disabled" class="control-label">Versions Disabled</label><br />
|
||||
<input type="text" name="config-versions-disabled" id="config-versions-disabled" aria-label="versions-disabled" disabled="disabled" value="{{ config.versions_disabled }}" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="config-functions-disabled" class="control-label">Functions Disabled</label><br />
|
||||
<input type="text" name="config-functions-disabled" id="config-functions-disabled" aria-label="functions-disabled" disabled="disabled" value="{{ config.functions_disabled }}" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="config-host" class="control-label">Host</label><br />
|
||||
<input type="text" name="config-host" id="config-host" aria-label="host" disabled="disabled" value="{{ config.host }}" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'api_config/css/api_config.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
7
apimanager/api_config/urls.py
Normal file
7
apimanager/api_config/urls.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', IndexView.as_view(), name='api-config-index'),
|
||||
]
|
||||
26
apimanager/api_config/views.py
Normal file
26
apimanager/api_config/views.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
CONFIG = {
|
||||
'versions_disabled': ', '.join(['1.4.0', '2.0.0']),
|
||||
'functions_disabled': ', '.join([
|
||||
'getBank', 'getBanks', 'getAccounts', 'getAccount',
|
||||
'getTransactions', 'getTransaction'
|
||||
]),
|
||||
'host': 'http://127.0.0.1:8080',
|
||||
}
|
||||
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "api_config/index.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'config': CONFIG,
|
||||
})
|
||||
return context
|
||||
0
apimanager/apimanager/__init__.py
Normal file
0
apimanager/apimanager/__init__.py
Normal file
185
apimanager/apimanager/settings.py
Normal file
185
apimanager/apimanager/settings.py
Normal file
@ -0,0 +1,185 @@
|
||||
"""
|
||||
Django settings for apimanager project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.10.1.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.10/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = None
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
# Set this to e.g. ['127.0.0.1', 'localhost'] if DEBUG = False
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.humanize',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'base',
|
||||
'oauth',
|
||||
'consumers',
|
||||
# 'users',
|
||||
# 'api_calls',
|
||||
# 'api_config',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'apimanager.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'base.context_processors.api_root',
|
||||
'base.context_processors.api_username',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'apimanager.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, '..', '..', 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.10/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-gb'
|
||||
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Set this to your local directory for static files
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, '..', '..', 'static-collected')
|
||||
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'base': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
LOGIN_URL = reverse_lazy('home')
|
||||
|
||||
|
||||
API_DATETIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
|
||||
|
||||
|
||||
OAUTH_API = 'http://127.0.0.1:8080'
|
||||
OAUTH_TOKEN_PATH = '/oauth/initiate'
|
||||
OAUTH_AUTHORIZATION_PATH = '/oauth/authorize'
|
||||
OAUTH_ACCESS_TOKEN_PATH = '/oauth/token'
|
||||
OAUTH_API_BASE_PATH = '/obp/v2.1.0'
|
||||
|
||||
|
||||
|
||||
# Set OAuth client key/secret in apimanager/local_settings.py
|
||||
OAUTH_CLIENT_KEY = None
|
||||
OAUTH_CLIENT_SECRET = None
|
||||
|
||||
# Local settings can override anything in here
|
||||
try:
|
||||
from apimanager.local_settings import *
|
||||
except:
|
||||
pass
|
||||
|
||||
if not OAUTH_CLIENT_KEY:
|
||||
raise ImproperlyConfigured('Missing settings for OAUTH_CLIENT_KEY')
|
||||
if not OAUTH_CLIENT_SECRET:
|
||||
raise ImproperlyConfigured('Missing settings for OAUTH_CLIENT_SECRET')
|
||||
28
apimanager/apimanager/urls.py
Normal file
28
apimanager/apimanager/urls.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""apimanager URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.10/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from base.views import HomeView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', HomeView.as_view(), name="home"),
|
||||
url(r'^oauth/', include('oauth.urls')),
|
||||
url(r'^consumers/', include('consumers.urls')),
|
||||
# url(r'^users/', include('users.urls')),
|
||||
# url(r'^api_calls/', include('api_calls.urls')),
|
||||
# url(r'^api_config/', include('api_config.urls')),
|
||||
]
|
||||
16
apimanager/apimanager/wsgi.py
Normal file
16
apimanager/apimanager/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for apimanager project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apimanager.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
0
apimanager/base/__init__.py
Normal file
0
apimanager/base/__init__.py
Normal file
5
apimanager/base/apps.py
Normal file
5
apimanager/base/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class HomeConfig(AppConfig):
|
||||
name = 'home'
|
||||
17
apimanager/base/context_processors.py
Normal file
17
apimanager/base/context_processors.py
Normal file
@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from base.utils import api_get
|
||||
|
||||
|
||||
def api_root(request):
|
||||
return {'API_ROOT': settings.OAUTH_API + settings.OAUTH_API_BASE_PATH}
|
||||
|
||||
def api_username(request):
|
||||
if request.user.is_authenticated:
|
||||
data = api_get(request, '/users/current')
|
||||
api_username = data['username']
|
||||
else:
|
||||
api_username = 'not authenticated'
|
||||
return {'API_USERNAME': api_username}
|
||||
63
apimanager/base/filters.py
Normal file
63
apimanager/base/filters.py
Normal file
@ -0,0 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
class BaseFilter(object):
|
||||
def __init__(self, context, request_get):
|
||||
self.context = context
|
||||
self.request_get = request_get
|
||||
|
||||
def _apply(self, data, filter_value):
|
||||
raise AttributeError('Not implemented yet!')
|
||||
|
||||
def apply(self, data):
|
||||
filter_all = 'active_{}_all'.format(self.filter_type)
|
||||
self.context[filter_all] = True
|
||||
|
||||
if not self.filter_type in self.request_get:
|
||||
return data
|
||||
|
||||
filter_value = self.request_get[self.filter_type].lower()
|
||||
if not filter_value or filter_value == 'all':
|
||||
return data
|
||||
|
||||
self.context[filter_all] = False
|
||||
filter_active = 'active_{}_{}'.format(self.filter_type, filter_value)
|
||||
self.context[filter_active] = True
|
||||
return self._apply(data, filter_value)
|
||||
|
||||
|
||||
|
||||
class FilterTime(BaseFilter):
|
||||
filter_type = 'time'
|
||||
|
||||
def __init__(self, context, request_get, time_fieldname):
|
||||
super().__init__(context, request_get)
|
||||
self.time_fieldname = time_fieldname
|
||||
|
||||
def _apply(self, data, filter_value):
|
||||
if filter_value == 'minute':
|
||||
delta = timedelta(minutes=1)
|
||||
elif filter_value == 'hour':
|
||||
delta = timedelta(hours=1)
|
||||
elif filter_value == 'day':
|
||||
delta = timedelta(days=1)
|
||||
elif filter_value == 'week':
|
||||
delta = timedelta(days=7)
|
||||
elif filter_value == 'month':
|
||||
delta = timedelta(days=30)
|
||||
elif filter_value == 'year':
|
||||
delta = timedelta(days=365)
|
||||
else:
|
||||
return data
|
||||
|
||||
now = datetime.now()
|
||||
filtered = []
|
||||
for item in data:
|
||||
item_date = datetime.strptime(
|
||||
item[self.time_fieldname], settings.API_DATETIMEFORMAT)
|
||||
if now - item_date <= delta:
|
||||
filtered.append(item)
|
||||
return filtered
|
||||
97
apimanager/base/static/css/base.css
Normal file
97
apimanager/base/static/css/base.css
Normal file
@ -0,0 +1,97 @@
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
padding-top: 70px;
|
||||
margin-bottom: 60px; /* footer height */
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
/* Set the fixed height of the footer here */
|
||||
height: 60px;
|
||||
background-color: #333;
|
||||
}
|
||||
.footer p {
|
||||
margin-top: 25px;
|
||||
font-size: 10px;
|
||||
text-align: center;
|
||||
color: #aaa;
|
||||
}
|
||||
.footer a:link, .footer a:visited {
|
||||
color: #ddd;
|
||||
}
|
||||
.footer a:hover, .footer a:focus {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.navbar-brand img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
|
||||
.navbar-default {
|
||||
background-color: #53c4ef;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:visited {
|
||||
color: #555;
|
||||
background-color: #fff;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.navbar-default .navbar-nav > li > a:link, .navbar-default .navbar-nav > li > a:visited {
|
||||
color: #000;
|
||||
}
|
||||
.navbar-default .navbar-nav > li > a:focus, .navbar-default .navbar-nav > li > a:hover {
|
||||
color: #03749f;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #53c4ef;
|
||||
border-color: #33a4cf;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #33a4cf;
|
||||
border-color: #33a4cf;
|
||||
}
|
||||
|
||||
.btn-green {
|
||||
background-color: #0c0;
|
||||
border-color: #0b0;
|
||||
}
|
||||
.btn-green:hover {
|
||||
background-color: #0b0;
|
||||
border-color: #0b0;
|
||||
}
|
||||
.btn-red {
|
||||
background-color: #f00;
|
||||
border-color: #d00;
|
||||
}
|
||||
.btn-red:hover {
|
||||
background-color: #d00;
|
||||
border-color: #d00;
|
||||
}
|
||||
|
||||
|
||||
.messages {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
|
||||
.home #login, .home #intro {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.home .text-center {
|
||||
margin-top: 80px;
|
||||
}
|
||||
6
apimanager/base/static/css/bootstrap.min.css
vendored
Normal file
6
apimanager/base/static/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
apimanager/base/static/img/favicon.ico
Normal file
BIN
apimanager/base/static/img/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
14
apimanager/base/static/js/Chart.min.js
vendored
Normal file
14
apimanager/base/static/js/Chart.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
apimanager/base/static/js/base.js
Normal file
2
apimanager/base/static/js/base.js
Normal file
@ -0,0 +1,2 @@
|
||||
$(document).ready(function($) {
|
||||
});
|
||||
7
apimanager/base/static/js/bootstrap.min.js
vendored
Normal file
7
apimanager/base/static/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
apimanager/base/static/js/jquery.min.js
vendored
Normal file
4
apimanager/base/static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
85
apimanager/base/templates/base.html
Normal file
85
apimanager/base/templates/base.html
Normal file
@ -0,0 +1,85 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="OBP API Manager" >
|
||||
<meta name="author" content="TESOBE, Sebastian Henschel">
|
||||
<title>{% block page_title %}OBP API Manager{% endblock page_title %}</title>
|
||||
<link rel="icon" type="image/png" href="{% static 'img/favicon.ico' %}" />
|
||||
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'css/base.css' %}" rel="stylesheet">
|
||||
{% block extracss %}{% endblock extracss %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="{% url 'home' %}"><img src="https://static.openbankproject.com/images/OBP/favicon.png" alt="brand" /></a>
|
||||
</div>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
{% url "consumers-index" as consumers_index_url %}
|
||||
<li{% ifequal request.path consumers_index_url %} class="active" {% endifequal %}><a href="{{ consumers_index_url }}">Consumers</a></li>
|
||||
{% comment %}
|
||||
{% url "users-index" as users_index_url %}
|
||||
<li{% ifequal request.path users_index_url %} class="active" {% endifequal %}><a href="{{ users_index_url }}">Users</a></li>
|
||||
{% url "api-calls-grouped" as api_calls_grouped_url %}
|
||||
<li{% ifequal request.path api_calls_grouped_url %} class="active" {% endifequal %}><a href="{{ api_calls_grouped_url }}">API Calls Grouped</a></li>
|
||||
{% url "api-calls-list" as api_calls_list_url %}
|
||||
<li{% ifequal request.path api_calls_list_url %} class="active" {% endifequal %}><a href="{{ api_calls_list_url }}">API Calls List</a></li>
|
||||
{% url "api-config-index" as api_config_index_url %}
|
||||
<li{% ifequal request.path api_config_index_url %} class="active" {% endifequal %}><a href="{{ api_config_index_url }}">API Config</a></li>
|
||||
{% endcomment %}
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
{% if user.is_authenticated %}
|
||||
<p class="navbar-btn"><a href="{% url 'oauth-logout' %}" class="btn btn-default">Logout {{ API_USERNAME }}</a></p>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div><!--/.nav-collapse -->
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{% if messages %}
|
||||
<div class="container messages">
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-dismissible{% ifequal message.tags "error" %} alert-danger{% else %}{% ifequal message.tags "debug" %} alert-info{% else %} alert-{{ message.tags }}{% endifequal %}{% endifequal %}" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="container">
|
||||
{% block content %}{% endblock content %}
|
||||
</div>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p class="text-muted">
|
||||
<a title="API ROOT" href="{{ API_ROOT }}">API ROOT: {{ API_ROOT }}</a> |
|
||||
<a title="Open Bank Project" href="https://openbankproject.com">Open Bank Project</a> |
|
||||
Powered by <a title="TESOBE" href="http://tesobe.com">TESOBE</a> |
|
||||
<small>Copyright © 2016</small>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="{% static 'js/jquery.min.js' %}"></script>
|
||||
<script src="{% static 'js/bootstrap.min.js' %}"></script>
|
||||
<script src="{% static 'js/base.js' %}"></script>
|
||||
{% block extrajs %}{% endblock extrajs %}
|
||||
</body>
|
||||
</html>
|
||||
26
apimanager/base/templates/home.html
Normal file
26
apimanager/base/templates/home.html
Normal file
@ -0,0 +1,26 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="home">
|
||||
<h1>Welcome to API Manager</h1>
|
||||
|
||||
<div id="intro">
|
||||
<p>
|
||||
This app gives you access to management functionality for the sandbox at <a href="{{ OAUTH_API }}">{{ OAUTH_API }}</a> if the authenticated user has the required permissions, e.g. being a super admin. Currently, you can see consumers, users, calls (list and grouped in a bar chart) and configuration of the sandbox.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
{% if not user.is_authenticated %}
|
||||
<div id="login">
|
||||
Please authorise against {{ OAUTH_API }}: <a class="btn btn-primary" href="{% url 'oauth-initiate' %}{% if request.GET.next %}?next={{ request.GET.next }}{% endif %}">Proceed</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p class="text-center">
|
||||
<a href="https://openbankproject.com"><img src="https://static.openbankproject.com/images/OBP/OBP_full_web.png" alt="OBP logo" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
68
apimanager/base/utils.py
Normal file
68
apimanager/base/utils.py
Normal file
@ -0,0 +1,68 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import time
|
||||
from requests_oauthlib import OAuth1Session
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||
|
||||
|
||||
DATE_FORMAT = '%d/%b/%Y %H:%M:%S'
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def json_serial(obj):
|
||||
"""JSON serializer for objects not serializable by default json code"""
|
||||
|
||||
if isinstance(obj, datetime):
|
||||
serial = naturaltime(obj)
|
||||
return serial
|
||||
raise TypeError('Type not serializable')
|
||||
|
||||
|
||||
|
||||
def api_log(level, message):
|
||||
now = datetime.now().strftime(DATE_FORMAT)
|
||||
msg = '[{}] API: {}'.format(now, message)
|
||||
LOGGER.log(level, msg)
|
||||
|
||||
|
||||
def api_get(request, urlpath=''):
|
||||
return api_call(request, 'GET', urlpath)
|
||||
|
||||
|
||||
def api_post(request, urlpath, payload):
|
||||
return api_call(request, 'POST', urlpath, payload)
|
||||
|
||||
|
||||
def api_put(request, urlpath, payload):
|
||||
return api_call(request, 'PUT', urlpath, payload)
|
||||
|
||||
|
||||
def api_call(request, method='GET', urlpath='', payload=None):
|
||||
url = settings.OAUTH_API + settings.OAUTH_API_BASE_PATH + urlpath
|
||||
api_log(logging.INFO, '{} {}'.format(method, url))
|
||||
if not hasattr(request, 'api'):
|
||||
request.api = OAuth1Session(
|
||||
settings.OAUTH_CLIENT_KEY,
|
||||
client_secret=settings.OAUTH_CLIENT_SECRET,
|
||||
resource_owner_key=request.session['oauth_token'],
|
||||
resource_owner_secret=request.session['oauth_secret']
|
||||
)
|
||||
time_start = time.time()
|
||||
if payload:
|
||||
response = request.api.request(method, url, json=payload)
|
||||
else:
|
||||
response = request.api.request(method, url)
|
||||
time_end = time.time()
|
||||
elapsed = int((time_end - time_start) * 1000)
|
||||
api_log(logging.INFO, 'Took {} ms'.format(elapsed))
|
||||
if response.status_code in [404, 500]:
|
||||
msg = 'Ran into a {}: {}'.format(response.status_code, response.text)
|
||||
api_log(logging.ERROR, msg)
|
||||
data = response.text
|
||||
else:
|
||||
data = response.json()
|
||||
return data
|
||||
12
apimanager/base/views.py
Normal file
12
apimanager/base/views.py
Normal file
@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.conf import settings
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
template_name = "home.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(HomeView, self).get_context_data(**kwargs)
|
||||
context['OAUTH_API'] = settings.OAUTH_API
|
||||
return context
|
||||
0
apimanager/consumers/__init__.py
Normal file
0
apimanager/consumers/__init__.py
Normal file
5
apimanager/consumers/apps.py
Normal file
5
apimanager/consumers/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AppsConfig(AppConfig):
|
||||
name = 'consumers'
|
||||
23
apimanager/consumers/static/consumers/css/consumers.css
Normal file
23
apimanager/consumers/static/consumers/css/consumers.css
Normal file
@ -0,0 +1,23 @@
|
||||
.consumers #consumer-list {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.consumers .consumer-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.consumers .consumer-enabled {
|
||||
background-color: rgba(0, 255, 0, 0.1);
|
||||
}
|
||||
|
||||
.consumers .consumer-disabled {
|
||||
background-color: rgba(255, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.consumers .table > tbody > tr.active > td {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.consumers #filter-enabled {
|
||||
margin-left: 10px;
|
||||
}
|
||||
35
apimanager/consumers/static/consumers/js/consumers.js
Normal file
35
apimanager/consumers/static/consumers/js/consumers.js
Normal file
@ -0,0 +1,35 @@
|
||||
$(document).ready(function($) {
|
||||
$('#consumer-detail').hide();
|
||||
$('.consumers .consumer-row td.select').click(function() {
|
||||
$('.consumers .consumer-row').removeClass('active');
|
||||
var tr = $(this).parent();
|
||||
tr.addClass('active');
|
||||
var consumer_id = tr.data('consumer-id');
|
||||
$.each(CONSUMERS, function (idx, consumer) {
|
||||
if (consumer['id'] == consumer_id) {
|
||||
$('#consumer-detail-id').val(consumer['id']);
|
||||
$('#consumer-detail-name').html(consumer['name']);
|
||||
$('#consumer-detail-developerEmail').html(consumer['developerEmail']);
|
||||
$('#consumer-detail-created').html(consumer['created']);
|
||||
$('#consumer-detail-description').html(consumer['description']);
|
||||
var isactive = $('#consumer-detail-isactive');
|
||||
var enableButton = $('#consumer-detail-enable');
|
||||
enableButton.removeClass('btn-green').removeClass('btn-red');
|
||||
if (consumer['enabled']) {
|
||||
enableButton.addClass('btn-red');
|
||||
enableButton.html('Disable');
|
||||
enableButton.attr('href',
|
||||
CONSUMERS_DISABLE.replace('0', consumer['id']));
|
||||
isactive.prop('checked', true);
|
||||
} else {
|
||||
enableButton.addClass('btn-green');
|
||||
enableButton.html('Enable');
|
||||
enableButton.attr('href',
|
||||
CONSUMERS_ENABLE.replace('0', consumer['id']));
|
||||
isactive.prop('checked', false);
|
||||
}
|
||||
$('#consumer-detail').modal('show');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
101
apimanager/consumers/templates/consumers/index.html
Normal file
101
apimanager/consumers/templates/consumers/index.html
Normal file
@ -0,0 +1,101 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load humanize static %}
|
||||
|
||||
{% block page_title %}{{ block.super }} / Consumers{% endblock page_title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="consumers">
|
||||
<h1>Consumers</h1>
|
||||
|
||||
<div class="btn-group" role="group" id="filter-time" aria-label="filter-time">
|
||||
<a href="?time=minute&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_minute %} active{% endif %}">Last Minute</a>
|
||||
<a href="?time=hour&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_hour %} active{% endif %}">Last Hour</a>
|
||||
<a href="?time=day&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_day %} active{% endif %}">Last Day</a>
|
||||
<a href="?time=week&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_week %} active{% endif %}">Last Week</a>
|
||||
<a href="?time=month&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_month %} active{% endif %}">Last Month</a>
|
||||
<a href="?time=year&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_year %} active{% endif %}">Last Year</a>
|
||||
<a href="?time=all&apptype={{ request.GET.apptype }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_time_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
<div class="btn-group pull-right" id="filter-enabled" role="group" aria-label="filter-enabled">
|
||||
<a href="?enabled=true&apptype={{ request.GET.apptype }}&time={{ request.GET.time }}" class="btn btn-default{% if active_enabled_true %} active{% endif %}">Enabled</a>
|
||||
<a href="?enabled=false&apptype={{ request.GET.apptype }}&time={{ request.GET.time }}" class="btn btn-default{% if active_enabled_false %} active{% endif %}">Disabled</a>
|
||||
<a href="?enabled=all&apptype={{ request.GET.apptype }}&time={{ request.GET.time }}" class="btn btn-default{% if active_enabled_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
<div class="btn-group pull-right" id="filter-apptype" role="group" aria-label="filter-apptype">
|
||||
<a href="?apptype=web&time={{ request.GET.time }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_apptype_web %} active{% endif %}">Web</a>
|
||||
<a href="?apptype=mobile&time={{ request.GET.time }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_apptype_mobile %} active{% endif %}">Mobile</a>
|
||||
<a href="?apptype=all&time={{ request.GET.time }}&enabled={{ request.GET.enabled }}" class="btn btn-default{% if active_apptype_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
|
||||
<table class="table table-hover" id="consumer-list">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Developer Email</th>
|
||||
<th>Created</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for consumer in consumers %}
|
||||
<tr class="consumer-row {% if consumer.enabled %}consumer-enabled{% else %}consumer-disabled{% endif %}" data-consumer-id="{{ consumer.id }}">
|
||||
<td class="select">{{ consumer.name }}</td>
|
||||
<td class="select">{{ consumer.developerEmail }}</td>
|
||||
<td class="select">{{ consumer.created|naturaltime }}</td>
|
||||
<td>{% if consumer.enabled %}<a class="btn btn-sm btn-primary btn-red" href="{% url 'consumers-disable' consumer.id %}?{{ request.GET.urlencode }}" role="button">Disable</a>{% else %}<a class="btn btn-sm btn-primary btn-green" href="{% url 'consumers-enable' consumer.id %}?{{ request.GET.urlencode }}" role="button">Enable</a>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="modal fade" id="consumer-detail" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 id="consumer-detail-name"></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
<strong>Developer Email</strong><br />
|
||||
<span id="consumer-detail-developerEmail"></span>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Created</strong><br />
|
||||
<span id="consumer-detail-created"></span>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Description</strong><br />
|
||||
<div class="well" id="consumer-detail-description"></div>
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a id="consumer-detail-enable" class="btn btn-primary btn-red" href="" role="button">UNKNOWN</a>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'consumers/js/consumers.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
CONSUMERS = {{ consumers_json|safe }};
|
||||
CONSUMERS_ENABLE = "{% url 'consumers-enable' 0 %}?{{ request.GET.urlencode }}";
|
||||
CONSUMERS_DISABLE = "{% url 'consumers-disable' 0 %}?{{ request.GET.urlencode }}";
|
||||
</script>
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'consumers/css/consumers.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
9
apimanager/consumers/urls.py
Normal file
9
apimanager/consumers/urls.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexView, EnableView, DisableView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', IndexView.as_view(), name='consumers-index'),
|
||||
url(r'^enable/(?P<consumer_id>[0-9]+)$', EnableView.as_view(), name='consumers-enable'),
|
||||
url(r'^disable/(?P<consumer_id>[0-9]+)$', DisableView.as_view(), name='consumers-disable'),
|
||||
]
|
||||
92
apimanager/consumers/views.py
Normal file
92
apimanager/consumers/views.py
Normal file
@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse
|
||||
from django.views.generic import TemplateView, RedirectView
|
||||
|
||||
from base.filters import BaseFilter, FilterTime
|
||||
from base.utils import json_serial, api_get, api_put, api_post
|
||||
|
||||
|
||||
|
||||
class FilterAppType(BaseFilter):
|
||||
filter_type = 'apptype'
|
||||
|
||||
def _apply(self, data, filter_value):
|
||||
filtered = [x for x in data if x['appType'].lower() == filter_value]
|
||||
return filtered
|
||||
|
||||
|
||||
class FilterEnabled(BaseFilter):
|
||||
filter_type = 'enabled'
|
||||
|
||||
def _apply(self, data, filter_value):
|
||||
enabled = filter_value in ['true']
|
||||
filtered = [x for x in data if x['enabled'] == enabled]
|
||||
return filtered
|
||||
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "consumers/index.html"
|
||||
|
||||
def scrub(self, data):
|
||||
for consumer in data:
|
||||
consumer['created'] = datetime.strptime(
|
||||
consumer['created'], settings.API_DATETIMEFORMAT)
|
||||
return data
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
filtered = []
|
||||
urlpath = '/management/consumers'
|
||||
consumers = api_get(self.request, urlpath)
|
||||
|
||||
if not isinstance(consumers, dict):
|
||||
messages.error(self.request, consumers)
|
||||
elif 'error' in consumers:
|
||||
messages.error(self.request, consumers['error'])
|
||||
else:
|
||||
filtered = FilterEnabled(context, self.request.GET)\
|
||||
.apply(consumers['list'])
|
||||
filtered = FilterAppType(context, self.request.GET)\
|
||||
.apply(filtered)
|
||||
filtered = FilterTime(context, self.request.GET, 'created')\
|
||||
.apply(filtered)
|
||||
filtered = self.scrub(filtered)
|
||||
|
||||
context.update({
|
||||
'consumers': filtered,
|
||||
'consumers_json': json.dumps(filtered, default=json_serial),
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class EnableDisableView(LoginRequiredMixin, RedirectView):
|
||||
def get_redirect_url(self,*args, **kwargs):
|
||||
urlpath = '/management/consumers/{}'.format(kwargs['consumer_id'])
|
||||
payload = {'enabled': self.enabled}
|
||||
result = api_put(self.request, urlpath, payload)
|
||||
if 'error' in result:
|
||||
messages.error(self.request, result['error'])
|
||||
else:
|
||||
messages.success(self.request, self.success)
|
||||
query = self.request.GET.urlencode()
|
||||
url = '{}?{}'.format(reverse('consumers-index'), query)
|
||||
return url
|
||||
|
||||
|
||||
class EnableView(EnableDisableView):
|
||||
enabled = True
|
||||
success = "Consumer has been enabled."
|
||||
|
||||
|
||||
class DisableView(EnableDisableView):
|
||||
enabled = False
|
||||
success = "Consumer has been disabled."
|
||||
22
apimanager/manage.py
Executable file
22
apimanager/manage.py
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apimanager.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError:
|
||||
# The above import may fail for some other reason. Ensure that the
|
||||
# issue is really that Django is missing to avoid masking other
|
||||
# exceptions on Python 2.
|
||||
try:
|
||||
import django
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
)
|
||||
raise
|
||||
execute_from_command_line(sys.argv)
|
||||
0
apimanager/oauth/__init__.py
Normal file
0
apimanager/oauth/__init__.py
Normal file
5
apimanager/oauth/apps.py
Normal file
5
apimanager/oauth/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class OauthConfig(AppConfig):
|
||||
name = 'oauth'
|
||||
9
apimanager/oauth/urls.py
Normal file
9
apimanager/oauth/urls.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import InitiateView, AuthorizeView, LogoutView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^initiate$', InitiateView.as_view(), name='oauth-initiate'),
|
||||
url(r'^authorize$', AuthorizeView.as_view(), name='oauth-authorize'),
|
||||
url(r'^logout$', LogoutView.as_view(), name='oauth-logout'),
|
||||
]
|
||||
81
apimanager/oauth/views.py
Normal file
81
apimanager/oauth/views.py
Normal file
@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import login, logout
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from requests_oauthlib import OAuth1Session
|
||||
|
||||
from base.utils import api_get
|
||||
|
||||
|
||||
class InitiateView(RedirectView):
|
||||
def get_callback_uri(self, request):
|
||||
base_url = '{}://{}'.format(
|
||||
request.scheme, request.environ['HTTP_HOST'])
|
||||
uri = base_url + reverse('oauth-authorize')
|
||||
if 'next' in request.GET:
|
||||
uri = '{}?next={}'.format(uri, request.GET['next'])
|
||||
return uri
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
callback_uri = self.get_callback_uri(self.request)
|
||||
api = OAuth1Session(
|
||||
settings.OAUTH_CLIENT_KEY,
|
||||
client_secret=settings.OAUTH_CLIENT_SECRET,
|
||||
callback_uri=callback_uri,
|
||||
)
|
||||
|
||||
try:
|
||||
url = settings.OAUTH_API + settings.OAUTH_TOKEN_PATH
|
||||
fetch_response = api.fetch_request_token(url)
|
||||
except ValueError as exc:
|
||||
messages.error(self.request, exc)
|
||||
return reverse('home')
|
||||
|
||||
url = settings.OAUTH_API + settings.OAUTH_AUTHORIZATION_PATH
|
||||
authorization_url = api.authorization_url(url)
|
||||
self.request.session['oauth_token'] = fetch_response.get('oauth_token')
|
||||
self.request.session['oauth_secret'] = fetch_response.get('oauth_token_secret')
|
||||
self.request.session.modified = True
|
||||
return authorization_url
|
||||
|
||||
|
||||
class AuthorizeView(RedirectView):
|
||||
def login_to_django(self):
|
||||
# Kind of faking it to establish if a user is authenticated later on
|
||||
data = api_get(self.request, '/users/current')
|
||||
userid = data['user_id'] or data['email']
|
||||
username = hashlib.sha256(userid.encode('utf-8')).hexdigest()
|
||||
password = username
|
||||
user, _ = User.objects.get_or_create(
|
||||
username=username, password=password,
|
||||
)
|
||||
login(self.request, user)
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
api = OAuth1Session(
|
||||
settings.OAUTH_CLIENT_KEY,
|
||||
settings.OAUTH_CLIENT_SECRET,
|
||||
resource_owner_key=self.request.session['oauth_token'],
|
||||
resource_owner_secret=self.request.session['oauth_secret']
|
||||
)
|
||||
api.parse_authorization_response(self.request.build_absolute_uri())
|
||||
url = settings.OAUTH_API + settings.OAUTH_ACCESS_TOKEN_PATH
|
||||
fetch_response = api.fetch_access_token(url)
|
||||
|
||||
self.request.session['oauth_token'] = fetch_response.get('oauth_token')
|
||||
self.request.session['oauth_secret'] = fetch_response.get('oauth_token_secret')
|
||||
self.login_to_django()
|
||||
redirect_url = self.request.GET.get('next', reverse('consumers-index'))
|
||||
return redirect_url
|
||||
|
||||
|
||||
class LogoutView(RedirectView):
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
logout(self.request)
|
||||
return reverse('home')
|
||||
0
apimanager/users/__init__.py
Normal file
0
apimanager/users/__init__.py
Normal file
5
apimanager/users/apps.py
Normal file
5
apimanager/users/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'users'
|
||||
21
apimanager/users/static/users/css/users.css
Normal file
21
apimanager/users/static/users/css/users.css
Normal file
@ -0,0 +1,21 @@
|
||||
.users #user-list {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.users #user-detail {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
.users #entitlement-template {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.users .form-inline .form-group {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.user-row.active {
|
||||
background-color: #ddd;
|
||||
}
|
||||
40
apimanager/users/static/users/js/users.js
Normal file
40
apimanager/users/static/users/js/users.js
Normal file
@ -0,0 +1,40 @@
|
||||
$(document).ready(function($) {
|
||||
$('#user-detail').hide();
|
||||
$('.users .user-row').click(function() {
|
||||
$('.users .user-row').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
var user_id = $(this).data('user-id')
|
||||
$.each(USERS, function (idx, user) {
|
||||
if (user['id'] == user_id) {
|
||||
$('#user-detail-id').val(user['id']);
|
||||
$('#user-detail-name').html(user['name_']);
|
||||
var isSuperAdmin = $('#user-detail-is-super-admin');
|
||||
if (user['is_super_admin']) {
|
||||
isSuperAdmin.html('Super Admin');
|
||||
} else {
|
||||
isSuperAdmin.html('');
|
||||
}
|
||||
$('#user-detail-email').html(user['email']);
|
||||
$('#user-detail-last-login').html(user['last_login']);
|
||||
$('#user-detail .entitlement').remove();
|
||||
$.each(user['entitlements'], function(idx, entitlement) {
|
||||
var role_name = entitlement['role_name'];
|
||||
console.log('entitlement ' + entitlement);
|
||||
var formgroup = $('#entitlement-template').clone();
|
||||
formgroup.removeAttr('id');
|
||||
formgroup.addClass('entitlement');
|
||||
var checkbox = formgroup.find('input');
|
||||
checkbox.prop('checked', true);
|
||||
checkbox.attr('name', 'entitlement-' + role_name);
|
||||
checkbox.attr('id', 'user-detail-entitlement-' + role_name);
|
||||
var label = formgroup.find('label');
|
||||
label.attr('for', 'user-detail-entitlement-' + role_name);
|
||||
label.html(role_name);
|
||||
formgroup.appendTo('#user-detail form');
|
||||
});
|
||||
$('#user-detail').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
96
apimanager/users/templates/users/index.html
Normal file
96
apimanager/users/templates/users/index.html
Normal file
@ -0,0 +1,96 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load humanize static %}
|
||||
|
||||
{% block content %}
|
||||
<div class="users">
|
||||
<h1>Users</h1>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
The only live data here is the role names!
|
||||
</div>
|
||||
|
||||
<div class="btn-group" role="group" id="filter-time" aria-label="filter-time">
|
||||
<a href="?time=minute&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_minute %} active{% endif %}">Last Minute</a>
|
||||
<a href="?time=hour&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_hour %} active{% endif %}">Last Hour</a>
|
||||
<a href="?time=day&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_day %} active{% endif %}">Last Day</a>
|
||||
<a href="?time=week&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_week %} active{% endif %}">Last Week</a>
|
||||
<a href="?time=month&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_month %} active{% endif %}">Last Month</a>
|
||||
<a href="?time=year&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_year %} active{% endif %}">Last Year</a>
|
||||
<a href="?time=all&role_name={{ request.GET.role_name }}" class="btn btn-default{% if active_time_all %} active{% endif %}">All</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="btn-group pull-right">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" id="filter-entitlement" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
{{ active_role_name }} <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="?role_name=all&time={{ request.GET.time }}">All</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
{% for role_name in role_names %}
|
||||
<li><a href="?role_name={{ role_name }}&time={{ request.GET.time }}">{{ role_name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<table class="table" id="user-list">
|
||||
<thead>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr class="user-row" data-user-id="{{ user.id }}">
|
||||
<td>{{ user.name_ }}</td>
|
||||
<td>{% if user.is_super_admin %}Super Admin{% endif %}</td>
|
||||
<td>{{ user.email }}</td>
|
||||
<td>{{ user.last_login|naturaltime }}</td>
|
||||
<td>{{ user.whatever }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<div id="user-detail">
|
||||
<h2>Details</h2>
|
||||
|
||||
<form class="form-inline">
|
||||
<input type="hidden" name="id" id="user-detail-id" value="" />
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="user-detail-name"></td>
|
||||
<td id="user-detail-is-super-admin"></td>
|
||||
<td id="user-detail-email"></td>
|
||||
<td id="user-detail-last-login"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<div class="form-group" id="entitlement-template">
|
||||
<input type="checkbox" class="form-control" name="" id="" aria-label="active" disabled="disabled" />
|
||||
<label for="user-detail-entitlement" class="control-label"></label>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajs %}
|
||||
<script type="text/javascript" src="{% static 'users/js/users.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
USERS = {{ users_json|safe }};
|
||||
</script>
|
||||
{% endblock extrajs %}
|
||||
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'users/css/users.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
7
apimanager/users/urls.py
Normal file
7
apimanager/users/urls.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', IndexView.as_view(), name='users-index'),
|
||||
]
|
||||
94
apimanager/users/views.py
Normal file
94
apimanager/users/views.py
Normal file
@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from base.filters import filter_time
|
||||
from base.utils import json_serial, api_get
|
||||
|
||||
|
||||
APIUSER = [
|
||||
{
|
||||
'id': 1,
|
||||
'email': 'sebastian@tesobe.com',
|
||||
'name_': 'Sebastian Henschel',
|
||||
'userid_': 'zyzop',
|
||||
#'userid_': '05c98d97-5d6d-46b5-a880-2da0a45019c8',
|
||||
'last_login': '2016-09-07 12:34:47',
|
||||
'whatever': 'dfasdfsd',
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'email': 'robert.x.0.gh@example.com',
|
||||
'name_': 'Robert X.0.GH',
|
||||
'userid_': 'ff3f94f9-bbd6-4cd9-ab78-3701e961eb58',
|
||||
'last_login': '2016-08-10 16:34:47',
|
||||
'whatever': 'ijkjkljljk',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
class IndexView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "users/index.html"
|
||||
|
||||
def filter_role_name(self, context, data):
|
||||
context['active_role_name'] = 'All'
|
||||
if not 'role_name' in self.request.GET:
|
||||
return data
|
||||
role_name = self.request.GET['role_name']
|
||||
if not role_name or role_name.lower() == 'all':
|
||||
return data
|
||||
|
||||
filtered = []
|
||||
for user in data:
|
||||
for entitlement in user['entitlements']:
|
||||
if role_name == entitlement['role_name']:
|
||||
filtered.append(user)
|
||||
break
|
||||
|
||||
if filtered:
|
||||
context['active_role_name'] = role_name
|
||||
return filtered
|
||||
|
||||
def scrub(self, data):
|
||||
for user in data:
|
||||
user['last_login'] = datetime.strptime(user['last_login'], '%Y-%m-%d %H:%M:%S')
|
||||
return data
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
filtered = deepcopy(APIUSER)
|
||||
role_names = []
|
||||
|
||||
for user in filtered:
|
||||
urlpath = '/users/{}/entitlements'.format(user['userid_'])
|
||||
entitlements = api_get(self.request, urlpath)
|
||||
if 'error' in entitlements:
|
||||
messages.error(self.request, entitlements['error'])
|
||||
break
|
||||
else:
|
||||
user['entitlements'] = []
|
||||
for entitlement in entitlements['list']:
|
||||
user['entitlements'].append(entitlement)
|
||||
if entitlement['role_name'] == 'SuperAdmin':
|
||||
user['is_super_admin'] = True
|
||||
role_names.append(entitlement['role_name'])
|
||||
role_names = list(set(role_names))
|
||||
role_names.sort()
|
||||
|
||||
filtered = self.filter_role_name(context, filtered)
|
||||
filtered = filter_time(self.request, context, filtered, 'last_login')
|
||||
filtered = self.scrub(filtered)
|
||||
|
||||
context.update({
|
||||
'role_names': role_names,
|
||||
'users': filtered,
|
||||
'users_json': json.dumps(filtered, default=json_serial),
|
||||
})
|
||||
return context
|
||||
12
gunicorn.conf.py
Normal file
12
gunicorn.conf.py
Normal file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
import multiprocessing
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
bind = '127.0.0.1:8000'
|
||||
accesslog = os.path.join(BASE_DIR, 'logs', 'gunicorn.access.log')
|
||||
errorlog = os.path.join(BASE_DIR, 'logs', 'gunicorn.error.log')
|
||||
loglevel = 'info'
|
||||
capture_output = True
|
||||
workers = multiprocessing.cpu_count() * 2 + 1
|
||||
21
nginx.apimanager.conf
Normal file
21
nginx.apimanager.conf
Normal file
@ -0,0 +1,21 @@
|
||||
# nginx server configuration for apimanager
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
server_name apimanager;
|
||||
|
||||
location / {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# enable this if and only if you use HTTPS
|
||||
# proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://127.0.0.1:8000;
|
||||
}
|
||||
|
||||
location /static {
|
||||
alias /var/www/apimanager/static-collected;
|
||||
}
|
||||
}
|
||||
6
requirements.txt
Normal file
6
requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Django==1.10.3
|
||||
oauthlib==2.0.0
|
||||
pkg-resources==0.0.0
|
||||
requests==2.11.1
|
||||
requests-oauthlib==0.6.2
|
||||
gunicorn==19.6.0
|
||||
10
supervisor.apimanager.conf
Normal file
10
supervisor.apimanager.conf
Normal file
@ -0,0 +1,10 @@
|
||||
[program:apimanager]
|
||||
directory = /var/www/apimanager/API-Manager/apimanager
|
||||
user = www-data
|
||||
group = www-data
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=3
|
||||
command = /var/www/apimanager/venv/bin/gunicorn --config /var/www/apimanager/API-Manager/gunicorn.conf.py apimanager.wsgi
|
||||
stdout_logfile = /var/www/apimanager/logs/supervisor.stdout.log
|
||||
stderr_logfile = /var/www/apimanager/logs/supervisor.stderr.log
|
||||
Loading…
Reference in New Issue
Block a user