add vendoring
This commit is contained in:
11
vendor/gitlab.com/etke.cc/go/env/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/env/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
661
vendor/gitlab.com/etke.cc/go/env/LICENSE
generated
vendored
Normal file
661
vendor/gitlab.com/etke.cc/go/env/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://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.
|
||||
|
||||
env
|
||||
Copyright (C) 2022 etke.cc / Go
|
||||
|
||||
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 <https://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
|
||||
<https://www.gnu.org/licenses/>.
|
||||
13
vendor/gitlab.com/etke.cc/go/env/README.md
generated
vendored
Normal file
13
vendor/gitlab.com/etke.cc/go/env/README.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# ENV
|
||||
|
||||
Simple go environment variables reader, for env-based configs
|
||||
|
||||
```go
|
||||
env.SetPrefix("app") // all env vars should start with APP_
|
||||
login := env.String("matrix.login", "none") // export APP_MATRIX_LOGIN=buscarron
|
||||
enabled := env.Bool("form.enabled") // export APP_FORM_ENABLED=1
|
||||
size := env.Int("cache.size", 1000) // export APP_CACHE_SIZE=500
|
||||
slice := env.Slice("form.fields") // export APP_FORM_FIELDS="one two three"
|
||||
```
|
||||
|
||||
see more in godoc
|
||||
59
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
Normal file
59
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var envprefix string
|
||||
|
||||
// SetPrefix sets prefix for all env vars
|
||||
func SetPrefix(prefix string) {
|
||||
envprefix = prefix
|
||||
}
|
||||
|
||||
// String returns string vars
|
||||
func String(shortkey string, defaultValue string) string {
|
||||
key := strings.ToUpper(envprefix + "_" + strings.ReplaceAll(shortkey, ".", "_"))
|
||||
value := strings.TrimSpace(os.Getenv(key))
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// Int returns int vars
|
||||
func Int(shortkey string, defaultValue int) int {
|
||||
str := String(shortkey, "")
|
||||
if str == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
val, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
// Bool returns boolean vars (1, true, yes)
|
||||
func Bool(shortkey string) bool {
|
||||
str := strings.ToLower(String(shortkey, ""))
|
||||
if str == "" {
|
||||
return false
|
||||
}
|
||||
return (str == "1" || str == "true" || str == "yes")
|
||||
}
|
||||
|
||||
// Slice returns slice from space-separated strings, eg: export VAR="one two three" => []string{"one", "two", "three"}
|
||||
func Slice(shortkey string) []string {
|
||||
str := String(shortkey, "")
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return strings.Split(str, " ")
|
||||
}
|
||||
11
vendor/gitlab.com/etke.cc/go/logger/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/logger/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
165
vendor/gitlab.com/etke.cc/go/logger/LICENSE
generated
vendored
Normal file
165
vendor/gitlab.com/etke.cc/go/logger/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
6
vendor/gitlab.com/etke.cc/go/logger/README.md
generated
vendored
Normal file
6
vendor/gitlab.com/etke.cc/go/logger/README.md
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# logger
|
||||
|
||||
Simple go logger, based on [log](https://pkg.go.dev/log) with following features:
|
||||
|
||||
* implements mautrix-go [Logger](https://pkg.go.dev/maunium.net/go/mautrix#Logger), [WarnLogger](https://pkg.go.dev/maunium.net/go/mautrix#WarnLogger), [crypto Logger](https://pkg.go.dev/maunium.net/go/mautrix/crypto#Logger)
|
||||
* integrated with [sentry](https://sentry.io) - automatically add breadcrumbs for any log entry
|
||||
188
vendor/gitlab.com/etke.cc/go/logger/logger.go
generated
vendored
Normal file
188
vendor/gitlab.com/etke.cc/go/logger/logger.go
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
)
|
||||
|
||||
// Logger struct
|
||||
type Logger struct {
|
||||
log *log.Logger
|
||||
hub *sentry.Hub
|
||||
level int
|
||||
}
|
||||
|
||||
const (
|
||||
// TRACE level
|
||||
TRACE int = iota
|
||||
// DEBUG level
|
||||
DEBUG
|
||||
// INFO level
|
||||
INFO
|
||||
// WARNING level
|
||||
WARNING
|
||||
// ERROR level
|
||||
ERROR
|
||||
// FATAL level
|
||||
FATAL
|
||||
)
|
||||
|
||||
var (
|
||||
txtLevelMap = map[string]int{
|
||||
"TRACE": TRACE,
|
||||
"DEBUG": DEBUG,
|
||||
"INFO": INFO,
|
||||
"WARNING": WARNING,
|
||||
"ERROR": ERROR,
|
||||
"FATAL": FATAL,
|
||||
}
|
||||
levelMap = map[int]string{
|
||||
TRACE: "TRACE",
|
||||
DEBUG: "DEBUG",
|
||||
INFO: "INFO",
|
||||
WARNING: "WARNING",
|
||||
ERROR: "ERROR",
|
||||
FATAL: "FATAL",
|
||||
}
|
||||
sentryLevelMap = map[int]sentry.Level{
|
||||
TRACE: sentry.LevelDebug,
|
||||
DEBUG: sentry.LevelDebug,
|
||||
INFO: sentry.LevelInfo,
|
||||
WARNING: sentry.LevelWarning,
|
||||
ERROR: sentry.LevelError,
|
||||
FATAL: sentry.LevelFatal,
|
||||
}
|
||||
)
|
||||
|
||||
// New creates new Logger object
|
||||
func New(prefix string, level string, sentryHub ...*sentry.Hub) *Logger {
|
||||
levelID, ok := txtLevelMap[strings.ToUpper(level)]
|
||||
if !ok {
|
||||
levelID = INFO
|
||||
}
|
||||
var hub *sentry.Hub
|
||||
if len(sentryHub) > 0 {
|
||||
hub = sentryHub[0]
|
||||
}
|
||||
|
||||
return &Logger{log: log.New(os.Stdout, prefix, 0), level: levelID, hub: hub}
|
||||
}
|
||||
|
||||
// GetHub returns sentry hub (either attached to the logger when called New() or current sentry hub)
|
||||
func (l *Logger) GetHub() *sentry.Hub {
|
||||
if l.hub == nil {
|
||||
return sentry.CurrentHub()
|
||||
}
|
||||
|
||||
return l.hub
|
||||
}
|
||||
|
||||
// GetLog returns underlying Logger object, useful in cases where log.Logger required
|
||||
func (l *Logger) GetLog() *log.Logger {
|
||||
return l.log
|
||||
}
|
||||
|
||||
// GetLevel (current)
|
||||
func (l *Logger) GetLevel() string {
|
||||
return levelMap[l.level]
|
||||
}
|
||||
|
||||
// Fatal log and exit
|
||||
func (l *Logger) Fatal(message string, args ...interface{}) {
|
||||
l.log.Panicln("FATAL", fmt.Sprintf(message, args...))
|
||||
}
|
||||
|
||||
// Error log
|
||||
func (l *Logger) Error(message string, args ...interface{}) {
|
||||
// do not recover
|
||||
if strings.HasPrefix(message, "recovery()") {
|
||||
return
|
||||
}
|
||||
|
||||
message = fmt.Sprintf(message, args...)
|
||||
l.GetHub().AddBreadcrumb(&sentry.Breadcrumb{
|
||||
Category: l.log.Prefix(),
|
||||
Message: message,
|
||||
Level: sentryLevelMap[ERROR],
|
||||
}, nil)
|
||||
|
||||
if l.level > ERROR {
|
||||
return
|
||||
}
|
||||
|
||||
l.log.Println("ERROR", message)
|
||||
}
|
||||
|
||||
// Warn log
|
||||
func (l *Logger) Warn(message string, args ...interface{}) {
|
||||
message = fmt.Sprintf(message, args...)
|
||||
l.GetHub().AddBreadcrumb(&sentry.Breadcrumb{
|
||||
Category: l.log.Prefix(),
|
||||
Message: message,
|
||||
Level: sentryLevelMap[WARNING],
|
||||
}, nil)
|
||||
if l.level > WARNING {
|
||||
return
|
||||
}
|
||||
|
||||
l.log.Println("WARNING", message)
|
||||
}
|
||||
|
||||
// Warnfln for mautrix.Logger
|
||||
func (l *Logger) Warnfln(message string, args ...interface{}) {
|
||||
l.Warn(message, args...)
|
||||
}
|
||||
|
||||
// Info log
|
||||
func (l *Logger) Info(message string, args ...interface{}) {
|
||||
message = fmt.Sprintf(message, args...)
|
||||
l.GetHub().AddBreadcrumb(&sentry.Breadcrumb{
|
||||
Category: l.log.Prefix(),
|
||||
Message: message,
|
||||
Level: sentryLevelMap[INFO],
|
||||
}, nil)
|
||||
if l.level > INFO {
|
||||
return
|
||||
}
|
||||
|
||||
l.log.Println("INFO", message)
|
||||
}
|
||||
|
||||
// Debug log
|
||||
func (l *Logger) Debug(message string, args ...interface{}) {
|
||||
message = fmt.Sprintf(message, args...)
|
||||
l.GetHub().AddBreadcrumb(&sentry.Breadcrumb{
|
||||
Category: l.log.Prefix(),
|
||||
Message: message,
|
||||
Level: sentryLevelMap[DEBUG],
|
||||
}, nil)
|
||||
if l.level > DEBUG {
|
||||
return
|
||||
}
|
||||
|
||||
l.log.Println("DEBUG", message)
|
||||
}
|
||||
|
||||
// Debugfln for mautrix.Logger
|
||||
func (l *Logger) Debugfln(message string, args ...interface{}) {
|
||||
l.Debug(message, args...)
|
||||
}
|
||||
|
||||
// Trace log
|
||||
func (l *Logger) Trace(message string, args ...interface{}) {
|
||||
message = fmt.Sprintf(message, args...)
|
||||
l.GetHub().AddBreadcrumb(&sentry.Breadcrumb{
|
||||
Category: l.log.Prefix(),
|
||||
Message: message,
|
||||
Level: sentryLevelMap[TRACE],
|
||||
}, nil)
|
||||
if l.level > TRACE {
|
||||
return
|
||||
}
|
||||
|
||||
l.log.Println("TRACE", message)
|
||||
}
|
||||
11
vendor/gitlab.com/etke.cc/go/mxidwc/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/mxidwc/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
166
vendor/gitlab.com/etke.cc/go/mxidwc/LICENSE
generated
vendored
Normal file
166
vendor/gitlab.com/etke.cc/go/mxidwc/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
5
vendor/gitlab.com/etke.cc/go/mxidwc/README.md
generated
vendored
Normal file
5
vendor/gitlab.com/etke.cc/go/mxidwc/README.md
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# mxidwc
|
||||
|
||||
**M**atri**xID** **W**ild**c**ard parser
|
||||
|
||||
See godoc for info
|
||||
105
vendor/gitlab.com/etke.cc/go/mxidwc/parser.go
generated
vendored
Normal file
105
vendor/gitlab.com/etke.cc/go/mxidwc/parser.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
package mxidwc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Match tells if the given user id is allowed according to the given list of regexes
|
||||
func Match(userID string, allowed []*regexp.Regexp) bool {
|
||||
for _, regex := range allowed {
|
||||
if regex.MatchString(userID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ParsePatterns converts a list of wildcard patterns to a list of regular expressions
|
||||
// See ParsePattern for details
|
||||
func ParsePatterns(patterns []string) ([]*regexp.Regexp, error) {
|
||||
regexes := make([]*regexp.Regexp, 0, len(patterns))
|
||||
|
||||
for _, pattern := range patterns {
|
||||
regex, err := ParsePattern(pattern)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse pattern `%s`: %s", pattern, err)
|
||||
}
|
||||
regexes = append(regexes, regex)
|
||||
}
|
||||
|
||||
return regexes, nil
|
||||
}
|
||||
|
||||
// ParsePattern parses a user wildcard pattern and returns a regular expression which corresponds to it
|
||||
//
|
||||
// Example conversion: `@bot.*.something:*.example.com` -> `^bot\.([^:@]*)\.something:([^:@]*)\.example.com$`
|
||||
// Example of recognized wildcard patterns: `@someone:example.com`, `@*:example.com`, `@bot.*:example.com`, `@someone:*`, `@someone:*.example.com`
|
||||
//
|
||||
// The `*` wildcard character is normally interpretted as "a number of literal characters or an empty string".
|
||||
// Our implementation below matches this (yielding `([^:@])*`), which could provide a slightly suboptimal regex in these cases:
|
||||
// - `@*:example.com` -> `^@([^:@])*:example\.com$`, although `^@([^:@])+:example\.com$` would be preferable
|
||||
// - `@someone:*` -> `@someone:([^:@])*$`, although `@someone:([^:@])+$` would be preferable
|
||||
// When it's a bare wildcard (`*`, instead of `*.example.com`) we likely prefer to yield a regex that matches **at least one character**.
|
||||
// This probably doesn't matter because mxids that we'll match against are all valid and fully complete.
|
||||
func ParsePattern(pattern string) (*regexp.Regexp, error) {
|
||||
if !strings.HasPrefix(pattern, "@") {
|
||||
return nil, fmt.Errorf("patterns need to be fully-qualified, starting with a @")
|
||||
}
|
||||
|
||||
pattern = pattern[1:]
|
||||
if strings.Contains(pattern, "@") {
|
||||
return nil, fmt.Errorf("patterns cannot contain more than one @")
|
||||
}
|
||||
|
||||
parts := strings.Split(pattern, ":")
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("expected exactly 2 parts in the pattern, separated by `:`")
|
||||
}
|
||||
|
||||
localpart := parts[0]
|
||||
localpartPattern, err := getPattern(localpart)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert localpart `%s` to regex: %s", localpart, err)
|
||||
}
|
||||
|
||||
domain := parts[1]
|
||||
domainPattern, err := getPattern(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert domain `%s` to regex: %s", domain, err)
|
||||
}
|
||||
|
||||
pattern = fmt.Sprintf("^@%s:%s$", localpartPattern, domainPattern)
|
||||
|
||||
regex, err := regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to compile regex `%s`: %s", pattern, err)
|
||||
}
|
||||
|
||||
return regex, nil
|
||||
}
|
||||
|
||||
func getPattern(part string) (string, error) {
|
||||
if part == "" {
|
||||
return "", fmt.Errorf("rejecting empty part")
|
||||
}
|
||||
|
||||
var pattern strings.Builder
|
||||
for _, runeItem := range part {
|
||||
if runeItem == '*' {
|
||||
// We match everything except for `:` and `@`, because that would be an invalid MXID anyway.
|
||||
//
|
||||
// If the whole part is `*` (only) instead of merely containing `*` within it,
|
||||
// we may also consider replacing it with `([^:@]+)` (+, instead of *).
|
||||
// See ParsePattern for notes about this.
|
||||
pattern.WriteString("([^:@]*)")
|
||||
continue
|
||||
}
|
||||
|
||||
pattern.WriteString(regexp.QuoteMeta(string(runeItem)))
|
||||
}
|
||||
|
||||
return pattern.String(), nil
|
||||
}
|
||||
11
vendor/gitlab.com/etke.cc/go/secgen/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/secgen/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
166
vendor/gitlab.com/etke.cc/go/secgen/LICENSE
generated
vendored
Normal file
166
vendor/gitlab.com/etke.cc/go/secgen/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
16
vendor/gitlab.com/etke.cc/go/secgen/README.md
generated
vendored
Normal file
16
vendor/gitlab.com/etke.cc/go/secgen/README.md
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# secgen
|
||||
|
||||
Secrets generator, supported types:
|
||||
|
||||
* Passwords
|
||||
* ED25519 SSH keypairs
|
||||
|
||||
Simple go environment variables reader, for env-based configs
|
||||
|
||||
```go
|
||||
// password
|
||||
securePassword := secgen.Password(64)
|
||||
|
||||
// ssh key
|
||||
publicSSHkey, privateSSHkey, err := secgen.Keypair()
|
||||
```
|
||||
68
vendor/gitlab.com/etke.cc/go/secgen/keypair.go
generated
vendored
Normal file
68
vendor/gitlab.com/etke.cc/go/secgen/keypair.go
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
package secgen
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"strings"
|
||||
|
||||
"github.com/mikesmitty/edkey"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
// RSABits used for DKIM keypair
|
||||
const RSABits = 3072
|
||||
|
||||
// Keypair generates ed25519 keypair for ssh (public key, private key)
|
||||
func Keypair() (string, string, error) {
|
||||
publicBytes, privateBytes, err := ed25519.GenerateKey(nil)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
publicStruct, err := ssh.NewPublicKey(publicBytes)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
pemblock := &pem.Block{
|
||||
Type: "OPENSSH PRIVATE KEY",
|
||||
Bytes: edkey.MarshalED25519PrivateKey(privateBytes),
|
||||
}
|
||||
private := pem.EncodeToMemory(pemblock)
|
||||
public := ssh.MarshalAuthorizedKey(publicStruct)
|
||||
|
||||
return string(public), string(private), nil
|
||||
}
|
||||
|
||||
// DKIM generates DKIM signature and private key (TXT record, private key)
|
||||
func DKIM() (string, string, error) {
|
||||
privateBytes, err := rsa.GenerateKey(rand.Reader, RSABits)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
publicBytes, err := x509.MarshalPKIXPublicKey(privateBytes.Public())
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
pkcs8, err := x509.MarshalPKCS8PrivateKey(privateBytes)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
pemblock := &pem.Block{
|
||||
Type: "PRIVATE KEY",
|
||||
Bytes: pkcs8,
|
||||
}
|
||||
private := pem.EncodeToMemory(pemblock)
|
||||
dkim := []string{
|
||||
"v=DKIM1",
|
||||
"k=rsa",
|
||||
"p=" + base64.StdEncoding.EncodeToString(publicBytes),
|
||||
}
|
||||
|
||||
return strings.Join(dkim, "; "), string(private), nil
|
||||
}
|
||||
22
vendor/gitlab.com/etke.cc/go/secgen/password.go
generated
vendored
Normal file
22
vendor/gitlab.com/etke.cc/go/secgen/password.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package secgen
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const charset = "abcdedfghijklmnopqrstABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // a-z A-Z 0-9
|
||||
var charsetlen = big.NewInt(57)
|
||||
|
||||
// Password generates secure password
|
||||
func Password(length int) string {
|
||||
var password strings.Builder
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
index, _ := rand.Int(rand.Reader, charsetlen)
|
||||
password.WriteByte(charset[index.Int64()])
|
||||
}
|
||||
|
||||
return password.String()
|
||||
}
|
||||
11
vendor/gitlab.com/etke.cc/go/trysmtp/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/trysmtp/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
166
vendor/gitlab.com/etke.cc/go/trysmtp/LICENSE
generated
vendored
Normal file
166
vendor/gitlab.com/etke.cc/go/trysmtp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
20
vendor/gitlab.com/etke.cc/go/trysmtp/README.md
generated
vendored
Normal file
20
vendor/gitlab.com/etke.cc/go/trysmtp/README.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# trySMTP
|
||||
|
||||
Library that tries to connect to SMTP host by TO/target email address:
|
||||
|
||||
* Lookup MX and A
|
||||
* Try to connect to SMTP on different ports
|
||||
* Try to use STARTTLS if server supports it
|
||||
* Return SMTP Client with `Mail()` and `Rcpt()` already called
|
||||
|
||||
|
||||
```go
|
||||
from := "sender@example.com"
|
||||
to := "target@example.org"
|
||||
client, err := trysmtp.Connect(from, to)
|
||||
if err != nil {
|
||||
// something went wrong!
|
||||
}
|
||||
|
||||
client.Data([]byte("your email data here"))
|
||||
```
|
||||
82
vendor/gitlab.com/etke.cc/go/trysmtp/client.go
generated
vendored
Normal file
82
vendor/gitlab.com/etke.cc/go/trysmtp/client.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
package trysmtp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SMTPAddrs priority list
|
||||
var SMTPAddrs = []string{":25", ":587", ":465"}
|
||||
|
||||
// Connect to SMTP server and call MAIL and RCPT commands
|
||||
func Connect(from, to string) (*smtp.Client, error) {
|
||||
localname := strings.SplitN(from, "@", 2)[1]
|
||||
hostname := strings.SplitN(to, "@", 2)[1]
|
||||
client, err := initClient(localname, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = client.Mail(from)
|
||||
if err != nil {
|
||||
client.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = client.Rcpt(to)
|
||||
if err != nil {
|
||||
client.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func initClient(localname, hostname string) (*smtp.Client, error) {
|
||||
mxs, err := net.LookupMX(hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, mx := range mxs {
|
||||
for _, addr := range SMTPAddrs {
|
||||
client := trySMTP(localname, strings.TrimSuffix(mx.Host, "."), addr)
|
||||
if client != nil {
|
||||
return client, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no MX records, according to https://datatracker.ietf.org/doc/html/rfc5321#section-5.1,
|
||||
// we're supposed to try talking directly to the host.
|
||||
if len(mxs) == 0 {
|
||||
for _, addr := range SMTPAddrs {
|
||||
client := trySMTP(localname, hostname, addr)
|
||||
if client != nil {
|
||||
return client, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("target SMTP server not found")
|
||||
}
|
||||
|
||||
func trySMTP(localname, mxhost, addr string) *smtp.Client {
|
||||
conn, err := smtp.Dial(mxhost + addr)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = conn.Hello(localname)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if ok, _ := conn.Extension("STARTTLS"); ok {
|
||||
config := &tls.Config{ServerName: mxhost}
|
||||
conn.StartTLS(config) //nolint:errcheck // if it doesn't work - we can't do anything anyway
|
||||
}
|
||||
|
||||
return conn
|
||||
}
|
||||
11
vendor/gitlab.com/etke.cc/go/validator/.gitlab-ci.yml
generated
vendored
Normal file
11
vendor/gitlab.com/etke.cc/go/validator/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
lint:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
|
||||
unit:
|
||||
image: registry.gitlab.com/etke.cc/base
|
||||
script:
|
||||
- go test -coverprofile=cover.out ./...
|
||||
- go tool cover -func=cover.out
|
||||
- rm -f cover.out
|
||||
166
vendor/gitlab.com/etke.cc/go/validator/LICENSE
generated
vendored
Normal file
166
vendor/gitlab.com/etke.cc/go/validator/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
10
vendor/gitlab.com/etke.cc/go/validator/README.md
generated
vendored
Normal file
10
vendor/gitlab.com/etke.cc/go/validator/README.md
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# validator
|
||||
|
||||
Library that validates different things:
|
||||
|
||||
* A/CNAME/MX lookups
|
||||
* Domain names
|
||||
* Emails
|
||||
* etc
|
||||
|
||||
Check go doc for examples
|
||||
72
vendor/gitlab.com/etke.cc/go/validator/domains.go
generated
vendored
Normal file
72
vendor/gitlab.com/etke.cc/go/validator/domains.go
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
// based on W3C email regex, ref: https://www.w3.org/TR/2016/REC-html51-20161101/sec-forms.html#email-state-typeemail
|
||||
var domainRegex = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$`)
|
||||
var privateSuffix = []string{".etke.host"}
|
||||
|
||||
// Domain checks if domain is valid
|
||||
func (v *V) Domain(domain string) bool {
|
||||
if domain == "" {
|
||||
return !v.enforce.Domain
|
||||
}
|
||||
|
||||
if !v.DomainString(domain) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// DomainString checks if domain string / value is valid using string checks like length and regexp
|
||||
func (v *V) DomainString(domain string) bool {
|
||||
if len(domain) < 4 || len(domain) > 77 {
|
||||
v.log.Info("domain %s invalid, reason: length", domain)
|
||||
return false
|
||||
}
|
||||
|
||||
if !domainRegex.MatchString(domain) {
|
||||
v.log.Info("domain %s invalid, reason: regexp", domain)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// GetBase returns base domain/host of the provided domain
|
||||
func (v *V) GetBase(domain string) string {
|
||||
// domain without subdomain "example.com" has parts: example com
|
||||
minSize := 2
|
||||
if v.hasSuffix(domain) {
|
||||
// domain with a certain TLDs contains 3 parts: example.co.uk -> example co uk
|
||||
minSize = 3
|
||||
}
|
||||
|
||||
parts := strings.Split(domain, ".")
|
||||
size := len(parts)
|
||||
// If domain contains only 2 parts (or less) - consider it without subdomains
|
||||
if size <= minSize {
|
||||
return domain
|
||||
}
|
||||
|
||||
// return domain without subdomain (sub.example.com -> example.com; sub.example.co.uk -> example.co.uk)
|
||||
return strings.Join(parts[size-minSize:], ".")
|
||||
}
|
||||
|
||||
// hasSuffix checks if domain has a suffix from public suffix list or from predefined suffix list
|
||||
func (v *V) hasSuffix(domain string) bool {
|
||||
for _, suffix := range privateSuffix {
|
||||
if strings.HasSuffix(domain, suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
eTLD, _ := publicsuffix.PublicSuffix(domain)
|
||||
return strings.IndexByte(eTLD, '.') >= 0
|
||||
}
|
||||
79
vendor/gitlab.com/etke.cc/go/validator/emails.go
generated
vendored
Normal file
79
vendor/gitlab.com/etke.cc/go/validator/emails.go
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"net/mail"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/etke.cc/go/trysmtp"
|
||||
)
|
||||
|
||||
// Email checks if email is valid
|
||||
func (v *V) Email(email string) bool {
|
||||
// edge case: email may be optional
|
||||
if email == "" {
|
||||
return !v.enforce.Email
|
||||
}
|
||||
|
||||
length := len(email)
|
||||
// email cannot too short and too big
|
||||
if length < 3 || length > 254 {
|
||||
v.log.Info("email %s invalid, reason: length", email)
|
||||
return false
|
||||
}
|
||||
|
||||
_, err := mail.ParseAddress(email)
|
||||
if err != nil {
|
||||
v.log.Info("email %s invalid, reason: %v", email, err)
|
||||
return false
|
||||
}
|
||||
|
||||
emailb := []byte(email)
|
||||
for _, spamregex := range v.spamlist {
|
||||
if spamregex.Match(emailb) {
|
||||
v.log.Info("email %s invalid, reason: spamlist", email)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if v.emailMX(email) {
|
||||
return false
|
||||
}
|
||||
|
||||
smtpCheck := !v.emailSMTP(email)
|
||||
if v.enforce.SMTP {
|
||||
return smtpCheck
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (v *V) emailMX(email string) bool {
|
||||
at := strings.LastIndex(email, "@")
|
||||
domain := email[at+1:]
|
||||
|
||||
nomx := !v.MX(domain)
|
||||
if nomx {
|
||||
v.log.Info("email %s domain %s invalid, reason: no MX", email, domain)
|
||||
if v.enforce.MX {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (v *V) emailSMTP(email string) bool {
|
||||
client, err := trysmtp.Connect(v.from, email)
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "45") {
|
||||
v.log.Info("email %s may be invalid, reason: SMTP check (%v)", email, err)
|
||||
return false
|
||||
}
|
||||
|
||||
v.log.Info("email %s invalid, reason: SMTP check (%v)", email, err)
|
||||
return true
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
return false
|
||||
}
|
||||
45
vendor/gitlab.com/etke.cc/go/validator/lookups.go
generated
vendored
Normal file
45
vendor/gitlab.com/etke.cc/go/validator/lookups.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
package validator
|
||||
|
||||
import "net"
|
||||
|
||||
// A checks if host has at least one A record
|
||||
func (v *V) A(host string) bool {
|
||||
if host == "" {
|
||||
return false
|
||||
}
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
v.log.Error("cannot get A records of %s: %v", host, err)
|
||||
return false
|
||||
}
|
||||
|
||||
return len(ips) > 0
|
||||
}
|
||||
|
||||
// CNAME checks if host has at least one CNAME record
|
||||
func (v *V) CNAME(host string) bool {
|
||||
if host == "" {
|
||||
return false
|
||||
}
|
||||
cname, err := net.LookupCNAME(host)
|
||||
if err != nil {
|
||||
v.log.Error("cannot get CNAME records of %s: %v", host, err)
|
||||
return false
|
||||
}
|
||||
|
||||
return cname != ""
|
||||
}
|
||||
|
||||
// MX checks if host has at least one MX record
|
||||
func (v *V) MX(host string) bool {
|
||||
if host == "" {
|
||||
return false
|
||||
}
|
||||
mxs, err := net.LookupMX(host)
|
||||
if err != nil {
|
||||
v.log.Error("cannot get MX records of %s: %v", host, err)
|
||||
return false
|
||||
}
|
||||
|
||||
return len(mxs) > 0
|
||||
}
|
||||
73
vendor/gitlab.com/etke.cc/go/validator/validator.go
generated
vendored
Normal file
73
vendor/gitlab.com/etke.cc/go/validator/validator.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// V is a validator implementation
|
||||
type V struct {
|
||||
spamlist []*regexp.Regexp
|
||||
enforce Enforce
|
||||
from string
|
||||
log Logger
|
||||
}
|
||||
|
||||
// Enforce checks
|
||||
type Enforce struct {
|
||||
// Email enforces email check and rejects empty emails
|
||||
Email bool
|
||||
// Domain enforces domain check and rejects empty domains
|
||||
Domain bool
|
||||
// SMTP enforces SMTP check (email actually exists on mail server) and rejects non-existing emails
|
||||
SMTP bool
|
||||
// MX enforces MX records check on email's mail server
|
||||
MX bool
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
Info(string, ...interface{})
|
||||
Error(string, ...interface{})
|
||||
}
|
||||
|
||||
// New Validator, accepts spamlist with wildcards
|
||||
func New(spamlist []string, enforce Enforce, smtpFrom string, log Logger) *V {
|
||||
spamregexes, err := parseSpamlist(spamlist)
|
||||
if err != nil {
|
||||
log.Error("cannot parse spamlist: %v", err)
|
||||
}
|
||||
|
||||
return &V{
|
||||
spamlist: spamregexes,
|
||||
enforce: enforce,
|
||||
from: smtpFrom,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
func parseSpamlist(patterns []string) ([]*regexp.Regexp, error) {
|
||||
regexes := []*regexp.Regexp{}
|
||||
for _, pattern := range patterns {
|
||||
rule, err := regexp.Compile("^" + parsePattern(pattern) + "$")
|
||||
if err != nil {
|
||||
return regexes, err
|
||||
}
|
||||
|
||||
regexes = append(regexes, rule)
|
||||
}
|
||||
|
||||
return regexes, nil
|
||||
}
|
||||
|
||||
func parsePattern(pattern string) string {
|
||||
var regexpattern strings.Builder
|
||||
for _, runeItem := range pattern {
|
||||
if runeItem == '*' {
|
||||
regexpattern.WriteString("(.*)")
|
||||
continue
|
||||
}
|
||||
regexpattern.WriteString(regexp.QuoteMeta(string(runeItem)))
|
||||
}
|
||||
|
||||
return regexpattern.String()
|
||||
}
|
||||
94
vendor/gitlab.com/etke.cc/linkpearl/.golangci.yml
generated
vendored
Normal file
94
vendor/gitlab.com/etke.cc/linkpearl/.golangci.yml
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
run:
|
||||
concurrency: 4
|
||||
timeout: 5m
|
||||
issues-exit-code: 1
|
||||
tests: true
|
||||
build-tags: []
|
||||
skip-dirs: []
|
||||
skip-dirs-use-default: true
|
||||
skip-files: []
|
||||
modules-download-mode: readonly
|
||||
allow-parallel-runners: false
|
||||
|
||||
output:
|
||||
format: colored-line-number
|
||||
print-issued-lines: true
|
||||
print-linter-name: true
|
||||
uniq-by-line: true
|
||||
path-prefix: ""
|
||||
sort-results: true
|
||||
|
||||
linters-settings:
|
||||
errcheck:
|
||||
check-blank: true
|
||||
gci:
|
||||
local-prefixes: gitlab.com/etke.cc/linkpearl
|
||||
gocognit:
|
||||
min-complexity: 10
|
||||
nestif:
|
||||
min-complexity: 4
|
||||
gocritic:
|
||||
enabled-tags:
|
||||
- performance
|
||||
gofumpt:
|
||||
lang-version: "1.19"
|
||||
goimports:
|
||||
local-prefixes: gitlab.com/etke.cc/linkpearl
|
||||
gosimple:
|
||||
go: "1.19"
|
||||
checks: [ "all" ]
|
||||
govet:
|
||||
check-shadowing: true
|
||||
enable:
|
||||
- atomicalign
|
||||
- shadow
|
||||
misspell:
|
||||
locale: US
|
||||
staticcheck:
|
||||
go: "1.19"
|
||||
checks: [ "all" ]
|
||||
stylecheck:
|
||||
go: "1.19"
|
||||
unparam:
|
||||
check-exported: true
|
||||
unused:
|
||||
go: "1.19"
|
||||
linters:
|
||||
disable-all: false
|
||||
enable:
|
||||
- megacheck
|
||||
- govet
|
||||
- errcheck
|
||||
- gci
|
||||
- gocognit
|
||||
- nestif
|
||||
- gocritic
|
||||
- gofumpt
|
||||
- goimports
|
||||
- gosimple
|
||||
- govet
|
||||
- misspell
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- unparam
|
||||
- unused
|
||||
fast: false
|
||||
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gocyclo
|
||||
- errcheck
|
||||
- dupl
|
||||
- gosec
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: "SA9003:"
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate "
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
new: false
|
||||
165
vendor/gitlab.com/etke.cc/linkpearl/LICENSE
generated
vendored
Normal file
165
vendor/gitlab.com/etke.cc/linkpearl/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
26
vendor/gitlab.com/etke.cc/linkpearl/Makefile
generated
vendored
Normal file
26
vendor/gitlab.com/etke.cc/linkpearl/Makefile
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# update go dependencies
|
||||
update:
|
||||
go get .
|
||||
go get -u maunium.net/go/mautrix
|
||||
go mod tidy
|
||||
|
||||
mock:
|
||||
-@rm -rf mocks
|
||||
@mockery --all
|
||||
|
||||
# run linter
|
||||
lint:
|
||||
golangci-lint run ./...
|
||||
|
||||
# run linter and fix issues if possible
|
||||
lintfix:
|
||||
golangci-lint run --fix ./...
|
||||
|
||||
vuln:
|
||||
govulncheck ./...
|
||||
|
||||
# run unit tests
|
||||
test:
|
||||
@go test ${BUILDFLAGS} -coverprofile=cover.out ./...
|
||||
@go tool cover -func=cover.out
|
||||
-@rm -f cover.out
|
||||
35
vendor/gitlab.com/etke.cc/linkpearl/README.md
generated
vendored
Normal file
35
vendor/gitlab.com/etke.cc/linkpearl/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# linkpearl [](https://ko-fi.com/etkecc) [](https://goreportcard.com/report/gitlab.com/etke.cc/linkpearl) [](https://pkg.go.dev/gitlab.com/etke.cc/linkpearl)
|
||||
|
||||
> [more about that name](https://ffxiv.gamerescape.com/wiki/Linkpearl)
|
||||
|
||||
A wrapper around [mautrix-go](https://github.com/mautrix/go) with infrastructure/glue code included
|
||||
|
||||
## How to get
|
||||
|
||||
```
|
||||
go get gitlab.com/etke.cc/linkpearl
|
||||
```
|
||||
|
||||
```
|
||||
lp, err := linkpearl.New(&linkpearl.Config{
|
||||
// your options here
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go lp.Start()
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
* Unit tests
|
||||
|
||||
## Features
|
||||
|
||||
* Zero configuration End-to-End encryption
|
||||
* Zero configuration persistent storage
|
||||
* Zero configuration session restores
|
||||
* Zero configuration room and user account data encryption with AES GCM (both keys and values)
|
||||
* Zero configuration room and user account data caching
|
||||
* All wrapped components exported
|
||||
129
vendor/gitlab.com/etke.cc/linkpearl/accountdata.go
generated
vendored
Normal file
129
vendor/gitlab.com/etke.cc/linkpearl/accountdata.go
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// GetAccountData of the user (from cache and API, with encryption support)
|
||||
func (l *Linkpearl) GetAccountData(name string) (map[string]string, error) {
|
||||
cached, ok := l.acc.Get(name)
|
||||
if ok {
|
||||
l.log.Debug("GetAccountData(%s) from cache (data): %+v", name, cached)
|
||||
if cached == nil {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
l.log.Debug("GetAccountData(%s) from API", name)
|
||||
var data map[string]string
|
||||
err := l.GetClient().GetAccountData(name, &data)
|
||||
if err != nil {
|
||||
l.log.Debug("GetAccountData(%s) from API (error): %v", name, err)
|
||||
data = map[string]string{}
|
||||
if strings.Contains(err.Error(), "M_NOT_FOUND") {
|
||||
l.acc.Add(name, data)
|
||||
return data, nil
|
||||
}
|
||||
return data, err
|
||||
}
|
||||
data = l.decryptAccountData(data)
|
||||
l.log.Debug("GetAccountData(%s) from API (data): %+v", name, data)
|
||||
|
||||
l.acc.Add(name, data)
|
||||
return data, err
|
||||
}
|
||||
|
||||
// SetAccountData of the user (to cache and API, with encryption support)
|
||||
func (l *Linkpearl) SetAccountData(name string, data map[string]string) error {
|
||||
l.acc.Add(name, data)
|
||||
|
||||
l.log.Debug("SetAccountData(%s) to API (data): %+v", name, data)
|
||||
data = l.encryptAccountData(data)
|
||||
return l.GetClient().SetAccountData(name, data)
|
||||
}
|
||||
|
||||
// GetRoomAccountData of the room (from cache and API, with encryption support)
|
||||
func (l *Linkpearl) GetRoomAccountData(roomID id.RoomID, name string) (map[string]string, error) {
|
||||
key := roomID.String() + name
|
||||
cached, ok := l.acc.Get(key)
|
||||
if ok {
|
||||
l.log.Debug("GetRoomAccountData(%s, %s) from cache (data): %+v", roomID, name, cached)
|
||||
if cached == nil {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
l.log.Debug("GetRoomAccountData(%s, %s) from API", roomID, name)
|
||||
var data map[string]string
|
||||
err := l.GetClient().GetRoomAccountData(roomID, name, &data)
|
||||
if err != nil {
|
||||
l.log.Debug("GetRoomAccountData(%s, %s) from API (error): %v", roomID, name, err)
|
||||
data = map[string]string{}
|
||||
if strings.Contains(err.Error(), "M_NOT_FOUND") {
|
||||
l.acc.Add(key, data)
|
||||
return data, nil
|
||||
}
|
||||
return data, err
|
||||
}
|
||||
data = l.decryptAccountData(data)
|
||||
l.log.Debug("GetRoomAccountData(%s,%s) from API (data): %+v", roomID, name, data)
|
||||
|
||||
l.acc.Add(key, data)
|
||||
return data, err
|
||||
}
|
||||
|
||||
// SetRoomAccountData of the room (to cache and API, with encryption support)
|
||||
func (l *Linkpearl) SetRoomAccountData(roomID id.RoomID, name string, data map[string]string) error {
|
||||
key := roomID.String() + name
|
||||
l.acc.Add(key, data)
|
||||
|
||||
l.log.Debug("SetRoomAccountData(%s, %s) to API (data): %+v", roomID, name, data)
|
||||
data = l.encryptAccountData(data)
|
||||
return l.GetClient().SetRoomAccountData(roomID, name, data)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) encryptAccountData(data map[string]string) map[string]string {
|
||||
if l.acr == nil {
|
||||
return data
|
||||
}
|
||||
|
||||
encrypted := make(map[string]string, len(data))
|
||||
for k, v := range data {
|
||||
ek, err := l.acr.Encrypt(k)
|
||||
if err != nil {
|
||||
l.log.Error("cannot encrypt account data (key=%s): %v", k, err)
|
||||
}
|
||||
ev, err := l.acr.Encrypt(v)
|
||||
if err != nil {
|
||||
l.log.Error("cannot encrypt account data (key=%s): %v", k, err)
|
||||
}
|
||||
encrypted[ek] = ev // worst case: plaintext value
|
||||
}
|
||||
|
||||
return encrypted
|
||||
}
|
||||
|
||||
func (l *Linkpearl) decryptAccountData(data map[string]string) map[string]string {
|
||||
if l.acr == nil {
|
||||
return data
|
||||
}
|
||||
|
||||
decrypted := make(map[string]string, len(data))
|
||||
for ek, ev := range data {
|
||||
k, err := l.acr.Decrypt(ek)
|
||||
if err != nil {
|
||||
l.log.Error("cannot decrypt account data (key=%s): %v", k, err)
|
||||
}
|
||||
v, err := l.acr.Decrypt(ev)
|
||||
if err != nil {
|
||||
l.log.Error("cannot decrypt account data (key=%s): %v", k, err)
|
||||
}
|
||||
decrypted[k] = v // worst case: encrypted value, usual case: migration from plaintext to encrypted account data
|
||||
}
|
||||
|
||||
return decrypted
|
||||
}
|
||||
74
vendor/gitlab.com/etke.cc/linkpearl/auth.go
generated
vendored
Normal file
74
vendor/gitlab.com/etke.cc/linkpearl/auth.go
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func (l *Linkpearl) login(username string, password string) error {
|
||||
if err := l.restoreSession(); err == nil {
|
||||
l.log.Debug("session restored successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
l.log.Debug("auth using login and password...")
|
||||
_, err := l.api.Login(&mautrix.ReqLogin{
|
||||
Type: "m.login.password",
|
||||
Identifier: mautrix.UserIdentifier{
|
||||
Type: mautrix.IdentifierTypeUser,
|
||||
User: username,
|
||||
},
|
||||
Password: password,
|
||||
StoreCredentials: true,
|
||||
})
|
||||
if err != nil {
|
||||
l.log.Error("cannot authorize using login and password: %v", err)
|
||||
return err
|
||||
}
|
||||
l.store.SaveSession(l.api.UserID, l.api.DeviceID, l.api.AccessToken)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// restoreSession tries to load previous active session token from db (if any)
|
||||
func (l *Linkpearl) restoreSession() error {
|
||||
l.log.Debug("restoring previous session...")
|
||||
|
||||
userID, deviceID, token := l.store.LoadSession()
|
||||
if userID == "" || deviceID == "" || token == "" {
|
||||
return errors.New("cannot restore session from db")
|
||||
}
|
||||
if !l.validateSession(userID, deviceID, token) {
|
||||
return errors.New("restored session is invalid")
|
||||
}
|
||||
|
||||
l.api.AccessToken = token
|
||||
l.api.UserID = userID
|
||||
l.api.DeviceID = deviceID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Linkpearl) validateSession(userID id.UserID, deviceID id.DeviceID, token string) bool {
|
||||
valid := true
|
||||
// preserve current values
|
||||
currentToken := l.api.AccessToken
|
||||
currentUserID := l.api.UserID
|
||||
currentDeviceID := l.api.DeviceID
|
||||
// set new values
|
||||
l.api.AccessToken = token
|
||||
l.api.UserID = userID
|
||||
l.api.DeviceID = deviceID
|
||||
|
||||
if _, err := l.api.GetOwnPresence(); err != nil {
|
||||
l.log.Debug("previous session token was not found or invalid: %v", err)
|
||||
valid = false
|
||||
}
|
||||
|
||||
// restore original values
|
||||
l.api.AccessToken = currentToken
|
||||
l.api.UserID = currentUserID
|
||||
l.api.DeviceID = currentDeviceID
|
||||
return valid
|
||||
}
|
||||
62
vendor/gitlab.com/etke.cc/linkpearl/config/config.go
generated
vendored
Normal file
62
vendor/gitlab.com/etke.cc/linkpearl/config/config.go
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
// Package config was added to store cross-package structs and interfaces.
|
||||
package config
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/event"
|
||||
)
|
||||
|
||||
// Config represents matrix config
|
||||
type Config struct {
|
||||
// Homeserver url
|
||||
Homeserver string
|
||||
// Login is a localpart (honoroit - OK, @honoroit:example.com - wrong)
|
||||
Login string
|
||||
// Password for login/password auth only
|
||||
Password string
|
||||
|
||||
// JoinPermit is a callback function that tells
|
||||
// if linkpearl should respond to the given "invite" event
|
||||
// and join the room
|
||||
JoinPermit func(*event.Event) bool
|
||||
|
||||
// AutoLeave if true, linkpearl will automatically leave empty rooms
|
||||
AutoLeave bool
|
||||
|
||||
// AccountDataCache size
|
||||
AccountDataCache int
|
||||
|
||||
// AccountDataSecret (Password) for encryption
|
||||
AccountDataSecret string
|
||||
|
||||
// MaxRetries for operations like auto join
|
||||
MaxRetries int
|
||||
|
||||
// NoEncryption disabled encryption support
|
||||
NoEncryption bool
|
||||
|
||||
// LPLogger used for linkpearl's glue code
|
||||
LPLogger Logger
|
||||
// APILogger used for matrix CS API calls
|
||||
APILogger Logger
|
||||
// StoreLogger used for persistent store
|
||||
StoreLogger Logger
|
||||
// CryptoLogger used for OLM machine
|
||||
CryptoLogger Logger
|
||||
|
||||
// DB object
|
||||
DB *sql.DB
|
||||
// Dialect of the DB: postgres, sqlite3
|
||||
Dialect string
|
||||
}
|
||||
|
||||
// Logger implementation of crypto.Logger and mautrix.Logger
|
||||
type Logger interface {
|
||||
crypto.Logger
|
||||
mautrix.WarnLogger
|
||||
|
||||
Info(message string, args ...interface{})
|
||||
}
|
||||
73
vendor/gitlab.com/etke.cc/linkpearl/crypter.go
generated
vendored
Normal file
73
vendor/gitlab.com/etke.cc/linkpearl/crypter.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Crypter is special object that handles data encryption and decryption
|
||||
// apart from Matrix' standard encryption.
|
||||
// It can encrypt and decrypt arbitrary data using secret key (password)
|
||||
type Crypter struct {
|
||||
cipher cipher.AEAD
|
||||
nonceSize int
|
||||
}
|
||||
|
||||
// ErrInvalidData returned in provided encrypted data (ciphertext) is invalid
|
||||
var ErrInvalidData = errors.New("invalid data")
|
||||
|
||||
// NewCrypter creates new Crypter
|
||||
func NewCrypter(secretkey string) (*Crypter, error) {
|
||||
block, err := aes.NewCipher([]byte(secretkey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
aesGCM, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Crypter{
|
||||
cipher: aesGCM,
|
||||
nonceSize: aesGCM.NonceSize(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Decrypt data
|
||||
func (c *Crypter) Decrypt(data string) (string, error) {
|
||||
datab, err := base64.StdEncoding.DecodeString(data)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
if len(datab) < c.nonceSize {
|
||||
return data, ErrInvalidData
|
||||
}
|
||||
|
||||
nonce := datab[:c.nonceSize]
|
||||
ciphertext := datab[c.nonceSize:]
|
||||
|
||||
plaintext, err := c.cipher.Open(nil, nonce, ciphertext, nil)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
return string(plaintext), nil
|
||||
}
|
||||
|
||||
// Encrypt data
|
||||
func (c *Crypter) Encrypt(data string) (string, error) {
|
||||
nonce := make([]byte, c.nonceSize)
|
||||
_, err := io.ReadFull(rand.Reader, nonce)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
encrypted := c.cipher.Seal(nonce, nonce, []byte(data), nil)
|
||||
return base64.StdEncoding.EncodeToString(encrypted), nil
|
||||
}
|
||||
180
vendor/gitlab.com/etke.cc/linkpearl/linkpearl.go
generated
vendored
Normal file
180
vendor/gitlab.com/etke.cc/linkpearl/linkpearl.go
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
// Package linkpearl represents the library itself
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru/v2"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/event"
|
||||
|
||||
"gitlab.com/etke.cc/linkpearl/config"
|
||||
"gitlab.com/etke.cc/linkpearl/store"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultMaxRetries for operations like autojoin
|
||||
DefaultMaxRetries = 10
|
||||
// DefaultAccountDataCache size
|
||||
DefaultAccountDataCache = 1000
|
||||
)
|
||||
|
||||
// Linkpearl object
|
||||
type Linkpearl struct {
|
||||
db *sql.DB
|
||||
acc *lru.Cache[string, map[string]string]
|
||||
acr *Crypter
|
||||
log config.Logger
|
||||
api *mautrix.Client
|
||||
olm *crypto.OlmMachine
|
||||
store *store.Store
|
||||
|
||||
joinPermit func(*event.Event) bool
|
||||
autoleave bool
|
||||
maxretries int
|
||||
}
|
||||
|
||||
type ReqPresence struct {
|
||||
Presence event.Presence `json:"presence"`
|
||||
StatusMsg string `json:"status_msg,omitempty"`
|
||||
}
|
||||
|
||||
func setDefaults(cfg *config.Config) {
|
||||
if cfg.MaxRetries == 0 {
|
||||
cfg.MaxRetries = DefaultMaxRetries
|
||||
}
|
||||
if cfg.AccountDataCache == 0 {
|
||||
cfg.AccountDataCache = DefaultAccountDataCache
|
||||
}
|
||||
if cfg.JoinPermit == nil {
|
||||
// By default, we approve all join requests
|
||||
cfg.JoinPermit = func(*event.Event) bool { return true }
|
||||
}
|
||||
}
|
||||
|
||||
func initCrypter(secret string) (*Crypter, error) {
|
||||
if secret == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return NewCrypter(secret)
|
||||
}
|
||||
|
||||
// New linkpearl
|
||||
func New(cfg *config.Config) (*Linkpearl, error) {
|
||||
setDefaults(cfg)
|
||||
api, err := mautrix.NewClient(cfg.Homeserver, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
api.Logger = cfg.APILogger
|
||||
|
||||
acc, _ := lru.New[string, map[string]string](cfg.AccountDataCache) //nolint:errcheck // addressed in setDefaults()
|
||||
acr, err := initCrypter(cfg.AccountDataSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lp := &Linkpearl{
|
||||
db: cfg.DB,
|
||||
acc: acc,
|
||||
acr: acr,
|
||||
api: api,
|
||||
log: cfg.LPLogger,
|
||||
joinPermit: cfg.JoinPermit,
|
||||
autoleave: cfg.AutoLeave,
|
||||
maxretries: cfg.MaxRetries,
|
||||
}
|
||||
|
||||
storer := store.New(cfg.DB, cfg.Dialect, cfg.StoreLogger)
|
||||
if err = storer.CreateTables(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lp.store = storer
|
||||
lp.api.Store = storer
|
||||
|
||||
if err = lp.login(cfg.Login, cfg.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !cfg.NoEncryption {
|
||||
if err = lp.store.WithCrypto(lp.api.UserID, lp.api.DeviceID, cfg.StoreLogger); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lp.olm = crypto.NewOlmMachine(lp.api, cfg.CryptoLogger, lp.store, lp.store)
|
||||
if err = lp.olm.Load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return lp, nil
|
||||
}
|
||||
|
||||
// GetClient returns underlying API client
|
||||
func (l *Linkpearl) GetClient() *mautrix.Client {
|
||||
return l.api
|
||||
}
|
||||
|
||||
// GetDB returns underlying DB object
|
||||
func (l *Linkpearl) GetDB() *sql.DB {
|
||||
return l.db
|
||||
}
|
||||
|
||||
// GetStore returns underlying persistent store object, compatible with crypto.Store, crypto.StateStore and mautrix.Storer
|
||||
func (l *Linkpearl) GetStore() *store.Store {
|
||||
return l.store
|
||||
}
|
||||
|
||||
// GetMachine returns underlying OLM machine
|
||||
func (l *Linkpearl) GetMachine() *crypto.OlmMachine {
|
||||
return l.olm
|
||||
}
|
||||
|
||||
// GetAccountDataCrypter returns crypter used for account data (if any)
|
||||
func (l *Linkpearl) GetAccountDataCrypter() *Crypter {
|
||||
return l.acr
|
||||
}
|
||||
|
||||
// SetPresence (own). See https://spec.matrix.org/v1.3/client-server-api/#put_matrixclientv3presenceuseridstatus
|
||||
func (l *Linkpearl) SetPresence(presence event.Presence, message string) error {
|
||||
req := ReqPresence{Presence: presence, StatusMsg: message}
|
||||
u := l.GetClient().BuildClientURL("v3", "presence", l.GetClient().UserID, "status")
|
||||
_, err := l.GetClient().MakeRequest("PUT", u, req, nil)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SetJoinPermit sets the the join permit callback function
|
||||
func (l *Linkpearl) SetJoinPermit(value func(*event.Event) bool) {
|
||||
l.joinPermit = value
|
||||
}
|
||||
|
||||
// Start performs matrix /sync
|
||||
func (l *Linkpearl) Start(optionalStatusMsg ...string) error {
|
||||
l.initSync()
|
||||
var statusMsg string
|
||||
if len(optionalStatusMsg) > 0 {
|
||||
statusMsg = optionalStatusMsg[0]
|
||||
}
|
||||
|
||||
err := l.SetPresence(event.PresenceOnline, statusMsg)
|
||||
if err != nil {
|
||||
l.log.Error("cannot set presence: %v", err)
|
||||
}
|
||||
defer l.Stop()
|
||||
|
||||
l.log.Info("client has been started")
|
||||
return l.api.Sync()
|
||||
}
|
||||
|
||||
// Stop the client
|
||||
func (l *Linkpearl) Stop() {
|
||||
l.log.Debug("stopping the client")
|
||||
err := l.api.SetPresence(event.PresenceOffline)
|
||||
if err != nil {
|
||||
l.log.Error("cannot set presence: %v", err)
|
||||
}
|
||||
l.api.StopSync()
|
||||
l.log.Info("client has been stopped")
|
||||
}
|
||||
82
vendor/gitlab.com/etke.cc/linkpearl/send.go
generated
vendored
Normal file
82
vendor/gitlab.com/etke.cc/linkpearl/send.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// Send a message to the roomID and automatically try to encrypt it, if the destination room is encrypted
|
||||
func (l *Linkpearl) Send(roomID id.RoomID, content interface{}) (id.EventID, error) {
|
||||
if !l.store.IsEncrypted(roomID) {
|
||||
l.log.Debug("room %s is not encrypted", roomID)
|
||||
return l.SendPlaintext(roomID, content)
|
||||
}
|
||||
l.log.Debug("room %s is encrypted", roomID)
|
||||
|
||||
encrypted, err := l.EncryptEvent(roomID, content)
|
||||
if err != nil {
|
||||
l.log.Error("cannot encrypt message: %v, sending plaintext...", roomID, err)
|
||||
return l.SendPlaintext(roomID, content)
|
||||
}
|
||||
|
||||
return l.SendEncrypted(roomID, encrypted)
|
||||
}
|
||||
|
||||
// SendFile to a matrix room
|
||||
func (l *Linkpearl) SendFile(roomID id.RoomID, req *mautrix.ReqUploadMedia, msgtype event.MessageType, relation *event.RelatesTo) error {
|
||||
resp, err := l.GetClient().UploadMedia(*req)
|
||||
if err != nil {
|
||||
l.log.Error("cannot upload file %s: %v", req.FileName, err)
|
||||
return err
|
||||
}
|
||||
_, err = l.Send(roomID, &event.Content{
|
||||
Parsed: &event.MessageEventContent{
|
||||
MsgType: msgtype,
|
||||
Body: req.FileName,
|
||||
URL: resp.ContentURI.CUString(),
|
||||
RelatesTo: relation,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
l.log.Error("cannot send uploaded file: %s: %v", req.FileName, err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SendPlaintext sends plaintext event only
|
||||
func (l *Linkpearl) SendPlaintext(roomID id.RoomID, content interface{}) (id.EventID, error) {
|
||||
l.log.Debug("sending plaintext event to %s: %+v", roomID, content)
|
||||
resp, err := l.api.SendMessageEvent(roomID, event.EventMessage, content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.EventID, nil
|
||||
}
|
||||
|
||||
// SendEncrypted sends encrypted event only
|
||||
func (l *Linkpearl) SendEncrypted(roomID id.RoomID, content interface{}) (id.EventID, error) {
|
||||
l.log.Debug("sending encrypted event to %s: %+v", roomID, content)
|
||||
resp, err := l.api.SendMessageEvent(roomID, event.EventEncrypted, content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.EventID, nil
|
||||
}
|
||||
|
||||
// EncryptEvent before sending
|
||||
func (l *Linkpearl) EncryptEvent(roomID id.RoomID, content interface{}) (*event.EncryptedEventContent, error) {
|
||||
l.log.Debug("encrypting event %+v", content)
|
||||
encrypted, err := l.olm.EncryptMegolmEvent(roomID, event.EventMessage, content)
|
||||
if crypto.IsShareError(err) {
|
||||
err = l.olm.ShareGroupSession(roomID, l.store.GetRoomMembers(roomID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encrypted, err = l.olm.EncryptMegolmEvent(roomID, event.EventMessage, content)
|
||||
}
|
||||
|
||||
return encrypted, err
|
||||
}
|
||||
214
vendor/gitlab.com/etke.cc/linkpearl/store/crypto.go
generated
vendored
Normal file
214
vendor/gitlab.com/etke.cc/linkpearl/store/crypto.go
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// NOTE: functions in that file are for crypto.Store implementation
|
||||
// ref: https://pkg.go.dev/maunium.net/go/mautrix/crypto#Store
|
||||
|
||||
// Flush does nothing for this implementation as data is already persisted in the database.
|
||||
// nolint // interface cannot be changed
|
||||
func (s *Store) Flush() error {
|
||||
s.log.Debug("flushing crypto store")
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutNextBatch stores the next sync batch token for the current account.
|
||||
func (s *Store) PutNextBatch(nextBatch string) error {
|
||||
s.log.Debug("storing next batch token")
|
||||
return s.s.PutNextBatch(nextBatch)
|
||||
}
|
||||
|
||||
// GetNextBatch retrieves the next sync batch token for the current account.
|
||||
func (s *Store) GetNextBatch() (string, error) {
|
||||
s.log.Debug("loading next batch token")
|
||||
return s.s.GetNextBatch()
|
||||
}
|
||||
|
||||
// PutAccount stores an OlmAccount in the database.
|
||||
func (s *Store) PutAccount(account *crypto.OlmAccount) error {
|
||||
s.log.Debug("storing olm account")
|
||||
return s.s.PutAccount(account)
|
||||
}
|
||||
|
||||
// GetAccount retrieves an OlmAccount from the database.
|
||||
func (s *Store) GetAccount() (*crypto.OlmAccount, error) {
|
||||
s.log.Debug("loading olm account")
|
||||
return s.s.GetAccount()
|
||||
}
|
||||
|
||||
// HasSession returns whether there is an Olm session for the given sender key.
|
||||
func (s *Store) HasSession(key id.SenderKey) bool {
|
||||
s.log.Debug("check if olm session exists for the key %s", key)
|
||||
return s.s.HasSession(key)
|
||||
}
|
||||
|
||||
// GetSessions returns all the known Olm sessions for a sender key.
|
||||
func (s *Store) GetSessions(key id.SenderKey) (crypto.OlmSessionList, error) {
|
||||
s.log.Debug("loading olm session for the key %s", key)
|
||||
return s.s.GetSessions(key)
|
||||
}
|
||||
|
||||
// GetLatestSession retrieves the Olm session for a given sender key from the database that has the largest ID.
|
||||
func (s *Store) GetLatestSession(key id.SenderKey) (*crypto.OlmSession, error) {
|
||||
s.log.Debug("loading latest session for the key %s", key)
|
||||
return s.s.GetLatestSession(key)
|
||||
}
|
||||
|
||||
// AddSession persists an Olm session for a sender in the database.
|
||||
func (s *Store) AddSession(key id.SenderKey, session *crypto.OlmSession) error {
|
||||
s.log.Debug("adding new olm session for the key %s", key)
|
||||
return s.s.AddSession(key, session)
|
||||
}
|
||||
|
||||
// UpdateSession replaces the Olm session for a sender in the database.
|
||||
func (s *Store) UpdateSession(key id.SenderKey, session *crypto.OlmSession) error {
|
||||
s.log.Debug("update olm session for the key %s", key)
|
||||
return s.s.UpdateSession(key, session)
|
||||
}
|
||||
|
||||
// PutGroupSession stores an inbound Megolm group session for a room, sender and session.
|
||||
func (s *Store) PutGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, session *crypto.InboundGroupSession) error {
|
||||
s.log.Debug("storing inbound group session for the room %s", roomID)
|
||||
return s.s.PutGroupSession(roomID, senderKey, sessionID, session)
|
||||
}
|
||||
|
||||
// GetGroupSession retrieves an inbound Megolm group session for a room, sender and session.
|
||||
func (s *Store) GetGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*crypto.InboundGroupSession, error) {
|
||||
s.log.Debug("loading inbound group session for the room %s", roomID)
|
||||
return s.s.GetGroupSession(roomID, senderKey, sessionID)
|
||||
}
|
||||
|
||||
// PutWithheldGroupSession tells the store that a specific Megolm session was withheld.
|
||||
// nolint // method is part of interface and cannot be changed
|
||||
func (s *Store) PutWithheldGroupSession(content event.RoomKeyWithheldEventContent) error {
|
||||
s.log.Debug("storing withheld group session")
|
||||
return s.s.PutWithheldGroupSession(content)
|
||||
}
|
||||
|
||||
// GetWithheldGroupSession gets the event content that was previously inserted with PutWithheldGroupSession.
|
||||
func (s *Store) GetWithheldGroupSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID) (*event.RoomKeyWithheldEventContent, error) {
|
||||
s.log.Debug("loading withheld group session")
|
||||
return s.s.GetWithheldGroupSession(roomID, senderKey, sessionID)
|
||||
}
|
||||
|
||||
// GetGroupSessionsForRoom gets all the inbound Megolm sessions for a specific room. This is used for creating key
|
||||
// export files. Unlike GetGroupSession, this should not return any errors about withheld keys.
|
||||
func (s *Store) GetGroupSessionsForRoom(roomID id.RoomID) ([]*crypto.InboundGroupSession, error) {
|
||||
s.log.Debug("loading group session for the room %s", roomID)
|
||||
return s.s.GetGroupSessionsForRoom(roomID)
|
||||
}
|
||||
|
||||
// GetAllGroupSessions gets all the inbound Megolm sessions in the store. This is used for creating key export
|
||||
// files. Unlike GetGroupSession, this should not return any errors about withheld keys.
|
||||
func (s *Store) GetAllGroupSessions() ([]*crypto.InboundGroupSession, error) {
|
||||
s.log.Debug("loading all group sessions")
|
||||
return s.s.GetAllGroupSessions()
|
||||
}
|
||||
|
||||
// AddOutboundGroupSession stores an outbound Megolm session, along with the information about the room and involved devices.
|
||||
func (s *Store) AddOutboundGroupSession(session *crypto.OutboundGroupSession) (err error) {
|
||||
s.log.Debug("storing outbound group session")
|
||||
return s.s.AddOutboundGroupSession(session)
|
||||
}
|
||||
|
||||
// UpdateOutboundGroupSession replaces an outbound Megolm session with for same room and session ID.
|
||||
func (s *Store) UpdateOutboundGroupSession(session *crypto.OutboundGroupSession) error {
|
||||
s.log.Debug("updating outbound group session")
|
||||
return s.s.UpdateOutboundGroupSession(session)
|
||||
}
|
||||
|
||||
// GetOutboundGroupSession retrieves the outbound Megolm session for the given room ID.
|
||||
func (s *Store) GetOutboundGroupSession(roomID id.RoomID) (*crypto.OutboundGroupSession, error) {
|
||||
s.log.Debug("loading outbound group session")
|
||||
return s.s.GetOutboundGroupSession(roomID)
|
||||
}
|
||||
|
||||
// RemoveOutboundGroupSession removes the outbound Megolm session for the given room ID.
|
||||
func (s *Store) RemoveOutboundGroupSession(roomID id.RoomID) error {
|
||||
s.log.Debug("removing outbound group session")
|
||||
return s.s.RemoveOutboundGroupSession(roomID)
|
||||
}
|
||||
|
||||
// ValidateMessageIndex returns whether the given event information match the ones stored in the database
|
||||
// for the given sender key, session ID and index.
|
||||
// If the event information was not yet stored, it's stored now.
|
||||
func (s *Store) ValidateMessageIndex(senderKey id.SenderKey, sessionID id.SessionID, eventID id.EventID, index uint, timestamp int64) (bool, error) {
|
||||
s.log.Debug("validating message index")
|
||||
return s.s.ValidateMessageIndex(senderKey, sessionID, eventID, index, timestamp)
|
||||
}
|
||||
|
||||
// GetDevices returns a map of device IDs to device identities, including the identity and signing keys, for a given user ID.
|
||||
func (s *Store) GetDevices(userID id.UserID) (map[id.DeviceID]*id.Device, error) {
|
||||
s.log.Debug("loading devices of the %s", userID)
|
||||
return s.s.GetDevices(userID)
|
||||
}
|
||||
|
||||
// GetDevice returns the device dentity for a given user and device ID.
|
||||
func (s *Store) GetDevice(userID id.UserID, deviceID id.DeviceID) (*id.Device, error) {
|
||||
s.log.Debug("loading device %s for the %s", deviceID, userID)
|
||||
return s.s.GetDevice(userID, deviceID)
|
||||
}
|
||||
|
||||
// FindDeviceByKey finds a specific device by its sender key.
|
||||
func (s *Store) FindDeviceByKey(userID id.UserID, identityKey id.IdentityKey) (*id.Device, error) {
|
||||
s.log.Debug("loading device of the %s by the key %s", userID, identityKey)
|
||||
return s.s.FindDeviceByKey(userID, identityKey)
|
||||
}
|
||||
|
||||
// PutDevice stores a single device for a user, replacing it if it exists already.
|
||||
func (s *Store) PutDevice(userID id.UserID, device *id.Device) error {
|
||||
s.log.Debug("storing device of the %s", userID)
|
||||
return s.s.PutDevice(userID, device)
|
||||
}
|
||||
|
||||
// PutDevices stores the device identity information for the given user ID.
|
||||
func (s *Store) PutDevices(userID id.UserID, devices map[id.DeviceID]*id.Device) error {
|
||||
s.log.Debug("storing devices of the %s", userID)
|
||||
return s.s.PutDevices(userID, devices)
|
||||
}
|
||||
|
||||
// FilterTrackedUsers finds all of the user IDs out of the given ones for which the database contains identity information.
|
||||
func (s *Store) FilterTrackedUsers(users []id.UserID) ([]id.UserID, error) {
|
||||
s.log.Debug("filtering tracked users")
|
||||
return s.s.FilterTrackedUsers(users)
|
||||
}
|
||||
|
||||
// PutCrossSigningKey stores a cross-signing key of some user along with its usage.
|
||||
func (s *Store) PutCrossSigningKey(userID id.UserID, usage id.CrossSigningUsage, key id.Ed25519) error {
|
||||
s.log.Debug("storing crosssigning key of the %s", userID)
|
||||
return s.s.PutCrossSigningKey(userID, usage, key)
|
||||
}
|
||||
|
||||
// GetCrossSigningKeys retrieves a user's stored cross-signing keys.
|
||||
func (s *Store) GetCrossSigningKeys(userID id.UserID) (map[id.CrossSigningUsage]id.CrossSigningKey, error) {
|
||||
s.log.Debug("loading crosssigning keys of the %s", userID)
|
||||
return s.s.GetCrossSigningKeys(userID)
|
||||
}
|
||||
|
||||
// PutSignature stores a signature of a cross-signing or device key along with the signer's user ID and key.
|
||||
func (s *Store) PutSignature(signedUserID id.UserID, signedKey id.Ed25519, signerUserID id.UserID, signerKey id.Ed25519, signature string) error {
|
||||
s.log.Debug("storing signature")
|
||||
return s.s.PutSignature(signedUserID, signedKey, signerUserID, signerKey, signature)
|
||||
}
|
||||
|
||||
// GetSignaturesForKeyBy retrieves the stored signatures for a given cross-signing or device key, by the given signer.
|
||||
func (s *Store) GetSignaturesForKeyBy(userID id.UserID, key id.Ed25519, signerID id.UserID) (map[id.Ed25519]string, error) {
|
||||
s.log.Debug("loading signatures")
|
||||
return s.s.GetSignaturesForKeyBy(userID, key, signerID)
|
||||
}
|
||||
|
||||
// IsKeySignedBy returns whether a cross-signing or device key is signed by the given signer.
|
||||
func (s *Store) IsKeySignedBy(userID id.UserID, key id.Ed25519, signerID id.UserID, signerKey id.Ed25519) (bool, error) {
|
||||
s.log.Debug("checking if key is signed by")
|
||||
return s.s.IsKeySignedBy(userID, key, signerID, signerKey)
|
||||
}
|
||||
|
||||
// DropSignaturesByKey deletes the signatures made by the given user and key from the store. It returns the number of signatures deleted.
|
||||
func (s *Store) DropSignaturesByKey(userID id.UserID, key id.Ed25519) (int64, error) {
|
||||
s.log.Debug("removing signatures by the %s/%s", userID, key)
|
||||
return s.s.DropSignaturesByKey(userID, key)
|
||||
}
|
||||
209
vendor/gitlab.com/etke.cc/linkpearl/store/linkpearl.go
generated
vendored
Normal file
209
vendor/gitlab.com/etke.cc/linkpearl/store/linkpearl.go
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
var acceptedMembershipTypes = []event.Membership{
|
||||
event.MembershipJoin,
|
||||
event.MembershipInvite,
|
||||
event.MembershipBan,
|
||||
event.MembershipLeave,
|
||||
}
|
||||
|
||||
// IsEncrypted returns whether a room is encrypted.
|
||||
func (s *Store) IsEncrypted(roomID id.RoomID) bool {
|
||||
if !s.encryption {
|
||||
return false
|
||||
}
|
||||
|
||||
s.log.Debug("checking if room %s is encrypted", roomID)
|
||||
return s.GetEncryptionEvent(roomID) != nil
|
||||
}
|
||||
|
||||
// SetEncryptionEvent creates or updates room's encryption event info
|
||||
func (s *Store) SetEncryptionEvent(evt *event.Event) {
|
||||
if !s.encryption {
|
||||
return
|
||||
}
|
||||
if evt == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var encryptionEventJSON []byte
|
||||
encryptionEventJSON, err := json.Marshal(evt)
|
||||
if err != nil {
|
||||
s.log.Debug("cannot marshal encryption event: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Error("cannot begin transaction: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var insert string
|
||||
switch s.dialect {
|
||||
case "sqlite3":
|
||||
insert = "INSERT OR IGNORE INTO rooms VALUES (?, ?)"
|
||||
case "postgres":
|
||||
insert = "INSERT INTO rooms VALUES ($1, $2) ON CONFLICT DO NOTHING"
|
||||
}
|
||||
update := "UPDATE rooms SET encryption_event = $1 WHERE room_id = $2"
|
||||
|
||||
_, err = tx.Exec(update, encryptionEventJSON, evt.RoomID)
|
||||
if err != nil {
|
||||
s.log.Error("cannot update encryption event: %v", err)
|
||||
// nolint // we already have err to return
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
_, err = tx.Exec(insert, evt.RoomID, encryptionEventJSON)
|
||||
if err != nil {
|
||||
s.log.Error("cannot insert encryption event: %v", err)
|
||||
// nolint // interface doesn't allow to return error
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
s.log.Error("cannot commit transaction: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// SetMembership saves room members
|
||||
func (s *Store) SetMembership(evt *event.Event) {
|
||||
s.log.Debug("saving membership event for %s", evt.RoomID)
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Error("cannot begin transaction: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var insert string
|
||||
switch s.dialect {
|
||||
case "sqlite3":
|
||||
insert = "INSERT OR IGNORE INTO room_members VALUES (?, ?)"
|
||||
case "postgres":
|
||||
insert = "INSERT INTO room_members VALUES ($1, $2) ON CONFLICT DO NOTHING"
|
||||
}
|
||||
del := "DELETE FROM room_members WHERE room_id = $1 AND user_id = $2"
|
||||
|
||||
membership := evt.Content.AsMember().Membership
|
||||
if s.shouldIgnoreMembership(membership) {
|
||||
return
|
||||
}
|
||||
if membership.IsInviteOrJoin() {
|
||||
_, err := tx.Exec(insert, evt.RoomID, evt.GetStateKey())
|
||||
if err != nil {
|
||||
s.log.Error("cannot insert membership event: %v", err)
|
||||
// nolint // interface doesn't allow to return error
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, err := tx.Exec(del, evt.RoomID, evt.GetStateKey())
|
||||
if err != nil {
|
||||
s.log.Error("cannot delete membership event: %v", err)
|
||||
// nolint // interface doesn't allow to return error
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
commitErr := tx.Commit()
|
||||
if commitErr != nil {
|
||||
s.log.Error("cannot commit transaction: %v", commitErr)
|
||||
// nolint // interface doesn't allow to return error
|
||||
tx.Rollback()
|
||||
}
|
||||
}
|
||||
|
||||
// GetRoomMembers ...
|
||||
func (s *Store) GetRoomMembers(roomID id.RoomID) []id.UserID {
|
||||
s.log.Debug("loading room members of %s", roomID)
|
||||
query := "SELECT user_id FROM room_members WHERE room_id = $1"
|
||||
rows, err := s.db.Query(query, roomID)
|
||||
users := make([]id.UserID, 0)
|
||||
if err != nil {
|
||||
s.log.Error("cannot load room members: %v", err)
|
||||
return users
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var userID id.UserID
|
||||
for rows.Next() {
|
||||
if err := rows.Scan(&userID); err == nil {
|
||||
users = append(users, userID)
|
||||
}
|
||||
}
|
||||
return users
|
||||
}
|
||||
|
||||
// SaveSession to DB
|
||||
func (s *Store) SaveSession(userID id.UserID, deviceID id.DeviceID, accessToken string) {
|
||||
s.log.Debug("saving session credentials of %s/%s", userID, deviceID)
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Error("cannot begin transaction: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var insert string
|
||||
switch s.dialect {
|
||||
case "sqlite3":
|
||||
insert = "INSERT OR IGNORE INTO session VALUES (?, ?, ?)"
|
||||
case "postgres":
|
||||
insert = "INSERT INTO session VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||
}
|
||||
update := "UPDATE session SET access_token = $1, device_id = $2 WHERE user_id = $3"
|
||||
|
||||
if _, err = tx.Exec(update, accessToken, deviceID, userID); err != nil {
|
||||
s.log.Error("cannot update session credentials: %v", err)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = tx.Exec(insert, userID, deviceID, accessToken); err != nil {
|
||||
s.log.Error("cannot insert session credentials: %v", err)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
s.log.Error("cannot commit transaction: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadSession from DB (user ID, device ID, access token)
|
||||
func (s *Store) LoadSession() (id.UserID, id.DeviceID, string) {
|
||||
s.log.Debug("loading session credentials...")
|
||||
row := s.db.QueryRow("SELECT * FROM session LIMIT 1")
|
||||
var userID id.UserID
|
||||
var deviceID id.DeviceID
|
||||
var accessToken string
|
||||
if err := row.Scan(&userID, &deviceID, &accessToken); err != nil {
|
||||
s.log.Error("cannot load session credentials: %v", err)
|
||||
return "", "", ""
|
||||
}
|
||||
return userID, deviceID, accessToken
|
||||
}
|
||||
|
||||
func (s *Store) shouldIgnoreMembership(membership event.Membership) bool {
|
||||
for _, mtype := range acceptedMembershipTypes {
|
||||
if membership == mtype {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
66
vendor/gitlab.com/etke.cc/linkpearl/store/migrations.go
generated
vendored
Normal file
66
vendor/gitlab.com/etke.cc/linkpearl/store/migrations.go
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
package store
|
||||
|
||||
var migrations = []string{
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS user_filter_ids (
|
||||
user_id VARCHAR(255) PRIMARY KEY,
|
||||
filter_id VARCHAR(255)
|
||||
)
|
||||
`,
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS user_batch_tokens (
|
||||
user_id VARCHAR(255) PRIMARY KEY,
|
||||
next_batch_token VARCHAR(255)
|
||||
)
|
||||
`,
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS rooms (
|
||||
room_id VARCHAR(255) PRIMARY KEY,
|
||||
encryption_event VARCHAR(65535) NULL
|
||||
)
|
||||
`,
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS room_members (
|
||||
room_id VARCHAR(255),
|
||||
user_id VARCHAR(255),
|
||||
PRIMARY KEY (room_id, user_id)
|
||||
)
|
||||
`,
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS session (
|
||||
user_id VARCHAR(255),
|
||||
device_id VARCHAR(255),
|
||||
access_token VARCHAR(255)
|
||||
)
|
||||
`,
|
||||
}
|
||||
|
||||
// CreateTables applies all the pending database migrations.
|
||||
func (s *Store) CreateTables() error {
|
||||
s.log.Debug("migrating database...")
|
||||
tx, beginErr := s.db.Begin()
|
||||
if beginErr != nil {
|
||||
s.log.Error("cannot begin transaction: %v", beginErr)
|
||||
return beginErr
|
||||
}
|
||||
|
||||
for _, query := range migrations {
|
||||
_, execErr := tx.Exec(query)
|
||||
if execErr != nil {
|
||||
s.log.Error("cannot apply migration: %v", execErr)
|
||||
// nolint // we already have the execErr to return
|
||||
tx.Rollback()
|
||||
return execErr
|
||||
}
|
||||
}
|
||||
|
||||
commitErr := tx.Commit()
|
||||
if commitErr != nil {
|
||||
s.log.Error("cannot commit transaction: %v", commitErr)
|
||||
// nolint // we already have the commitErr to return
|
||||
tx.Rollback()
|
||||
return commitErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
63
vendor/gitlab.com/etke.cc/linkpearl/store/state.go
generated
vendored
Normal file
63
vendor/gitlab.com/etke.cc/linkpearl/store/state.go
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// NOTE: functions in that file are for crypto.StateStore implementation
|
||||
// ref: https://pkg.go.dev/maunium.net/go/mautrix/crypto#StateStore
|
||||
|
||||
// GetEncryptionEvent returns the encryption event's content for an encrypted room.
|
||||
func (s *Store) GetEncryptionEvent(roomID id.RoomID) *event.EncryptionEventContent {
|
||||
if !s.encryption {
|
||||
return nil
|
||||
}
|
||||
s.log.Debug("finding encryption event of %s", roomID)
|
||||
query := "SELECT encryption_event FROM rooms WHERE room_id = $1"
|
||||
row := s.db.QueryRow(query, roomID)
|
||||
|
||||
var encryptionEventJSON []byte
|
||||
err := row.Scan(&encryptionEventJSON)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
s.log.Error("cannot find encryption event: %v", err)
|
||||
return nil
|
||||
}
|
||||
var encryptionEvent event.EncryptionEventContent
|
||||
if err := json.Unmarshal(encryptionEventJSON, &encryptionEvent); err != nil {
|
||||
s.log.Debug("cannot unmarshal encryption event: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return &encryptionEvent
|
||||
}
|
||||
|
||||
// FindSharedRooms returns the encrypted rooms that another user is also in for a user ID.
|
||||
func (s *Store) FindSharedRooms(userID id.UserID) []id.RoomID {
|
||||
if !s.encryption {
|
||||
return nil
|
||||
}
|
||||
s.log.Debug("loading shared rooms for %s", userID)
|
||||
query := "SELECT room_id FROM room_members WHERE user_id = $1"
|
||||
rows, queryErr := s.db.Query(query, userID)
|
||||
rooms := make([]id.RoomID, 0)
|
||||
if queryErr != nil {
|
||||
s.log.Error("cannot load room members: %s", queryErr)
|
||||
return rooms
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var roomID id.RoomID
|
||||
for rows.Next() {
|
||||
scanErr := rows.Scan(&roomID)
|
||||
if scanErr != nil {
|
||||
continue
|
||||
}
|
||||
rooms = append(rooms, roomID)
|
||||
}
|
||||
|
||||
return rooms
|
||||
}
|
||||
55
vendor/gitlab.com/etke.cc/linkpearl/store/store.go
generated
vendored
Normal file
55
vendor/gitlab.com/etke.cc/linkpearl/store/store.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// Package store implements crypto.Store, crypto.StateStore, mautrix.Storer and some additional "glue methods"
|
||||
package store
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"maunium.net/go/mautrix/crypto"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/dbutil"
|
||||
|
||||
"gitlab.com/etke.cc/linkpearl/config"
|
||||
)
|
||||
|
||||
// Store for the matrix
|
||||
type Store struct {
|
||||
db *sql.DB
|
||||
dialect string
|
||||
log config.Logger
|
||||
encryption bool
|
||||
s *crypto.SQLCryptoStore
|
||||
}
|
||||
|
||||
// New store
|
||||
func New(db *sql.DB, dialect string, log config.Logger) *Store {
|
||||
return &Store{
|
||||
db: db,
|
||||
log: log,
|
||||
dialect: dialect,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCrypto adds crypto store support
|
||||
func (s *Store) WithCrypto(userID id.UserID, deviceID id.DeviceID, logger config.Logger) error {
|
||||
s.log.Debug("crypto store enabled")
|
||||
s.encryption = true
|
||||
db, err := dbutil.NewWithDB(s.db, s.dialect)
|
||||
if err != nil {
|
||||
logger.Error("cannot init database: %v", err)
|
||||
return err
|
||||
}
|
||||
s.s = crypto.NewSQLCryptoStore(
|
||||
db,
|
||||
dbutil.NoopLogger,
|
||||
userID.String(),
|
||||
deviceID,
|
||||
[]byte(userID),
|
||||
)
|
||||
|
||||
return s.s.Upgrade()
|
||||
}
|
||||
|
||||
// GetDialect returns database dialect
|
||||
func (s *Store) GetDialect() string {
|
||||
return s.dialect
|
||||
}
|
||||
126
vendor/gitlab.com/etke.cc/linkpearl/store/storer.go
generated
vendored
Normal file
126
vendor/gitlab.com/etke.cc/linkpearl/store/storer.go
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// NOTE: functions in that file are for mautrix.Storer implementation
|
||||
// ref: https://pkg.go.dev/maunium.net/go/mautrix#Storer
|
||||
|
||||
// SaveFilterID to DB
|
||||
func (s *Store) SaveFilterID(userID id.UserID, filterID string) {
|
||||
s.log.Debug("saving filter ID %s for %s", filterID, userID)
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Error("cannot begin transaction: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var insert string
|
||||
switch s.dialect {
|
||||
case "sqlite3":
|
||||
insert = "INSERT OR IGNORE INTO user_filter_ids VALUES (?, ?)"
|
||||
case "postgres":
|
||||
insert = "INSERT INTO user_filter_ids VALUES ($1, $2) ON CONFLICT DO NOTHING"
|
||||
}
|
||||
update := "UPDATE user_filter_ids SET filter_id = $1 WHERE user_id = $2"
|
||||
|
||||
_, updateErr := tx.Exec(update, filterID, userID)
|
||||
if updateErr != nil {
|
||||
s.log.Error("cannot update filter ID: %v", updateErr)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
_, insertErr := tx.Exec(insert, userID, filterID)
|
||||
if insertErr != nil {
|
||||
s.log.Error("cannot create filter ID: %v", insertErr)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
commitErr := tx.Commit()
|
||||
if commitErr != nil {
|
||||
s.log.Error("cannot upsert filter ID: %v", commitErr)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFilterID from DB
|
||||
func (s *Store) LoadFilterID(userID id.UserID) string {
|
||||
s.log.Debug("loading filter ID for %s", userID)
|
||||
query := "SELECT filter_id FROM user_filter_ids WHERE user_id = $1"
|
||||
row := s.db.QueryRow(query, userID)
|
||||
var filterID string
|
||||
if err := row.Scan(&filterID); err != nil {
|
||||
s.log.Error("cannot load filter ID: %s", err)
|
||||
return ""
|
||||
}
|
||||
return filterID
|
||||
}
|
||||
|
||||
// SaveNextBatch to DB
|
||||
func (s *Store) SaveNextBatch(userID id.UserID, nextBatchToken string) {
|
||||
s.log.Debug("saving next batch token for %s", userID)
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Error("cannot begin transaction: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var insert string
|
||||
switch s.dialect {
|
||||
case "sqlite3":
|
||||
insert = "INSERT OR IGNORE INTO user_batch_tokens VALUES (?, ?)"
|
||||
case "postgres":
|
||||
insert = "INSERT INTO user_batch_tokens VALUES ($1, $2) ON CONFLICT DO NOTHING"
|
||||
}
|
||||
update := "UPDATE user_batch_tokens SET next_batch_token = $1 WHERE user_id = $2"
|
||||
|
||||
if _, err := tx.Exec(update, nextBatchToken, userID); err != nil {
|
||||
s.log.Error("cannot update next batch token: %v", err)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(insert, userID, nextBatchToken); err != nil {
|
||||
s.log.Error("cannot insert next batch token: %v", err)
|
||||
// nolint // no need to check error here
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
commitErr := tx.Commit()
|
||||
if commitErr != nil {
|
||||
s.log.Error("cannot commit transaction: %v", commitErr)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadNextBatch from DB
|
||||
func (s *Store) LoadNextBatch(userID id.UserID) string {
|
||||
s.log.Debug("loading next batch token for %s", userID)
|
||||
query := "SELECT next_batch_token FROM user_batch_tokens WHERE user_id = $1"
|
||||
row := s.db.QueryRow(query, userID)
|
||||
var batchToken string
|
||||
if err := row.Scan(&batchToken); err != nil {
|
||||
s.log.Error("cannot load next batch token: %v", err)
|
||||
return ""
|
||||
}
|
||||
return batchToken
|
||||
}
|
||||
|
||||
// SaveRoom to DB, not implemented
|
||||
func (s *Store) SaveRoom(room *mautrix.Room) {
|
||||
s.log.Debug("saving room %s (stub, not implemented)", room.ID)
|
||||
}
|
||||
|
||||
// LoadRoom from DB, not implemented
|
||||
func (s *Store) LoadRoom(roomID id.RoomID) *mautrix.Room {
|
||||
s.log.Debug("loading room %s (stub, not implemented)", roomID)
|
||||
return mautrix.NewRoom(roomID)
|
||||
}
|
||||
117
vendor/gitlab.com/etke.cc/linkpearl/sync.go
generated
vendored
Normal file
117
vendor/gitlab.com/etke.cc/linkpearl/sync.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
// OnEventType allows callers to be notified when there are new events for the given event type.
|
||||
// There are no duplicate checks.
|
||||
func (l *Linkpearl) OnEventType(eventType event.Type, callback mautrix.EventHandler) {
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnEventType(eventType, callback)
|
||||
}
|
||||
|
||||
// OnSync shortcut to mautrix.DefaultSyncer.OnSync
|
||||
func (l *Linkpearl) OnSync(callback mautrix.SyncHandler) {
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnSync(callback)
|
||||
}
|
||||
|
||||
// OnEvent shortcut to mautrix.DefaultSyncer.OnEvent
|
||||
func (l *Linkpearl) OnEvent(callback mautrix.EventHandler) {
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnEvent(callback)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) initSync() {
|
||||
if l.olm != nil {
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnSync(l.olm.ProcessSyncResponse)
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnEventType(
|
||||
event.StateEncryption,
|
||||
func(source mautrix.EventSource, evt *event.Event) {
|
||||
go l.onEncryption(source, evt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
l.api.Syncer.(*mautrix.DefaultSyncer).OnEventType(
|
||||
event.StateMember,
|
||||
func(source mautrix.EventSource, evt *event.Event) {
|
||||
go l.onMembership(source, evt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) onMembership(_ mautrix.EventSource, evt *event.Event) {
|
||||
if l.olm != nil {
|
||||
l.olm.HandleMemberEvent(evt)
|
||||
}
|
||||
l.store.SetMembership(evt)
|
||||
|
||||
// potentially autoaccept invites
|
||||
l.onInvite(evt)
|
||||
|
||||
// autoleave empty rooms
|
||||
l.onEmpty(evt)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) onInvite(evt *event.Event) {
|
||||
userID := l.api.UserID.String()
|
||||
invite := evt.Content.AsMember().Membership == event.MembershipInvite
|
||||
if !invite || evt.GetStateKey() != userID {
|
||||
return
|
||||
}
|
||||
|
||||
if l.joinPermit(evt) {
|
||||
l.tryJoin(evt.RoomID, 0)
|
||||
return
|
||||
}
|
||||
|
||||
l.tryLeave(evt.RoomID, 0)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) tryJoin(roomID id.RoomID, retry int) {
|
||||
if retry >= l.maxretries {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := l.api.JoinRoomByID(roomID)
|
||||
if err != nil {
|
||||
l.log.Error("cannot join the room %s: %v", roomID, err)
|
||||
time.Sleep(5 * time.Second)
|
||||
l.log.Debug("trying to join again (%d/%d)", retry+1, l.maxretries)
|
||||
l.tryJoin(roomID, retry+1)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Linkpearl) tryLeave(roomID id.RoomID, retry int) {
|
||||
if retry >= l.maxretries {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := l.api.LeaveRoom(roomID)
|
||||
if err != nil {
|
||||
l.log.Error("cannot leave room: %v", err)
|
||||
time.Sleep(5 * time.Second)
|
||||
l.log.Debug("trying to leave again (%d/%d)", retry+1, l.maxretries)
|
||||
l.tryLeave(roomID, retry+1)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Linkpearl) onEmpty(evt *event.Event) {
|
||||
if !l.autoleave {
|
||||
return
|
||||
}
|
||||
|
||||
members := l.store.GetRoomMembers(evt.RoomID)
|
||||
if len(members) >= 1 && members[0] != l.api.UserID {
|
||||
return
|
||||
}
|
||||
|
||||
l.tryLeave(evt.RoomID, 0)
|
||||
}
|
||||
|
||||
func (l *Linkpearl) onEncryption(_ mautrix.EventSource, evt *event.Event) {
|
||||
l.store.SetEncryptionEvent(evt)
|
||||
}
|
||||
Reference in New Issue
Block a user