mirror of
https://github.com/certd/certd.git
synced 2026-04-04 06:30:51 +08:00
Compare commits
241 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99bb7b70e0 | ||
|
|
443f6358c9 | ||
|
|
0bae4851c1 | ||
|
|
66710d33c6 | ||
|
|
73fe1422f3 | ||
|
|
47f3cf7ba5 | ||
|
|
d5ef57542a | ||
|
|
cc3531b9d5 | ||
|
|
95722f46f4 | ||
|
|
5950e1cae7 | ||
|
|
d176ab4886 | ||
|
|
cbccf1024b | ||
|
|
643148d283 | ||
|
|
ac15c8fc0e | ||
|
|
3751fcd4c9 | ||
|
|
6f6606d76d | ||
|
|
8c152371a1 | ||
|
|
f489c59ca3 | ||
|
|
d2897cefaa | ||
|
|
9747d40734 | ||
|
|
e123ec4089 | ||
|
|
f358a0f226 | ||
|
|
003ea9310b | ||
|
|
d602df4c70 | ||
|
|
daa990ee96 | ||
|
|
0fca7dc3ce | ||
|
|
0a946f55ca | ||
|
|
458756e895 | ||
|
|
76dd23174a | ||
|
|
0ad667b00a | ||
|
|
699ab168c1 | ||
|
|
5ccb4a6f08 | ||
|
|
2c10cedb34 | ||
|
|
3b357ef301 | ||
|
|
f686fb0d95 | ||
|
|
3f739daaea | ||
|
|
c9d415f9db | ||
|
|
51249c304c | ||
|
|
83f9a551e7 | ||
|
|
6c450d3249 | ||
|
|
8b828b3f34 | ||
|
|
146d106991 | ||
|
|
b15b2edcdf | ||
|
|
f08f765529 | ||
|
|
fbde7cbd93 | ||
|
|
d10e80bf83 | ||
|
|
a269d8374e | ||
|
|
49ea196160 | ||
|
|
ddb1bc87bb | ||
|
|
07a45b4530 | ||
|
|
dcd1023a39 | ||
|
|
52522f27e9 | ||
|
|
e4ec4e1404 | ||
|
|
717d203622 | ||
|
|
c23f6172b5 | ||
|
|
b04d4cb5c5 | ||
|
|
d66bc33761 | ||
|
|
f710c00c0d | ||
|
|
e68862b633 | ||
|
|
6094a4af79 | ||
|
|
146ac49703 | ||
|
|
909b75eb40 | ||
|
|
dcdb25d92d | ||
|
|
3dfdd3c31c | ||
|
|
25d5a99b3d | ||
|
|
e1466737e3 | ||
|
|
370a28c10e | ||
|
|
af919c2f6e | ||
|
|
dc3ab544c8 | ||
|
|
708bebe6e3 | ||
|
|
3722e922ff | ||
|
|
8b5d5a8bf9 | ||
|
|
038b1c9ca4 | ||
|
|
b10ff5b6ee | ||
|
|
6950d779e0 | ||
|
|
4c31db427a | ||
|
|
540981e071 | ||
|
|
ed8b9cd5e9 | ||
|
|
3dea83ce31 | ||
|
|
cfb46a7c2b | ||
|
|
dd2f44bfe9 | ||
|
|
09d0e79bcd | ||
|
|
a9c1ca5c97 | ||
|
|
1af6fb3a58 | ||
|
|
b7bde7b685 | ||
|
|
718028ca62 | ||
|
|
98b2863547 | ||
|
|
b1e60456cf | ||
|
|
a38004c1ed | ||
|
|
5a355b276e | ||
|
|
a52721bd7e | ||
|
|
6df399fe02 | ||
|
|
6d8ede9575 | ||
|
|
7145aa60ca | ||
|
|
b1181c0f9a | ||
|
|
bace2a7c25 | ||
|
|
a70b4373de | ||
|
|
b7c12e6d91 | ||
|
|
6a88dd476e | ||
|
|
5fbd774266 | ||
|
|
bdec010d2e | ||
|
|
05a00b7b78 | ||
|
|
eaf23c3034 | ||
|
|
276a8b35e5 | ||
|
|
466d659f6e | ||
|
|
84e26381b5 | ||
|
|
469b5a5f69 | ||
|
|
ad77ebd2f9 | ||
|
|
b75543c3bc | ||
|
|
0677275742 | ||
|
|
0c3724e0ad | ||
|
|
803083d23c | ||
|
|
f4f8067a12 | ||
|
|
caa9f084d6 | ||
|
|
81407b65d1 | ||
|
|
8a24293fd7 | ||
|
|
8f1886a585 | ||
|
|
0a64e5fa67 | ||
|
|
7a70603971 | ||
|
|
0d5e00e744 | ||
|
|
91ba1433af | ||
|
|
12e56d14f2 | ||
|
|
7326119f52 | ||
|
|
136983cf14 | ||
|
|
105a1b80ae | ||
|
|
b8000ca533 | ||
|
|
c3e374e6e5 | ||
|
|
a9b6e87249 | ||
|
|
61de5422bf | ||
|
|
f96697f619 | ||
|
|
b4560d6370 | ||
|
|
a7bcde8d82 | ||
|
|
34bb4d54c2 | ||
|
|
e0116a1a03 | ||
|
|
12fec7939d | ||
|
|
ff8e02cceb | ||
|
|
8122bed97f | ||
|
|
991c3dbb76 | ||
|
|
399c23623d | ||
|
|
2232f21b48 | ||
|
|
e41c084381 | ||
|
|
520b27e0dc | ||
|
|
ace7e0247a | ||
|
|
9ae414b1c6 | ||
|
|
cb8c8186f1 | ||
|
|
82f86d9556 | ||
|
|
cfb1034450 | ||
|
|
2a07442a85 | ||
|
|
68c1eff81d | ||
|
|
baec15dfc6 | ||
|
|
6eb9817296 | ||
|
|
b9d5d33aaa | ||
|
|
560519894c | ||
|
|
9f434b0968 | ||
|
|
07066dde87 | ||
|
|
074c8f7cd0 | ||
|
|
e9df2355f4 | ||
|
|
45547d6f94 | ||
|
|
4a421d5b14 | ||
|
|
7b9825eb40 | ||
|
|
5cde165f0b | ||
|
|
305824ff1a | ||
|
|
86ddb72227 | ||
|
|
cca33478e4 | ||
|
|
a8f41d3c48 | ||
|
|
a25a15ca6e | ||
|
|
a39dac4dbd | ||
|
|
eab0c3be60 | ||
|
|
b4ee3d0dfc | ||
|
|
2f03e18c59 | ||
|
|
232cd7215e | ||
|
|
86b1e9959b | ||
|
|
fd130f86fd | ||
|
|
2669f509e1 | ||
|
|
d3619ad60f | ||
|
|
c26417d769 | ||
|
|
2942d39dfe | ||
|
|
df65b0509e | ||
|
|
fbde35483b | ||
|
|
7370f8b83b | ||
|
|
8b0ca1da2e | ||
|
|
466f2b1a02 | ||
|
|
f1d6cce88c | ||
|
|
ad7ababb4c | ||
|
|
72fa623674 | ||
|
|
e5d117c134 | ||
|
|
f8944a1331 | ||
|
|
e850855154 | ||
|
|
06eacee90c | ||
|
|
b1e100982e | ||
|
|
8f30158b00 | ||
|
|
576f7db978 | ||
|
|
137e043dfe | ||
|
|
15467fc233 | ||
|
|
eec0fcdcf1 | ||
|
|
a41dee015e | ||
|
|
d1a74713ef | ||
|
|
813e9e71d7 | ||
|
|
3d08dce26e | ||
|
|
4739d75f4a | ||
|
|
30cd62664b | ||
|
|
ae6b0fb111 | ||
|
|
9ec48f6ab8 | ||
|
|
f68565f444 | ||
|
|
ce5aae3795 | ||
|
|
bd00c09da0 | ||
|
|
44326c3abe | ||
|
|
2f3db7d982 | ||
|
|
9e4e3044b4 | ||
|
|
23bf0d07f7 | ||
|
|
6e61f8bcfb | ||
|
|
c7b28feb07 | ||
|
|
624eade9f2 | ||
|
|
d727a77289 | ||
|
|
c0c2cb328c | ||
|
|
8cc80deff8 | ||
|
|
5312c11472 | ||
|
|
f07ce6f47d | ||
|
|
259e797ea5 | ||
|
|
d77addd2dc | ||
|
|
c2420edb5a | ||
|
|
e1396bb107 | ||
|
|
b0def03790 | ||
|
|
9f371df372 | ||
|
|
986fd4b010 | ||
|
|
4cd7b02cb7 | ||
|
|
67bff28255 | ||
|
|
43e90503ca | ||
|
|
25dae3d1ec | ||
|
|
ec81572670 | ||
|
|
71f6d5769a | ||
|
|
49b96592a0 | ||
|
|
af0875ac4c | ||
|
|
48192b9002 | ||
|
|
ca289d4604 | ||
|
|
6529fd2fdb | ||
|
|
e84f5e8b0a | ||
|
|
df9f561fd3 | ||
|
|
06603759fd | ||
|
|
a4bd29e6bf | ||
|
|
458486dd6b |
8
CHANGELOG.md
Normal file
8
CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.1](https://github.com/certd/certd/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <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/>.
|
||||
139
README.md
Normal file
139
README.md
Normal file
@@ -0,0 +1,139 @@
|
||||
# CertD
|
||||
|
||||
CertD 是一个帮助你全自动申请和部署SSL证书的工具。
|
||||
后缀D取自linux守护进程的命名风格,意为证书守护进程。
|
||||
|
||||
## 特性
|
||||
本项目不仅支持证书申请过程自动化,还可以自动化部署证书,让你的证书永不过期。
|
||||
|
||||
* 全自动申请证书
|
||||
* 全自动部署证书(目前支持服务器上传部署、阿里云、腾讯云等)
|
||||
* 可与CI/DI工具结合使用
|
||||
|
||||
## 免费证书申请说明
|
||||
* 本项目ssl证书提供商为letencrypt
|
||||
* 申请过程遵循acme协议
|
||||
* 需要验证域名所有权,一般有两种方式(目前本项目仅支持dns-01)
|
||||
* http-01: 在网站根目录下放置一份txt文件
|
||||
* dns-01: 需要给域名添加txt解析记录,泛域名只能用这种方式
|
||||
* 证书续期:
|
||||
* 实际上acme并没有续期概念。
|
||||
* 我们所说的续期,其实就是按照全套流程重新申请一份新证书。
|
||||
* 免费证书过期时间90天,以后可能还会缩短,所以自动化部署必不可少
|
||||
|
||||
|
||||
|
||||
## 快速开始
|
||||
本案例演示,如何配置自动申请证书,并部署到阿里云CDN,然后快要到期前自动更新证书并重新部署
|
||||
|
||||
|
||||
1. 环境准备
|
||||
安装[nodejs](https://nodejs.org/zh-cn/)
|
||||
|
||||
|
||||
2. 生成node项目
|
||||
|
||||
通过ui生成: https://certd.docmirror.cn/
|
||||
|
||||
开始生成证书,先填写域名,支持将多个域名打到一个证书上
|
||||

|
||||
|
||||
配置证书详细信息
|
||||

|
||||
|
||||
配置证书部署流程
|
||||

|
||||
|
||||
配置好之后,点击导出按钮,导出一个node项目包
|
||||
|
||||
4. 运行
|
||||
将导出的压缩包解压,然后执行如下命令,即可开始申请证书并部署
|
||||
```
|
||||
npm install
|
||||
npm run certd
|
||||
```
|
||||
5. 执行效果
|
||||
生成的证书默认会存储在 `${home}/.certd/${email}/certs/${domain}/current`目录下
|
||||
```
|
||||
[2021-01-08T16:15:04.681] [INFO] certd - 任务完成
|
||||
[2021-01-08T16:15:04.681] [INFO] certd - ---------------------------任务结果总览--------------------------
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - 【更新证书】--------------------------------------- [success]
|
||||
证书申请成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - 【流程1-部署到阿里云CDN】---------------------------- [success] 执行成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - └【上传到阿里云】-------------------------------- [success] 执行成功
|
||||
[2021-01-08T16:15:04.682] [INFO] certd - └【部署证书到CDN】------------------------------- [success] 执行成功
|
||||
```
|
||||
6. 证书续期
|
||||
实际上没有证书续期的概念,只有重新生成一份新的证书,然后重新部署证书
|
||||
所以每天定时运行即可,当证书过期日前20天时,会重新申请新的证书,然后执行部署任务。
|
||||
|
||||
7. 其他说明
|
||||
证书的部署任务执行后会记录执行结果,已经成功过的不会重复执行
|
||||
所以当你临时需要将证书部署到其他地方时,直接追加部署任务,然后再次运行即可
|
||||
|
||||
## CI/DI集成与自动续期重新部署
|
||||
集成前,将以上导出的node项目提交到内网git仓库,或者私有git仓库(由于包含敏感信息,不要提交到公开git仓库)
|
||||
|
||||
### jenkins任务
|
||||
1. 创建任务
|
||||
选择构建自由风格的任务
|
||||
|
||||
2. 配置git
|
||||
配置cert-run的git地址
|
||||
|
||||
3. 构建触发器
|
||||
配置 `H 3 * * *` ,每天凌晨3点-4点执行一次
|
||||
|
||||
4. 构建环境
|
||||
勾选 `Provide Node & npm bin/ folder to PATH`,提供nodejs运行环境
|
||||
如果没有此选项,需要jenkins安装`nodejs`插件
|
||||
|
||||
5. 构建
|
||||
执行shell
|
||||
```
|
||||
npm install --production #执行过一次之后,就可以注释掉,加快执行速度
|
||||
npm run post
|
||||
```
|
||||
6. 构建后操作
|
||||
邮件通知
|
||||
配置你的邮箱地址,可以在执行失败时收到邮件通知。
|
||||
|
||||
|
||||
## API
|
||||
先列个提纲,待完善
|
||||
|
||||
参数示例参考:https://gitee.com/certd/certd/blob/master/test/options.js
|
||||
|
||||
### 授权提供者
|
||||
用于dns验证接口调用
|
||||
#### aliyun
|
||||
|
||||
#### dnspod
|
||||
|
||||
### deploy插件
|
||||
部署任务插件
|
||||
#### 阿里云
|
||||
##### 上传到阿里云
|
||||
type = uploadCertToAliyun
|
||||
##### 部署到阿里云DNS
|
||||
type = deployCertToAliyunCDN
|
||||
|
||||
##### 部署到阿里云CLB
|
||||
type = deployCertToAliyunCLB
|
||||
|
||||
#### 腾讯云
|
||||
##### 上传到腾讯云
|
||||
type = uploadCertToTencent
|
||||
|
||||
##### 部署到腾讯云DNS
|
||||
type = deployCertToTencentDNS
|
||||
|
||||
##### 部署到腾讯云CLB
|
||||
type = deployCertToTencentCLB
|
||||
|
||||
##### 部署到腾讯云TKE-ingress
|
||||
type = deployCertToTencentTKEIngress
|
||||
|
||||
|
||||
### 更多部署插件
|
||||
等你来提需求
|
||||
80
deploy.js
Normal file
80
deploy.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const http = require("axios")
|
||||
const exec = require('child_process').exec;
|
||||
|
||||
//builder
|
||||
function execute(cmd){
|
||||
return new Promise((resolve,reject)=>{
|
||||
console.log("cmd executing: " + cmd)
|
||||
exec(cmd, function(error, stdout, stderr) {
|
||||
if(error){
|
||||
console.error(error);
|
||||
console.info(stderr)
|
||||
reject(error)
|
||||
}
|
||||
else{
|
||||
console.info(stdout)
|
||||
console.log("success");
|
||||
resolve(true)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async function build(){
|
||||
await execute("cd ./packages/fast-admin/fs-admin-antdv/ && npm run build")
|
||||
await execute("cd ./packages/fast-admin/fs-admin-element/ && npm run build")
|
||||
await execute("cd ./packages/fast-admin/fs-admin-naive-ui/ && npm run build")
|
||||
await execute("npm run docs:build")
|
||||
}
|
||||
|
||||
|
||||
|
||||
// trigger
|
||||
|
||||
const naive = "http://flow-openapi.aliyun.com/pipeline/webhook/Zm3TJyDtyFZgV4dtJiD1"
|
||||
const doc = "http://flow-openapi.aliyun.com/pipeline/webhook/soOYdQ5sF3kLjTPJGmIO"
|
||||
const antdv = "http://flow-openapi.aliyun.com/pipeline/webhook/HiL0uVYxfUnBzIMJZVXB"
|
||||
const element = "http://flow-openapi.aliyun.com/pipeline/webhook/uFTI0XJ9RgqnofX7jpRD"
|
||||
|
||||
const webhooks = [doc,naive,antdv,element]
|
||||
|
||||
async function sleep(time){
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve,time)
|
||||
})
|
||||
}
|
||||
|
||||
async function trigger(){
|
||||
for (const webhook of webhooks) {
|
||||
await http({
|
||||
url:webhook,
|
||||
method:'POST',
|
||||
headers:{
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data:{}
|
||||
})
|
||||
console.log(`webhook success:${webhook}`)
|
||||
await sleep(1000)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function start(){
|
||||
// await build()
|
||||
console.log("等待60秒")
|
||||
await sleep(60*1000)
|
||||
await trigger()
|
||||
}
|
||||
|
||||
start()
|
||||
|
||||
|
||||
/**
|
||||
* 打包前 修改 lerna
|
||||
* nodemodules里面搜索如下
|
||||
* return childProcess.exec("git", ["add", "--", ...files], execOpts);
|
||||
*
|
||||
* ('git', ['add', '--', ...files]
|
||||
* ('git', ['add', '.']
|
||||
*/
|
||||
BIN
doc/step1.png
Normal file
BIN
doc/step1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
doc/step2.png
Normal file
BIN
doc/step2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
BIN
doc/step3.png
Normal file
BIN
doc/step3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
BIN
doc/tasks.png
Normal file
BIN
doc/tasks.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
13
lerna.json
Normal file
13
lerna.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"useWorkspaces": true,
|
||||
"command": {
|
||||
"bootstrap": {
|
||||
"npmClientArgs": [
|
||||
"--no-package-lock"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmClient": "pnpm",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
26
package.json
Normal file
26
package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "root",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@lerna-lite/cli": "^2.4.0",
|
||||
"@lerna-lite/run": "^2.4.0",
|
||||
"@lerna-lite/publish": "^2.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "lerna bootstrap --hoist",
|
||||
"i-all": "lerna link && lerna exec npm install ",
|
||||
"publish": "npm run proxy && npm run prepublishOnly && lerna publish --conventional-commits && npm run afterpublishOnly",
|
||||
"afterpublishOnly": "",
|
||||
"proxy": "npm config set proxy=http://127.0.0.1:10809",
|
||||
"prepublishOnly": "npm run before-build && lerna run build ",
|
||||
"before-build": "cd ./packages/core/acme-client && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\""
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/**"
|
||||
]
|
||||
}
|
||||
1
packages/core/acme-client/.gitignore
vendored
1
packages/core/acme-client/.gitignore
vendored
@@ -4,3 +4,4 @@ npm-debug.log
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
/.idea/
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.1](https://github.com/publishlab/node-acme-client/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/acme-client
|
||||
|
||||
# Changelog
|
||||
|
||||
## Important upgrade notice
|
||||
@@ -6,7 +15,6 @@ On September 15, 2022, Let's Encrypt will stop accepting Certificate Signing Req
|
||||
|
||||
A more detailed explanation can be found [at the Let's Encrypt forums](https://community.letsencrypt.org/t/rejecting-sha-1-csrs-and-validation-using-tls-1-0-1-1-urls/175144).
|
||||
|
||||
|
||||
## v5.0.0 (2022-07-28)
|
||||
|
||||
* [Upgrade guide here](docs/upgrade-v5.md)
|
||||
@@ -16,39 +24,32 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `changed` Replace `bluebird` dependency with native promise APIs
|
||||
* `changed` Replace `backo2` dependency with internal utility
|
||||
|
||||
|
||||
## v4.2.5 (2022-03-21)
|
||||
|
||||
* `fixed` Upgrade `axios@0.26.1`
|
||||
* `fixed` Upgrade `node-forge@1.3.0` - [CVE-2022-24771](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24771), [CVE-2022-24772](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24772), [CVE-2022-24773](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24773)
|
||||
|
||||
|
||||
## 4.2.4 (2022-03-19)
|
||||
|
||||
* `fixed` Use SHA-256 when signing CSRs
|
||||
|
||||
|
||||
## v3.3.2 (2022-03-19)
|
||||
|
||||
* `backport` Use SHA-256 when signing CSRs
|
||||
|
||||
|
||||
## v4.2.3 (2022-01-11)
|
||||
|
||||
* `added` Directory URLs for ACME providers [Buypass](https://www.buypass.com) and [ZeroSSL](https://zerossl.com)
|
||||
* `fixed` Skip already valid authorizations when using `client.auto()`
|
||||
|
||||
|
||||
## v4.2.2 (2022-01-10)
|
||||
|
||||
* `fixed` Upgrade `node-forge@1.2.0`
|
||||
|
||||
|
||||
## v4.2.1 (2022-01-10)
|
||||
|
||||
* `fixed` ZeroSSL `duplicate_domains_in_array` error when using `client.auto()`
|
||||
|
||||
|
||||
## v4.2.0 (2022-01-06)
|
||||
|
||||
* `added` Support for external account binding - [RFC 8555 Section 7.3.4](https://tools.ietf.org/html/rfc8555#section-7.3.4)
|
||||
@@ -59,27 +60,22 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `fixed` Error verbosity when failing to read ACME directory
|
||||
* `fixed` Correctly recognize `ready` and `processing` states - [RFC 8555 Section 7.1.6](https://tools.ietf.org/html/rfc8555#section-7.1.6)
|
||||
|
||||
|
||||
## v4.1.4 (2021-12-23)
|
||||
|
||||
* `fixed` Upgrade `axios@0.21.4` - [CVE-2021-3749](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3749)
|
||||
|
||||
|
||||
## v4.1.3 (2021-02-22)
|
||||
|
||||
* `fixed` Upgrade `axios@0.21.1` - [CVE-2020-28168](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28168)
|
||||
|
||||
|
||||
## v4.1.2 (2020-11-16)
|
||||
|
||||
* `fixed` Bug when encoding PEM payloads, potentially causing malformed requests
|
||||
|
||||
|
||||
## v4.1.1 (2020-11-13)
|
||||
|
||||
* `fixed` Missing TypeScript definitions
|
||||
|
||||
|
||||
## v4.1.0 (2020-11-12)
|
||||
|
||||
* `added` Option `preferredChain` added to `client.getCertificate()` and `client.auto()` to indicate which certificate chain is preferred if a CA offers multiple
|
||||
@@ -90,17 +86,14 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `fixed` Missing URL augmentation in `client.finalizeOrder()` and `client.deactivateAuthorization()`
|
||||
* `fixed` Add certificate issuer to response from `forge.readCertificateInfo()`
|
||||
|
||||
|
||||
## v4.0.2 (2020-10-09)
|
||||
|
||||
* `fixed` Explicitly set default `axios` HTTP adapter - [axios/axios#1180](https://github.com/axios/axios/issues/1180)
|
||||
|
||||
|
||||
## v4.0.1 (2020-09-15)
|
||||
|
||||
* `fixed` Upgrade `node-forge@0.10.0` - [CVE-2020-7720](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7720)
|
||||
|
||||
|
||||
## v4.0.0 (2020-05-29)
|
||||
|
||||
* `breaking` Remove support for Node v8
|
||||
@@ -108,23 +101,19 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `fixed` Incorrect TypeScript `CertificateInfo` definitions
|
||||
* `fixed` Allow trailing whitespace character in `http-01` challenge response
|
||||
|
||||
|
||||
## v3.3.1 (2020-01-07)
|
||||
|
||||
* `fixed` Improvements to TypeScript definitions
|
||||
|
||||
|
||||
## v3.3.0 (2019-12-19)
|
||||
|
||||
* `added` TypeScript definitions
|
||||
* `fixed` Allow missing ACME directory meta field - [RFC 8555 Section 7.1.1](https://tools.ietf.org/html/rfc8555#section-7.1.1)
|
||||
|
||||
|
||||
## v3.2.1 (2019-11-14)
|
||||
|
||||
* `added` New option `skipChallengeVerification` added to `client.auto()` to bypass internal challenge verification
|
||||
|
||||
|
||||
## v3.2.0 (2019-08-26)
|
||||
|
||||
* `added` More extensive testing using [letsencrypt/pebble](https://github.com/letsencrypt/pebble)
|
||||
@@ -135,64 +124,53 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `fixed` Ensure subject common name is present in SAN when creating a CSR - [CAB v1.2.3 Section 9.2.2](https://cabforum.org/wp-content/uploads/BRv1.2.3.pdf)
|
||||
* `fixed` Send empty JSON body when responding to challenges - [RFC 8555 Section 7.5.1](https://tools.ietf.org/html/rfc8555#section-7.5.1)
|
||||
|
||||
|
||||
## v2.3.1 (2019-08-26)
|
||||
|
||||
* `backport` Minor bugs related to `POST-as-GET` when calling `client.updateAccount()`
|
||||
* `backport` Send empty JSON body when responding to challenges
|
||||
|
||||
|
||||
## v3.1.0 (2019-08-21)
|
||||
|
||||
* `added` UTF-8 support when generating a CSR subject using forge - [RFC 5280](https://tools.ietf.org/html/rfc5280)
|
||||
* `fixed` Implement `POST-as-GET` for all ACME API requests - [RFC 8555 Section 6.3](https://tools.ietf.org/html/rfc8555#section-6.3)
|
||||
|
||||
|
||||
## v2.3.0 (2019-08-21)
|
||||
|
||||
* `backport` Implement `POST-as-GET` for all ACME API requests
|
||||
|
||||
|
||||
## v3.0.0 (2019-07-13)
|
||||
|
||||
* `added` Expose `axios` instance to allow manipulating HTTP client defaults
|
||||
* `breaking` Remove support for Node v4 and v6
|
||||
* `breaking` Remove Babel transpilation
|
||||
|
||||
|
||||
## v2.2.3 (2019-01-25)
|
||||
|
||||
* `added` DNS CNAME detection when verifying `dns-01` challenges
|
||||
|
||||
|
||||
## v2.2.2 (2019-01-07)
|
||||
|
||||
* `added` Support for `tls-alpn-01` challenge key authorization
|
||||
|
||||
|
||||
## v2.2.1 (2019-01-04)
|
||||
|
||||
* `fixed` Handle and throw errors from OpenSSL process
|
||||
|
||||
|
||||
## v2.2.0 (2018-11-06)
|
||||
|
||||
* `added` New [node-forge](https://www.npmjs.com/package/node-forge) crypto interface, removes OpenSSL CLI dependency
|
||||
* `added` Support native `crypto.generateKeyPair()` API when generating key pairs
|
||||
|
||||
|
||||
## v2.1.0 (2018-10-21)
|
||||
|
||||
* `added` Ability to set and get current account URL
|
||||
* `fixed` Replace HTTP client `request` with `axios`
|
||||
* `fixed` Auto-mode no longer tries to create account when account URL exists
|
||||
|
||||
|
||||
## v2.0.1 (2018-08-17)
|
||||
|
||||
* `fixed` Key rollover in compliance with [draft-ietf-acme-13](https://tools.ietf.org/html/draft-ietf-acme-acme-13)
|
||||
|
||||
|
||||
## v2.0.0 (2018-04-02)
|
||||
|
||||
* `breaking` ACMEv2
|
||||
@@ -200,23 +178,19 @@ A more detailed explanation can be found [at the Let's Encrypt forums](https://c
|
||||
* `breaking` Rewrite to ES6
|
||||
* `breaking` Promises instead of callbacks
|
||||
|
||||
|
||||
## v1.0.0 (2017-10-20)
|
||||
|
||||
* API stable
|
||||
|
||||
|
||||
## v0.2.1 (2017-09-27)
|
||||
|
||||
* `fixed` Bug causing invalid anti-replay nonce
|
||||
|
||||
|
||||
## v0.2.0 (2017-09-21)
|
||||
|
||||
* `breaking` OpenSSL method `readCsrDomains` and `readCertificateInfo` now return domains as an object
|
||||
* `fixed` Added and fixed some tests
|
||||
|
||||
|
||||
## v0.1.0 (2017-09-14)
|
||||
|
||||
* `acme-client` released
|
||||
|
||||
1
packages/core/acme-client/build.md
Normal file
1
packages/core/acme-client/build.md
Normal file
@@ -0,0 +1 @@
|
||||
18:01
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "acme-client",
|
||||
"name": "@certd/acme-client",
|
||||
"description": "Simple and unopinionated ACME client",
|
||||
"private": false,
|
||||
"author": "nmorsman",
|
||||
"version": "5.0.0",
|
||||
"version": "1.0.1",
|
||||
"main": "src/index.js",
|
||||
"types": "types",
|
||||
"license": "MIT",
|
||||
@@ -31,7 +32,7 @@
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
"mocha": "^10.0.0",
|
||||
"nock": "^13.2.4",
|
||||
"typescript": "^4.6.2",
|
||||
"typescript": "^4.8.4",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -56,5 +57,6 @@
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/publishlab/node-acme-client/issues"
|
||||
}
|
||||
},
|
||||
"gitHead": "5950e1cae7cf30ebfc5128c15c7d1b0d101cbbb8"
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ module.exports = async function(client, userOpts) {
|
||||
|
||||
log('[auto] Resolving and satisfying authorization challenges');
|
||||
|
||||
const challengePromises = authorizations.map(async (authz) => {
|
||||
const challengeFunc = async (authz) => {
|
||||
const d = authz.identifier.value;
|
||||
let challengeCompleted = false;
|
||||
|
||||
@@ -114,9 +114,9 @@ module.exports = async function(client, userOpts) {
|
||||
/* Trigger challengeCreateFn() */
|
||||
log(`[auto] [${d}] Trigger challengeCreateFn()`);
|
||||
const keyAuthorization = await client.getChallengeKeyAuthorization(challenge);
|
||||
|
||||
let recordItem = null;
|
||||
try {
|
||||
await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
||||
recordItem = await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
||||
|
||||
/* Challenge verification */
|
||||
if (opts.skipChallengeVerification === true) {
|
||||
@@ -134,12 +134,16 @@ module.exports = async function(client, userOpts) {
|
||||
|
||||
await client.waitForValidStatus(challenge);
|
||||
}
|
||||
catch (e) {
|
||||
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`);
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
/* Trigger challengeRemoveFn(), suppress errors */
|
||||
log(`[auto] [${d}] Trigger challengeRemoveFn()`);
|
||||
|
||||
try {
|
||||
await opts.challengeRemoveFn(authz, challenge, keyAuthorization);
|
||||
await opts.challengeRemoveFn(authz, challenge, keyAuthorization, recordItem);
|
||||
}
|
||||
catch (e) {
|
||||
log(`[auto] [${d}] challengeRemoveFn threw error: ${e.message}`);
|
||||
@@ -163,10 +167,26 @@ module.exports = async function(client, userOpts) {
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
const challengePromises = authorizations.map((authz) => async () => {
|
||||
await challengeFunc(authz);
|
||||
});
|
||||
|
||||
log('[auto] Waiting for challenge valid status');
|
||||
await Promise.all(challengePromises);
|
||||
log('开始challenge');
|
||||
let promise = Promise.resolve();
|
||||
function runPromisesSerially(tasks) {
|
||||
tasks.forEach((task) => {
|
||||
promise = promise.then(task);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
await runPromisesSerially(challengePromises);
|
||||
log('challenge结束');
|
||||
|
||||
// log('[auto] Waiting for challenge valid status');
|
||||
// await Promise.all(challengePromises);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
59
packages/core/acme-client/test/retry.js
Normal file
59
packages/core/acme-client/test/retry.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { assert } = require('chai');
|
||||
const Promise = require('bluebird');
|
||||
const util = require('../src/util');
|
||||
|
||||
let count = 0;
|
||||
async function apiRequest() {
|
||||
count += 1;
|
||||
console.log(new Date(), 'retry count:', count);
|
||||
await Promise.delay(2000);
|
||||
return count;
|
||||
}
|
||||
|
||||
async function waitForValidStatus() {
|
||||
const verifyFn = async (abort) => {
|
||||
const resp = await apiRequest();
|
||||
|
||||
/* Verify status */
|
||||
console.log(new Date(), 'Item has status', resp);
|
||||
if (count < 3) {
|
||||
abort();
|
||||
throw new Error(`${new Date()}error`, count);
|
||||
}
|
||||
|
||||
console.log(new Date(), 'success');
|
||||
return 'success';
|
||||
|
||||
// if (resp.data.status === 'invalid') {
|
||||
// abort();
|
||||
// throw new Error(util.formatResponseError(resp));
|
||||
// }
|
||||
// else if (resp.data.status === 'pending') {
|
||||
// throw new Error('Operation is pending');
|
||||
// }
|
||||
// else if (resp.data.status === 'valid') {
|
||||
// return resp.data;
|
||||
// }
|
||||
//
|
||||
// throw new Error(`Unexpected item status: ${resp.data.status}`);
|
||||
};
|
||||
|
||||
console.log(new Date(), 'Waiting for valid status from', this.backoffOpts);
|
||||
return util.retry(verifyFn, this.backoffOpts);
|
||||
}
|
||||
/**
|
||||
*/
|
||||
describe('util', () => {
|
||||
it('retry', async function() {
|
||||
this.timeout(100000);
|
||||
try {
|
||||
await waitForValidStatus();
|
||||
}
|
||||
catch (e) {
|
||||
console.error('1111', e);
|
||||
}
|
||||
|
||||
|
||||
// await Promise.delay(100000);
|
||||
});
|
||||
});
|
||||
2
packages/core/acme-client/types/index.d.ts
vendored
2
packages/core/acme-client/types/index.d.ts
vendored
@@ -51,7 +51,7 @@ export interface ClientExternalAccountBindingOptions {
|
||||
export interface ClientAutoOptions {
|
||||
csr: CsrBuffer | CsrString;
|
||||
challengeCreateFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
|
||||
challengeRemoveFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string) => Promise<any>;
|
||||
challengeRemoveFn: (authz: Authorization, challenge: rfc8555.Challenge, keyAuthorization: string, recordRes:any) => Promise<any>;
|
||||
email?: string;
|
||||
termsOfServiceAgreed?: boolean;
|
||||
skipChallengeVerification?: boolean;
|
||||
|
||||
21
packages/core/pipeline/.eslintrc
Normal file
21
packages/core/pipeline/.eslintrc
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
// "no-unused-expressions": "off",
|
||||
"max-len": [0, 160, 2, { "ignoreUrls": true }]
|
||||
}
|
||||
}
|
||||
26
packages/core/pipeline/.gitignore
vendored
Normal file
26
packages/core/pipeline/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
test/user.secret.ts
|
||||
5
packages/core/pipeline/.mocharc.json
Normal file
5
packages/core/pipeline/.mocharc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "test/**/*.test.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
||||
3
packages/core/pipeline/.prettierrc
Normal file
3
packages/core/pipeline/.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printWidth": 160
|
||||
}
|
||||
8
packages/core/pipeline/CHANGELOG.md
Normal file
8
packages/core/pipeline/CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.1](https://github.com/certd/certd/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/pipeline
|
||||
16
packages/core/pipeline/README.md
Normal file
16
packages/core/pipeline/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
|
||||
## Type Support For `.vue` Imports in TS
|
||||
|
||||
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
|
||||
|
||||
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
|
||||
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
|
||||
|
||||
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
|
||||
1
packages/core/pipeline/index.ts
Normal file
1
packages/core/pipeline/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src";
|
||||
61
packages/core/pipeline/package.json
Normal file
61
packages/core/pipeline/package.json
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "@certd/pipeline",
|
||||
"private": false,
|
||||
"version": "1.0.1",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"publishConfig": {
|
||||
"main": "./dist/pipeline.umd.js",
|
||||
"module": "./dist/pipeline.mjs",
|
||||
"types": "./dist/d/index.d.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@certd/acme-client": "^1.0.1",
|
||||
"axios": "^0.21.1",
|
||||
"dayjs": "^1.11.6",
|
||||
"lodash": "^4.17.21",
|
||||
"log4js": "^6.3.0",
|
||||
"node-forge": "^0.10.0",
|
||||
"qs": "^6.9.4",
|
||||
"reflect-metadata": "^0.1.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@alicloud/cs20151215": "^3.0.3",
|
||||
"@alicloud/openapi-client": "^0.4.0",
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@midwayjs/bootstrap": "^3.9.1",
|
||||
"@midwayjs/cache": "^3.9.0",
|
||||
"@midwayjs/cli": "^1.3.21",
|
||||
"@midwayjs/core": "^3.0.0",
|
||||
"@midwayjs/decorator": "^3.0.0",
|
||||
"@midwayjs/koa": "^3.9.0",
|
||||
"@midwayjs/logger": "^2.17.0",
|
||||
"@midwayjs/typeorm": "^3.9.0",
|
||||
"@midwayjs/validate": "^3.9.0",
|
||||
"@rollup/plugin-typescript": "^11.0.0",
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/lodash": "^4.14.194",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node-forge": "^1.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||
"@typescript-eslint/parser": "^5.38.1",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"mocha": "^10.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.4",
|
||||
"vite": "^3.1.0",
|
||||
"vue-tsc": "^0.38.9"
|
||||
},
|
||||
"gitHead": "5950e1cae7cf30ebfc5128c15c7d1b0d101cbbb8"
|
||||
}
|
||||
18
packages/core/pipeline/src/access/api.ts
Normal file
18
packages/core/pipeline/src/access/api.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Registrable } from "../registry";
|
||||
import { FormItemProps } from "../d.ts";
|
||||
|
||||
export type AccessInputDefine = FormItemProps & {
|
||||
title: string;
|
||||
required?: boolean;
|
||||
};
|
||||
export type AccessDefine = Registrable & {
|
||||
input?: {
|
||||
[key: string]: AccessInputDefine;
|
||||
};
|
||||
};
|
||||
export interface IAccessService {
|
||||
getById(id: any): Promise<any>;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface IAccess {}
|
||||
39
packages/core/pipeline/src/access/decorator.ts
Normal file
39
packages/core/pipeline/src/access/decorator.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
// src/decorator/memoryCache.decorator.ts
|
||||
import { AccessDefine, AccessInputDefine } from "./api";
|
||||
import { Decorator } from "../decorator";
|
||||
import _ from "lodash";
|
||||
import { accessRegistry } from "./registry";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const ACCESS_CLASS_KEY = "pipeline:access";
|
||||
export const ACCESS_INPUT_KEY = "pipeline:access:input";
|
||||
|
||||
export function IsAccess(define: AccessDefine): ClassDecorator {
|
||||
return (target: any) => {
|
||||
target = Decorator.target(target);
|
||||
|
||||
const inputs: any = {};
|
||||
const properties = Decorator.getClassProperties(target);
|
||||
for (const property in properties) {
|
||||
const input = Reflect.getMetadata(ACCESS_INPUT_KEY, target, property);
|
||||
if (input) {
|
||||
inputs[property] = input;
|
||||
}
|
||||
}
|
||||
_.merge(define, { input: inputs });
|
||||
Reflect.defineMetadata(ACCESS_CLASS_KEY, define, target);
|
||||
target.define = define;
|
||||
accessRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function AccessInput(input?: AccessInputDefine): PropertyDecorator {
|
||||
return (target, propertyKey) => {
|
||||
target = Decorator.target(target, propertyKey);
|
||||
// const _type = Reflect.getMetadata("design:type", target, propertyKey);
|
||||
Reflect.defineMetadata(ACCESS_INPUT_KEY, input, target, propertyKey);
|
||||
};
|
||||
}
|
||||
3
packages/core/pipeline/src/access/index.ts
Normal file
3
packages/core/pipeline/src/access/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./api";
|
||||
export * from "./registry";
|
||||
export * from "./decorator";
|
||||
4
packages/core/pipeline/src/access/registry.ts
Normal file
4
packages/core/pipeline/src/access/registry.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Registry } from "../registry";
|
||||
|
||||
// @ts-ignore
|
||||
export const accessRegistry = new Registry();
|
||||
6
packages/core/pipeline/src/context/index.ts
Normal file
6
packages/core/pipeline/src/context/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
import { IContext } from "../core";
|
||||
|
||||
export type HttpClient = AxiosInstance;
|
||||
export type UserContext = IContext;
|
||||
export type PipelineContext = IContext;
|
||||
88
packages/core/pipeline/src/core/context.ts
Normal file
88
packages/core/pipeline/src/core/context.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { IStorage, MemoryStorage } from "./storage";
|
||||
const CONTEXT_VERSION_KEY = "contextVersion";
|
||||
export interface IContext {
|
||||
getInt(key: string): Promise<number>;
|
||||
get(key: string): Promise<string | null>;
|
||||
set(key: string, value: string): Promise<void>;
|
||||
getObj<T = any>(key: string): Promise<T | null>;
|
||||
setObj<T = any>(key: string, value: T): Promise<void>;
|
||||
updateVersion(): Promise<void>;
|
||||
initVersion(): Promise<void>;
|
||||
}
|
||||
|
||||
export class ContextFactory {
|
||||
storage: IStorage;
|
||||
memoryStorage: IStorage;
|
||||
|
||||
constructor(storage: IStorage) {
|
||||
this.storage = storage;
|
||||
this.memoryStorage = new MemoryStorage();
|
||||
}
|
||||
|
||||
getContext(scope: string, namespace: string): IContext {
|
||||
const context = new StorageContext(scope, namespace, this.storage);
|
||||
return context;
|
||||
}
|
||||
|
||||
getMemoryContext(scope: string, namespace: string): IContext {
|
||||
const context = new StorageContext(scope, namespace, this.memoryStorage);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
export class StorageContext implements IContext {
|
||||
storage: IStorage;
|
||||
namespace: string;
|
||||
scope: string;
|
||||
|
||||
_version = 0;
|
||||
_initialVersion = 0;
|
||||
constructor(scope: string, namespace: string, storage: IStorage) {
|
||||
this.storage = storage;
|
||||
this.scope = scope;
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
async initVersion() {
|
||||
const version = await this.getInt(CONTEXT_VERSION_KEY);
|
||||
this._initialVersion = version;
|
||||
this._version = version;
|
||||
}
|
||||
|
||||
async updateVersion() {
|
||||
if (this._version === this._initialVersion) {
|
||||
this._version++;
|
||||
}
|
||||
|
||||
await this.set(CONTEXT_VERSION_KEY, this._version.toString());
|
||||
}
|
||||
|
||||
async get(key: string) {
|
||||
const version = key === CONTEXT_VERSION_KEY ? 0 : this._version;
|
||||
return await this.storage.get(this.scope, this.namespace, version.toString(), key);
|
||||
}
|
||||
async set(key: string, value: string) {
|
||||
const version = key === CONTEXT_VERSION_KEY ? 0 : this._version;
|
||||
return await this.storage.set(this.scope, this.namespace, version.toString(), key, value);
|
||||
}
|
||||
|
||||
async getInt(key: string): Promise<number> {
|
||||
const str = await this.get(key);
|
||||
if (str) {
|
||||
return parseInt(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
async getObj<T = any>(key: string): Promise<T | null> {
|
||||
const str = await this.get(key);
|
||||
if (str) {
|
||||
const store = JSON.parse(str);
|
||||
return store.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async setObj<T = any>(key: string, value: T) {
|
||||
await this.set(key, JSON.stringify({ value }));
|
||||
}
|
||||
}
|
||||
207
packages/core/pipeline/src/core/executor.ts
Normal file
207
packages/core/pipeline/src/core/executor.ts
Normal file
@@ -0,0 +1,207 @@
|
||||
import { ConcurrencyStrategy, Pipeline, ResultType, Runnable, RunStrategy, Stage, Step, Task } from "../d.ts";
|
||||
import _ from "lodash";
|
||||
import { RunHistory, RunnableCollection } from "./run-history";
|
||||
import { AbstractTaskPlugin, PluginDefine, pluginRegistry } from "../plugin";
|
||||
import { ContextFactory, IContext } from "./context";
|
||||
import { IStorage } from "./storage";
|
||||
import { logger } from "../utils/util.log";
|
||||
import { Logger } from "log4js";
|
||||
import { request } from "../utils/util.request";
|
||||
import { IAccessService } from "../access";
|
||||
import { RegistryItem } from "../registry";
|
||||
import { Decorator } from "../decorator";
|
||||
|
||||
export class Executor {
|
||||
userId: any;
|
||||
pipeline: Pipeline;
|
||||
runtime!: RunHistory;
|
||||
accessService: IAccessService;
|
||||
contextFactory: ContextFactory;
|
||||
logger: Logger;
|
||||
pipelineContext!: IContext;
|
||||
lastStatusMap!: RunnableCollection;
|
||||
onChanged: (history: RunHistory) => void;
|
||||
constructor(options: {
|
||||
userId: any;
|
||||
pipeline: Pipeline;
|
||||
storage: IStorage;
|
||||
onChanged: (history: RunHistory) => Promise<void>;
|
||||
accessService: IAccessService;
|
||||
}) {
|
||||
this.pipeline = _.cloneDeep(options.pipeline);
|
||||
this.onChanged = async (history: RunHistory) => {
|
||||
await options.onChanged(history);
|
||||
};
|
||||
this.accessService = options.accessService;
|
||||
this.userId = options.userId;
|
||||
this.pipeline.userId = this.userId;
|
||||
this.contextFactory = new ContextFactory(options.storage);
|
||||
this.logger = logger;
|
||||
this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id);
|
||||
}
|
||||
|
||||
async init() {
|
||||
const lastRuntime = await this.pipelineContext.getObj(`lastRuntime`);
|
||||
this.lastStatusMap = new RunnableCollection(lastRuntime?.pipeline);
|
||||
}
|
||||
|
||||
async run(runtimeId: any = 0, triggerType: string) {
|
||||
try {
|
||||
await this.init();
|
||||
const trigger = { type: triggerType };
|
||||
// 读取last
|
||||
this.runtime = new RunHistory(runtimeId, trigger, this.pipeline);
|
||||
this.logger.info(`pipeline.${this.pipeline.id} start`);
|
||||
await this.runWithHistory(this.pipeline, "pipeline", async () => {
|
||||
await this.runStages(this.pipeline);
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error("pipeline 执行失败", e);
|
||||
} finally {
|
||||
await this.pipelineContext.setObj("lastRuntime", this.runtime);
|
||||
this.logger.info(`pipeline.${this.pipeline.id} end`);
|
||||
}
|
||||
}
|
||||
|
||||
async runWithHistory(runnable: Runnable, runnableType: string, run: () => Promise<void>) {
|
||||
runnable.runnableType = runnableType;
|
||||
this.runtime.start(runnable);
|
||||
await this.onChanged(this.runtime);
|
||||
|
||||
if (runnable.strategy?.runStrategy === RunStrategy.SkipWhenSucceed) {
|
||||
//如果是成功后跳过策略
|
||||
const lastNode = this.lastStatusMap.get(runnable.id);
|
||||
const lastResult = lastNode?.status?.status;
|
||||
const lastInput = JSON.stringify(lastNode?.status?.input);
|
||||
let inputChanged = false;
|
||||
if (runnableType === "step") {
|
||||
const step = runnable as Step;
|
||||
const input = JSON.stringify(step.input);
|
||||
if (input != null && lastInput !== input) {
|
||||
//参数有变化
|
||||
inputChanged = true;
|
||||
}
|
||||
}
|
||||
if (lastResult != null && lastResult === ResultType.success && !inputChanged) {
|
||||
this.runtime.skip(runnable);
|
||||
await this.onChanged(this.runtime);
|
||||
return ResultType.skip;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await run();
|
||||
this.runtime.success(runnable);
|
||||
await this.onChanged(this.runtime);
|
||||
return ResultType.success;
|
||||
} catch (e: any) {
|
||||
this.runtime.error(runnable, e);
|
||||
await this.onChanged(this.runtime);
|
||||
throw e;
|
||||
} finally {
|
||||
this.runtime.finally(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private async runStages(pipeline: Pipeline) {
|
||||
const resList: ResultType[] = [];
|
||||
for (const stage of pipeline.stages) {
|
||||
const res: ResultType = await this.runWithHistory(stage, "stage", async () => {
|
||||
await this.runStage(stage);
|
||||
});
|
||||
resList.push(res);
|
||||
}
|
||||
return this.compositionResultType(resList);
|
||||
}
|
||||
|
||||
async runStage(stage: Stage) {
|
||||
const runnerList = [];
|
||||
for (const task of stage.tasks) {
|
||||
const runner = this.runWithHistory(task, "task", async () => {
|
||||
await this.runTask(task);
|
||||
});
|
||||
runnerList.push(runner);
|
||||
}
|
||||
|
||||
let resList: ResultType[] = [];
|
||||
if (stage.concurrency === ConcurrencyStrategy.Parallel) {
|
||||
resList = await Promise.all(runnerList);
|
||||
} else {
|
||||
for (let i = 0; i < runnerList.length; i++) {
|
||||
const runner = runnerList[i];
|
||||
resList[i] = await runner;
|
||||
}
|
||||
}
|
||||
return this.compositionResultType(resList);
|
||||
}
|
||||
|
||||
compositionResultType(resList: ResultType[]) {
|
||||
let hasSuccess = false;
|
||||
for (const type of resList) {
|
||||
if (type === ResultType.error) {
|
||||
return ResultType.error;
|
||||
}
|
||||
if (type === ResultType.success) {
|
||||
hasSuccess = true;
|
||||
}
|
||||
}
|
||||
if (hasSuccess) {
|
||||
return ResultType.success;
|
||||
}
|
||||
return ResultType.error;
|
||||
}
|
||||
|
||||
private async runTask(task: Task) {
|
||||
const resList: ResultType[] = [];
|
||||
for (const step of task.steps) {
|
||||
step.runnableType = "step";
|
||||
const res: ResultType = await this.runWithHistory(step, "step", async () => {
|
||||
await this.runStep(step);
|
||||
});
|
||||
resList.push(res);
|
||||
}
|
||||
return this.compositionResultType(resList);
|
||||
}
|
||||
|
||||
private async runStep(step: Step) {
|
||||
const lastStatus = this.lastStatusMap.get(step.id);
|
||||
//执行任务
|
||||
const plugin: RegistryItem<AbstractTaskPlugin> = pluginRegistry.get(step.type);
|
||||
|
||||
// @ts-ignore
|
||||
const instance: ITaskPlugin = new plugin.target();
|
||||
// @ts-ignore
|
||||
const define: PluginDefine = plugin.define;
|
||||
//从outputContext读取输入参数
|
||||
Decorator.inject(define.input, instance, step.input, (item, key) => {
|
||||
if (item.component?.name === "pi-output-selector") {
|
||||
const contextKey = step.input[key];
|
||||
if (contextKey != null) {
|
||||
step.input[key] = this.runtime.context[contextKey];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const context: any = {
|
||||
logger: this.runtime._loggers[step.id],
|
||||
accessService: this.accessService,
|
||||
pipelineContext: this.pipelineContext,
|
||||
lastStatus,
|
||||
userContext: this.contextFactory.getContext("user", this.userId),
|
||||
http: request,
|
||||
};
|
||||
Decorator.inject(define.autowire, instance, context);
|
||||
|
||||
await instance.onInstance();
|
||||
await instance.execute();
|
||||
|
||||
if (instance.result.clearLastStatus) {
|
||||
this.lastStatusMap.clear();
|
||||
}
|
||||
//输出到output context
|
||||
_.forEach(define.output, (item, key) => {
|
||||
step!.status!.output[key] = instance[key];
|
||||
const stepOutputKey = `step.${step.id}.${key}`;
|
||||
this.runtime.context[stepOutputKey] = instance[key];
|
||||
});
|
||||
}
|
||||
}
|
||||
4
packages/core/pipeline/src/core/index.ts
Normal file
4
packages/core/pipeline/src/core/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./executor";
|
||||
export * from "./run-history";
|
||||
export * from "./context";
|
||||
export * from "./storage";
|
||||
158
packages/core/pipeline/src/core/run-history.ts
Normal file
158
packages/core/pipeline/src/core/run-history.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
import { Context, HistoryResult, Pipeline, ResultType, Runnable, RunnableMap, Stage, Step, Task } from "../d.ts";
|
||||
import _ from "lodash";
|
||||
import { buildLogger } from "../utils/util.log";
|
||||
import { Logger } from "log4js";
|
||||
|
||||
export type HistoryStatus = {
|
||||
result: HistoryResult;
|
||||
logs: string[];
|
||||
};
|
||||
|
||||
export type RunTrigger = {
|
||||
type: string; // user , timer
|
||||
};
|
||||
|
||||
export function NewRunHistory(obj: any) {
|
||||
const history = new RunHistory(obj.id, obj.trigger, obj.pipeline);
|
||||
history.context = obj.context;
|
||||
history.logs = obj.logs;
|
||||
history._loggers = obj.loggers;
|
||||
return history;
|
||||
}
|
||||
export class RunHistory {
|
||||
id!: string;
|
||||
//运行时上下文变量
|
||||
context: Context = {};
|
||||
pipeline!: Pipeline;
|
||||
logs: {
|
||||
[runnableId: string]: string[];
|
||||
} = {};
|
||||
_loggers: {
|
||||
[runnableId: string]: Logger;
|
||||
} = {};
|
||||
trigger!: RunTrigger;
|
||||
|
||||
constructor(runtimeId: any, trigger: RunTrigger, pipeline: Pipeline) {
|
||||
this.id = runtimeId;
|
||||
this.pipeline = pipeline;
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
start(runnable: Runnable): HistoryResult {
|
||||
const now = new Date().getTime();
|
||||
this.logs[runnable.id] = [];
|
||||
this._loggers[runnable.id] = buildLogger((text) => {
|
||||
this.logs[runnable.id].push(text);
|
||||
});
|
||||
const input = (runnable as Step).input;
|
||||
const status: HistoryResult = {
|
||||
output: {},
|
||||
input: _.cloneDeep(input),
|
||||
status: ResultType.start,
|
||||
startTime: now,
|
||||
result: ResultType.start,
|
||||
};
|
||||
runnable.status = status;
|
||||
this.log(runnable, `开始执行`);
|
||||
return status;
|
||||
}
|
||||
|
||||
success(runnable: Runnable) {
|
||||
const now = new Date().getTime();
|
||||
const status = runnable.status;
|
||||
_.merge(status, {
|
||||
status: "success",
|
||||
endTime: now,
|
||||
result: "success",
|
||||
});
|
||||
this.log(runnable, `执行成功`);
|
||||
}
|
||||
|
||||
skip(runnable: Runnable) {
|
||||
const now = new Date().getTime();
|
||||
const status = runnable.status;
|
||||
_.merge(status, {
|
||||
status: "success",
|
||||
endTime: now,
|
||||
result: "skip",
|
||||
});
|
||||
this.log(runnable, `跳过`);
|
||||
}
|
||||
|
||||
error(runnable: Runnable, e: Error) {
|
||||
const now = new Date().getTime();
|
||||
const status = runnable.status;
|
||||
_.merge(status, {
|
||||
status: ResultType.error,
|
||||
endTime: now,
|
||||
result: ResultType.error,
|
||||
message: e.message,
|
||||
});
|
||||
|
||||
this.logError(runnable, e);
|
||||
}
|
||||
|
||||
log(runnable: Runnable, text: string) {
|
||||
// @ts-ignore
|
||||
this._loggers[runnable.id].info(`[${runnable.title}]<id:${runnable.id}> [${runnable.runnableType}]`, text);
|
||||
}
|
||||
|
||||
logError(runnable: Runnable, e: Error) {
|
||||
// @ts-ignore
|
||||
this._loggers[runnable.id].error(`[${runnable.title}]<id:${runnable.id}> [${runnable.runnableType}]`, e);
|
||||
}
|
||||
|
||||
finally(runnable: Runnable) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
export class RunnableCollection {
|
||||
private collection: RunnableMap = {};
|
||||
private pipeline!: Pipeline;
|
||||
constructor(pipeline?: Pipeline) {
|
||||
if (!pipeline) {
|
||||
return;
|
||||
}
|
||||
this.pipeline = pipeline;
|
||||
const map = this.toMap(pipeline);
|
||||
this.collection = map;
|
||||
}
|
||||
|
||||
private each<T extends Runnable>(list: T[], exec: (item: Runnable) => void) {
|
||||
list.forEach((item) => {
|
||||
exec(item);
|
||||
if (item.runnableType === "pipeline") {
|
||||
// @ts-ignore
|
||||
this.each<Stage>(item.stages, exec);
|
||||
} else if (item.runnableType === "stage") {
|
||||
// @ts-ignore
|
||||
this.each<Task>(item.tasks, exec);
|
||||
} else if (item.runnableType === "task") {
|
||||
// @ts-ignore
|
||||
this.each<Step>(item.steps, exec);
|
||||
}
|
||||
});
|
||||
}
|
||||
private toMap(pipeline: Pipeline) {
|
||||
const map: RunnableMap = {};
|
||||
|
||||
this.each(pipeline.stages, (item) => {
|
||||
map[item.id] = item;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
get(id: string): Runnable | undefined {
|
||||
return this.collection[id];
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (!this.pipeline) {
|
||||
return;
|
||||
}
|
||||
this.each(this.pipeline.stages, (item) => {
|
||||
item.status = undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
140
packages/core/pipeline/src/core/storage.ts
Normal file
140
packages/core/pipeline/src/core/storage.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
|
||||
|
||||
export interface IStorage {
|
||||
get(scope: string, namespace: string, version: string, key: string): Promise<string | null>;
|
||||
set(scope: string, namespace: string, version: string, key: string, value: string): Promise<void>;
|
||||
remove(scope: string, namespace: string, version: string, key: string): Promise<void>;
|
||||
}
|
||||
|
||||
export class FileStorage implements IStorage {
|
||||
root: string;
|
||||
constructor(rootDir?: string) {
|
||||
if (rootDir == null) {
|
||||
const userHome = process.env.HOME || process.env.USERPROFILE;
|
||||
rootDir = userHome + "/.certd/storage/";
|
||||
}
|
||||
this.root = rootDir;
|
||||
|
||||
if (!fs.existsSync(this.root)) {
|
||||
fs.mkdirSync(this.root, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
async remove(scope: string, namespace: string, version: string, key: string): Promise<void> {
|
||||
if (key) {
|
||||
fs.unlinkSync(this.buildPath(scope, namespace, version, key));
|
||||
} else if (version) {
|
||||
fs.rmdirSync(this.buildPath(scope, namespace, version));
|
||||
} else if (namespace) {
|
||||
fs.rmdirSync(this.buildPath(scope, namespace));
|
||||
} else {
|
||||
fs.rmdirSync(this.buildPath(scope));
|
||||
}
|
||||
}
|
||||
|
||||
writeFile(filePath: string, value: string) {
|
||||
const dir = path.dirname(filePath);
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(filePath, value);
|
||||
return filePath;
|
||||
}
|
||||
|
||||
readFile(filePath: string) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
return fs.readFileSync(filePath).toString();
|
||||
}
|
||||
|
||||
async get(scope: string, namespace: string, version: string, key: string): Promise<string | null> {
|
||||
const path = this.buildPath(scope, namespace, version, key);
|
||||
return this.readFile(path);
|
||||
}
|
||||
|
||||
async set(scope: string, namespace: string, version: string, key: string, value: string): Promise<void> {
|
||||
const path = this.buildPath(scope, namespace, version, key);
|
||||
this.writeFile(path, value);
|
||||
}
|
||||
|
||||
private buildPath(scope: string, namespace?: string, version?: string, key?: string) {
|
||||
if (key) {
|
||||
return `${this.root}/${scope}/${namespace}/${version}/${key}`;
|
||||
} else if (version) {
|
||||
return `${this.root}/${scope}/${namespace}/${version}`;
|
||||
} else if (namespace) {
|
||||
return `${this.root}/${scope}/${namespace}`;
|
||||
} else {
|
||||
return `${this.root}/${scope}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MemoryStorage implements IStorage {
|
||||
/**
|
||||
* 范围: user / pipeline / runtime / task
|
||||
*/
|
||||
scope: any;
|
||||
namespace: any;
|
||||
context: {
|
||||
[scope: string]: {
|
||||
[key: string]: any;
|
||||
};
|
||||
} = {};
|
||||
|
||||
async get(scope: string, namespace: string, version: string, key: string): Promise<string | null> {
|
||||
const scopeContext = this.context[scope];
|
||||
if (scopeContext == null) {
|
||||
return null;
|
||||
}
|
||||
const nsContext = scopeContext[namespace];
|
||||
if (nsContext == null) {
|
||||
return null;
|
||||
}
|
||||
const versionContext = nsContext[version];
|
||||
if (versionContext == null) {
|
||||
return null;
|
||||
}
|
||||
return versionContext[key];
|
||||
}
|
||||
|
||||
async set(scope: string, namespace: string, version: string, key: string, value: string): Promise<void> {
|
||||
let scopeContext = this.context[scope];
|
||||
if (scopeContext == null) {
|
||||
scopeContext = scopeContext[scope];
|
||||
}
|
||||
let nsContext = scopeContext[namespace];
|
||||
if (nsContext == null) {
|
||||
nsContext = {};
|
||||
scopeContext[namespace] = nsContext;
|
||||
}
|
||||
let versionContext = nsContext[version];
|
||||
if (versionContext == null) {
|
||||
versionContext = {};
|
||||
nsContext[version] = versionContext;
|
||||
}
|
||||
versionContext[key] = value;
|
||||
}
|
||||
|
||||
async remove(scope: string, namespace = "", version = "", key = "") {
|
||||
if (key) {
|
||||
if (this.context[scope] && this.context[scope][namespace] && this.context[scope][namespace][version]) {
|
||||
delete this.context[scope][namespace][version][key];
|
||||
}
|
||||
} else if (version) {
|
||||
if (this.context[scope] && this.context[scope][namespace]) {
|
||||
delete this.context[scope][namespace][version];
|
||||
}
|
||||
} else if (namespace) {
|
||||
if (this.context[scope]) {
|
||||
delete this.context[scope][namespace];
|
||||
}
|
||||
} else {
|
||||
delete this.context[scope];
|
||||
}
|
||||
}
|
||||
}
|
||||
115
packages/core/pipeline/src/d.ts/fast-crud.ts
Normal file
115
packages/core/pipeline/src/d.ts/fast-crud.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* [x]-col的配置
|
||||
*/
|
||||
export type ColProps = {
|
||||
span?: number;
|
||||
[props: string]: any;
|
||||
};
|
||||
|
||||
export type FormItemProps = {
|
||||
/**
|
||||
* 字段label
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* 表单字段组件配置
|
||||
*/
|
||||
component?: ComponentProps;
|
||||
/**
|
||||
* 表单字段 [a|el|n]-col的配置
|
||||
* 一般用来配置跨列:{span:24} 占满一行
|
||||
*/
|
||||
col?: ColProps;
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
value?: any;
|
||||
/**
|
||||
* 帮助提示配置
|
||||
*/
|
||||
helper?: string | FormItemHelperProps;
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
order?: number;
|
||||
/**
|
||||
* 是否显示此字段
|
||||
*/
|
||||
show?: boolean;
|
||||
/**
|
||||
* 是否是空白占位栏
|
||||
*/
|
||||
blank?: boolean;
|
||||
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* 表单字段帮助说明配置
|
||||
*/
|
||||
export type FormItemHelperProps = {
|
||||
/**
|
||||
* 自定义渲染帮助说明
|
||||
* @param scope
|
||||
*/
|
||||
render?: (scope: any) => any;
|
||||
/**
|
||||
* 帮助文本
|
||||
*/
|
||||
text?: string;
|
||||
/**
|
||||
* 帮助说明所在的位置,[ undefined | label]
|
||||
*/
|
||||
position?: string;
|
||||
/**
|
||||
* [a|el|n]-tooltip配置
|
||||
*/
|
||||
tooltip?: object;
|
||||
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* 组件配置
|
||||
*/
|
||||
export type ComponentProps = {
|
||||
/**
|
||||
* 组件的名称
|
||||
*/
|
||||
name?: string | object;
|
||||
/**
|
||||
* vmodel绑定的目标属性名
|
||||
*/
|
||||
vModel?: string;
|
||||
|
||||
/**
|
||||
* 当原始组件名的参数被以上属性名占用时,可以配置在这里
|
||||
* 例如:原始组件有一个叫name的属性,你想要配置它,则可以按如下配置
|
||||
* ```
|
||||
* component:{
|
||||
* name:"组件的名称"
|
||||
* props:{
|
||||
* name:"组件的name属性" <-----------
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
props?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* 组件事件监听
|
||||
*/
|
||||
on?: {
|
||||
[key: string]: (context?: any) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* 组件其他参数
|
||||
* 事件:onXxx:(event)=>void 组件原始事件监听
|
||||
* on.onXxx:(context)=>void 组件事件监听(对原始事件包装)
|
||||
* 样式:style、class等
|
||||
*/
|
||||
[key: string]: any;
|
||||
};
|
||||
2
packages/core/pipeline/src/d.ts/index.ts
Normal file
2
packages/core/pipeline/src/d.ts/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./pipeline";
|
||||
export * from "./fast-crud";
|
||||
119
packages/core/pipeline/src/d.ts/pipeline.ts
Normal file
119
packages/core/pipeline/src/d.ts/pipeline.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
export enum RunStrategy {
|
||||
AlwaysRun,
|
||||
SkipWhenSucceed,
|
||||
}
|
||||
|
||||
export enum ConcurrencyStrategy {
|
||||
Serial,
|
||||
Parallel,
|
||||
}
|
||||
|
||||
export enum NextStrategy {
|
||||
AllSuccess,
|
||||
OneSuccess,
|
||||
}
|
||||
|
||||
export enum HandlerType {
|
||||
//清空后续任务的状态
|
||||
ClearFollowStatus,
|
||||
SendEmail,
|
||||
}
|
||||
|
||||
export type EventHandler = {
|
||||
type: HandlerType;
|
||||
params: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
export type RunnableStrategy = {
|
||||
runStrategy?: RunStrategy;
|
||||
onSuccess?: EventHandler[];
|
||||
onError?: EventHandler[];
|
||||
};
|
||||
|
||||
export type Step = Runnable & {
|
||||
type: string; //插件类型
|
||||
input: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
export type Task = Runnable & {
|
||||
steps: Step[];
|
||||
};
|
||||
|
||||
export type Stage = Runnable & {
|
||||
tasks: Task[];
|
||||
concurrency: ConcurrencyStrategy;
|
||||
next: NextStrategy;
|
||||
};
|
||||
|
||||
export type Trigger = {
|
||||
id: string;
|
||||
title: string;
|
||||
cron: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type Runnable = {
|
||||
id: string;
|
||||
title: string;
|
||||
strategy?: RunnableStrategy;
|
||||
runnableType?: string; // pipeline, stage, task , step
|
||||
status?: HistoryResult;
|
||||
default?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
export type Pipeline = Runnable & {
|
||||
version?: number;
|
||||
userId: any;
|
||||
stages: Stage[];
|
||||
triggers: Trigger[];
|
||||
};
|
||||
|
||||
export type Context = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type Log = {
|
||||
title: string;
|
||||
time: number;
|
||||
level: string;
|
||||
text: string;
|
||||
};
|
||||
|
||||
export enum ResultType {
|
||||
start = "start",
|
||||
success = "success",
|
||||
error = "error",
|
||||
skip = "skip",
|
||||
none = "none",
|
||||
}
|
||||
|
||||
export type HistoryResultGroup = {
|
||||
[key: string]: {
|
||||
runnable: Runnable;
|
||||
res: HistoryResult;
|
||||
};
|
||||
};
|
||||
export type HistoryResult = {
|
||||
input: any;
|
||||
output: any;
|
||||
/**
|
||||
* 任务状态
|
||||
*/
|
||||
status: ResultType;
|
||||
startTime: number;
|
||||
endTime?: number;
|
||||
/**
|
||||
* 处理结果
|
||||
*/
|
||||
result?: ResultType; //success, error,skip
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export type RunnableMap = {
|
||||
[id: string]: Runnable;
|
||||
};
|
||||
17
packages/core/pipeline/src/decorator/common.ts
Normal file
17
packages/core/pipeline/src/decorator/common.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Decorator } from "./index";
|
||||
|
||||
export type AutowireProp = {
|
||||
name?: string;
|
||||
type?: any;
|
||||
};
|
||||
export const AUTOWIRE_KEY = "pipeline:autowire";
|
||||
|
||||
export function Autowire(props?: AutowireProp): PropertyDecorator {
|
||||
return (target, propertyKey) => {
|
||||
const _type = Reflect.getMetadata("design:type", target, propertyKey);
|
||||
target = Decorator.target(target, propertyKey);
|
||||
props = props || {};
|
||||
props.type = _type;
|
||||
Reflect.defineMetadata(AUTOWIRE_KEY, props || {}, target, propertyKey);
|
||||
};
|
||||
}
|
||||
2
packages/core/pipeline/src/decorator/index.ts
Normal file
2
packages/core/pipeline/src/decorator/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./utils";
|
||||
export * from "./common";
|
||||
42
packages/core/pipeline/src/decorator/utils.ts
Normal file
42
packages/core/pipeline/src/decorator/utils.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import _ from "lodash";
|
||||
|
||||
const propertyMap: any = {};
|
||||
function attachProperty(target: any, propertyKey: string | symbol) {
|
||||
let props = propertyMap[target];
|
||||
if (props == null) {
|
||||
props = {};
|
||||
propertyMap[target] = props;
|
||||
}
|
||||
props[propertyKey] = true;
|
||||
}
|
||||
|
||||
function getClassProperties(target: any) {
|
||||
return propertyMap[target] || {};
|
||||
}
|
||||
|
||||
function target(target: any, propertyKey?: string | symbol) {
|
||||
if (typeof target === "object" && target.constructor) {
|
||||
target = target.constructor;
|
||||
}
|
||||
if (propertyKey != null) {
|
||||
attachProperty(target, propertyKey);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function inject(define: any, instance: any, context: any, preHandler?: (item: any, key: string, instance: any, context: any) => void) {
|
||||
_.forEach(define, (item, key) => {
|
||||
if (preHandler) {
|
||||
preHandler(item, key, instance, context);
|
||||
}
|
||||
if (context[key] != undefined) {
|
||||
instance[key] = context[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
export const Decorator = {
|
||||
target,
|
||||
attachProperty,
|
||||
getClassProperties,
|
||||
inject,
|
||||
};
|
||||
9
packages/core/pipeline/src/index.ts
Normal file
9
packages/core/pipeline/src/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export * from "./core";
|
||||
export * from "./d.ts";
|
||||
export * from "./access";
|
||||
export * from "./registry";
|
||||
export * from "./plugin";
|
||||
export * from "./utils";
|
||||
export * from "./midway";
|
||||
export * from "./context";
|
||||
export * from "./decorator";
|
||||
52
packages/core/pipeline/src/midway/configuration.ts
Normal file
52
packages/core/pipeline/src/midway/configuration.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Config, Configuration, Inject, Logger } from "@midwayjs/decorator";
|
||||
// @ts-ignore
|
||||
import { ILogger } from "@midwayjs/logger";
|
||||
import { IMidwayContainer, MidwayDecoratorService } from "@midwayjs/core";
|
||||
|
||||
// ... (see below) ...
|
||||
@Configuration({
|
||||
namespace: "pipeline",
|
||||
//importConfigs: [join(__dirname, './config')],
|
||||
})
|
||||
export class PipelineConfiguration {
|
||||
@Config()
|
||||
// @ts-ignore
|
||||
config;
|
||||
@Logger()
|
||||
// @ts-ignore
|
||||
logger: ILogger;
|
||||
|
||||
@Inject()
|
||||
// @ts-ignore
|
||||
decoratorService: MidwayDecoratorService;
|
||||
|
||||
async onReady(container: IMidwayContainer) {
|
||||
this.logger.info("pipeline install");
|
||||
|
||||
//this.implPropertyDecorator(container);
|
||||
this.logger.info("pipeline installed");
|
||||
}
|
||||
|
||||
// implPropertyDecorator(container: IMidwayContainer) {
|
||||
// this.logger.info("初始化 property decorator");
|
||||
// // 实现装饰器
|
||||
// this.decoratorService.registerPropertyHandler(CLASS_INPUTS_KEY, (propertyName, meta) => {
|
||||
// return undefined;
|
||||
// });
|
||||
//
|
||||
// const autowireWhiteList: any = {
|
||||
// logger: true,
|
||||
// };
|
||||
// this.decoratorService.registerPropertyHandler(CLASS_AUTOWIRE_KEY, (propertyName, meta) => {
|
||||
// // eslint-disable-next-line no-debugger
|
||||
// debugger;
|
||||
// const className = meta.name;
|
||||
// if (autowireWhiteList[className]) {
|
||||
// //在白名单里面,注入
|
||||
// return container.get(className);
|
||||
// }
|
||||
// this.logger.warn(`autowire failed:${className} class is not in white list`);
|
||||
// return undefined;
|
||||
// });
|
||||
// }
|
||||
}
|
||||
5
packages/core/pipeline/src/midway/index.ts
Normal file
5
packages/core/pipeline/src/midway/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/index.ts
|
||||
export { PipelineConfiguration } from "./configuration";
|
||||
// export * from './controller/user';
|
||||
// export * from './controller/api';
|
||||
// export * from './service/user';
|
||||
60
packages/core/pipeline/src/plugin/api.ts
Normal file
60
packages/core/pipeline/src/plugin/api.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Registrable } from "../registry";
|
||||
import { FormItemProps } from "../d.ts";
|
||||
|
||||
export enum ContextScope {
|
||||
global,
|
||||
pipeline,
|
||||
runtime,
|
||||
}
|
||||
|
||||
export type Storage = {
|
||||
scope: ContextScope;
|
||||
path: string;
|
||||
};
|
||||
|
||||
export type TaskOutputDefine = {
|
||||
title: string;
|
||||
value?: any;
|
||||
storage?: Storage;
|
||||
};
|
||||
export type TaskInputDefine = FormItemProps;
|
||||
|
||||
export type PluginDefine = Registrable & {
|
||||
default?: any;
|
||||
input?: {
|
||||
[key: string]: TaskInputDefine;
|
||||
};
|
||||
output?: {
|
||||
[key: string]: TaskOutputDefine;
|
||||
};
|
||||
|
||||
autowire?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
export type ITaskPlugin = {
|
||||
onInstance(): Promise<void>;
|
||||
execute(): Promise<void>;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type TaskResult = {
|
||||
clearLastStatus?: boolean;
|
||||
};
|
||||
export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
||||
result: TaskResult = {};
|
||||
clearLastStatus() {
|
||||
this.result.clearLastStatus = true;
|
||||
}
|
||||
async onInstance(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
abstract execute(): Promise<void>;
|
||||
}
|
||||
|
||||
export type OutputVO = {
|
||||
key: string;
|
||||
title: string;
|
||||
value: any;
|
||||
};
|
||||
63
packages/core/pipeline/src/plugin/decorator.ts
Normal file
63
packages/core/pipeline/src/plugin/decorator.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import _ from "lodash";
|
||||
import { pluginRegistry } from "./registry";
|
||||
import { PluginDefine, TaskInputDefine, TaskOutputDefine } from "./api";
|
||||
import { Decorator } from "../decorator";
|
||||
import { AUTOWIRE_KEY } from "../decorator";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const PLUGIN_CLASS_KEY = "pipeline:plugin";
|
||||
|
||||
export function IsTaskPlugin(define: PluginDefine): ClassDecorator {
|
||||
console.log("IsTaskPlugin");
|
||||
return (target: any) => {
|
||||
target = Decorator.target(target);
|
||||
|
||||
const inputs: any = {};
|
||||
const autowires: any = {};
|
||||
const outputs: any = {};
|
||||
const properties = Decorator.getClassProperties(target);
|
||||
for (const property in properties) {
|
||||
const input = Reflect.getMetadata(PLUGIN_INPUT_KEY, target, property);
|
||||
if (input) {
|
||||
inputs[property] = input;
|
||||
}
|
||||
|
||||
const autowire = Reflect.getMetadata(AUTOWIRE_KEY, target, property);
|
||||
if (autowire) {
|
||||
autowires[property] = autowire;
|
||||
}
|
||||
|
||||
const output = Reflect.getMetadata(PLUGIN_OUTPUT_KEY, target, property);
|
||||
if (output) {
|
||||
outputs[property] = output;
|
||||
}
|
||||
}
|
||||
_.merge(define, { input: inputs, autowire: autowires, output: outputs });
|
||||
|
||||
Reflect.defineMetadata(PLUGIN_CLASS_KEY, define, target);
|
||||
|
||||
target.define = define;
|
||||
pluginRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const PLUGIN_INPUT_KEY = "pipeline:plugin:input";
|
||||
|
||||
export function TaskInput(input?: TaskInputDefine): PropertyDecorator {
|
||||
return (target, propertyKey) => {
|
||||
target = Decorator.target(target, propertyKey);
|
||||
Reflect.defineMetadata(PLUGIN_INPUT_KEY, input, target, propertyKey);
|
||||
};
|
||||
}
|
||||
|
||||
// 装饰器内部的唯一 id
|
||||
export const PLUGIN_OUTPUT_KEY = "pipeline:plugin:output";
|
||||
export function TaskOutput(output?: TaskOutputDefine): PropertyDecorator {
|
||||
return (target, propertyKey) => {
|
||||
target = Decorator.target(target, propertyKey);
|
||||
Reflect.defineMetadata(PLUGIN_OUTPUT_KEY, output, target, propertyKey);
|
||||
};
|
||||
}
|
||||
3
packages/core/pipeline/src/plugin/index.ts
Normal file
3
packages/core/pipeline/src/plugin/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./api";
|
||||
export * from "./registry";
|
||||
export * from "./decorator";
|
||||
4
packages/core/pipeline/src/plugin/registry.ts
Normal file
4
packages/core/pipeline/src/plugin/registry.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Registry } from "../registry";
|
||||
import { AbstractTaskPlugin } from "./api";
|
||||
|
||||
export const pluginRegistry = new Registry<AbstractTaskPlugin>();
|
||||
31
packages/core/pipeline/src/plugin/test/echo-plugin.ts
Normal file
31
packages/core/pipeline/src/plugin/test/echo-plugin.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ILogger } from "@midwayjs/logger";
|
||||
import { ITaskPlugin } from "../api";
|
||||
import { IsTaskPlugin, TaskInput } from "../decorator";
|
||||
import { Autowire } from "../../decorator";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "EchoPlugin",
|
||||
title: "测试插件",
|
||||
desc: "test",
|
||||
})
|
||||
export class EchoPlugin implements ITaskPlugin {
|
||||
@TaskInput({
|
||||
title: "测试属性",
|
||||
component: {
|
||||
name: "text",
|
||||
},
|
||||
})
|
||||
test?: string;
|
||||
|
||||
@Autowire()
|
||||
// @ts-ignore
|
||||
logger: ILogger;
|
||||
|
||||
onInstance(): Promise<void> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
}
|
||||
1
packages/core/pipeline/src/registry/index.ts
Normal file
1
packages/core/pipeline/src/registry/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./registry";
|
||||
57
packages/core/pipeline/src/registry/registry.ts
Normal file
57
packages/core/pipeline/src/registry/registry.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
export type Registrable = {
|
||||
name: string;
|
||||
title: string;
|
||||
desc?: string;
|
||||
};
|
||||
|
||||
export type RegistryItem<T> = {
|
||||
define: Registrable;
|
||||
target: T;
|
||||
};
|
||||
export class Registry<T> {
|
||||
storage: {
|
||||
[key: string]: RegistryItem<T>;
|
||||
} = {};
|
||||
|
||||
register(key: string, value: RegistryItem<T>) {
|
||||
if (!key || value == null) {
|
||||
return;
|
||||
}
|
||||
this.storage[key] = value;
|
||||
}
|
||||
|
||||
get(name: string): RegistryItem<T> {
|
||||
if (!name) {
|
||||
throw new Error("插件名称不能为空");
|
||||
}
|
||||
|
||||
const plugin = this.storage[name];
|
||||
if (!plugin) {
|
||||
throw new Error(`插件${name}还未注册`);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
getStorage() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
getDefineList() {
|
||||
const list = [];
|
||||
for (const key in this.storage) {
|
||||
const define = this.getDefine(key);
|
||||
if (define) {
|
||||
list.push({ ...define, key });
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
getDefine(key: string) {
|
||||
const item = this.storage[key];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
return item.define;
|
||||
}
|
||||
}
|
||||
7
packages/core/pipeline/src/utils/index.ts
Normal file
7
packages/core/pipeline/src/utils/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import sleep from "./util.sleep";
|
||||
import { request } from "./util.request";
|
||||
export * from "./util.log";
|
||||
export const utils = {
|
||||
sleep,
|
||||
http: request,
|
||||
};
|
||||
35
packages/core/pipeline/src/utils/util.log.ts
Normal file
35
packages/core/pipeline/src/utils/util.log.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import log4js, { LoggingEvent, Logger } from "log4js";
|
||||
|
||||
const OutputAppender = {
|
||||
configure: (config: any, layouts: any, findAppender: any, levels: any) => {
|
||||
let layout = layouts.basicLayout;
|
||||
if (config.layout) {
|
||||
layout = layouts.layout(config.layout.type, config.layout);
|
||||
}
|
||||
function customAppender(layout: any, timezoneOffset: any) {
|
||||
return (loggingEvent: LoggingEvent) => {
|
||||
if (loggingEvent.context.outputHandler?.write) {
|
||||
const text = `${layout(loggingEvent, timezoneOffset)}\n`;
|
||||
loggingEvent.context.outputHandler.write(text);
|
||||
}
|
||||
};
|
||||
}
|
||||
return customAppender(layout, config.timezoneOffset);
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
log4js.configure({
|
||||
appenders: { std: { type: "stdout" }, output: { type: OutputAppender } },
|
||||
categories: { default: { appenders: ["std"], level: "info" }, pipeline: { appenders: ["std", "output"], level: "info" } },
|
||||
});
|
||||
export const logger = log4js.getLogger("default");
|
||||
|
||||
export function buildLogger(write: (text: string) => void) {
|
||||
const logger = log4js.getLogger("pipeline");
|
||||
logger.addContext("outputHandler", {
|
||||
write,
|
||||
});
|
||||
return logger;
|
||||
}
|
||||
export type ILogger = Logger;
|
||||
58
packages/core/pipeline/src/utils/util.request.ts
Normal file
58
packages/core/pipeline/src/utils/util.request.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import axios from "axios";
|
||||
// @ts-ignore
|
||||
import qs from "qs";
|
||||
import { logger } from "./util.log";
|
||||
/**
|
||||
* @description 创建请求实例
|
||||
*/
|
||||
function createService() {
|
||||
// 创建一个 axios 实例
|
||||
const service = axios.create();
|
||||
// 请求拦截
|
||||
service.interceptors.request.use(
|
||||
(config: any) => {
|
||||
if (config.formData) {
|
||||
config.data = qs.stringify(config.formData, {
|
||||
arrayFormat: "indices",
|
||||
allowDots: true,
|
||||
}); // 序列化请求参数
|
||||
delete config.formData;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error: Error) => {
|
||||
// 发送失败
|
||||
logger.error(error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
// 响应拦截
|
||||
service.interceptors.response.use(
|
||||
(response: any) => {
|
||||
logger.info("http response:", JSON.stringify(response.data));
|
||||
return response.data;
|
||||
},
|
||||
(error: any) => {
|
||||
// const status = _.get(error, 'response.status')
|
||||
// switch (status) {
|
||||
// case 400: error.message = '请求错误'; break
|
||||
// case 401: error.message = '未授权,请登录'; break
|
||||
// case 403: error.message = '拒绝访问'; break
|
||||
// case 404: error.message = `请求地址出错: ${error.response.config.url}`; break
|
||||
// case 408: error.message = '请求超时'; break
|
||||
// case 500: error.message = '服务器内部错误'; break
|
||||
// case 501: error.message = '服务未实现'; break
|
||||
// case 502: error.message = '网关错误'; break
|
||||
// case 503: error.message = '服务不可用'; break
|
||||
// case 504: error.message = '网关超时'; break
|
||||
// case 505: error.message = 'HTTP版本不受支持'; break
|
||||
// default: break
|
||||
// }
|
||||
logger.error("请求出错:", error.response.config.url, error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
return service;
|
||||
}
|
||||
|
||||
export const request = createService();
|
||||
7
packages/core/pipeline/src/utils/util.sleep.ts
Normal file
7
packages/core/pipeline/src/utils/util.sleep.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export default function (timeout: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({});
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
58
packages/core/pipeline/test/cert.fake.test.ts
Normal file
58
packages/core/pipeline/test/cert.fake.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
export const fakeCrt = `-----BEGIN CERTIFICATE-----
|
||||
MIIFSTCCBDGgAwIBAgITAPoZZk/LhVIyXoic2NnJyxubezANBgkqhkiG9w0BAQsF
|
||||
ADAiMSAwHgYDVQQDDBdGYWtlIExFIEludGVybWVkaWF0ZSBYMTAeFw0yMDEyMTQx
|
||||
NjA1NTFaFw0yMTAzMTQxNjA1NTFaMBsxGTAXBgNVBAMMECouZG9jbWlycm9yLmNs
|
||||
dWIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC75tGrYjly+RpcZehQ
|
||||
my1EpaXElT4L60pINKV2YDKnBrcSSo1c6rO7nFh12eC/ju4WwYUep0RVmBDF8xD0
|
||||
I1Sd1uuDTQWP0UT1X9yqdXtjvxpUqoCHAzG633f3sJRFul7mDLuC9tRCuae9o7qP
|
||||
EZ827XOmjBR35dso9I2GEE4828J3YE3tSKtobZlM+30jozLEcsO0PTyM5mq5PPjP
|
||||
VI3fGLcEaBmLZf5ixz4XkcY9IAhyAMYf03cT2wRoYPBaDdXblgCYL6sFtIMbzl3M
|
||||
Di94PB8NyoNSsC2nmBdWi54wFOgBvY/4ljsX/q7X3EqlSvcA0/M6/c/J9kJ3eupv
|
||||
jV8nAgMBAAGjggJ9MIICeTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYB
|
||||
BQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFAkdTjSCV3KD
|
||||
x28sf98MrwVfyFYgMB8GA1UdIwQYMBaAFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHcG
|
||||
CCsGAQUFBwEBBGswaTAyBggrBgEFBQcwAYYmaHR0cDovL29jc3Auc3RnLWludC14
|
||||
MS5sZXRzZW5jcnlwdC5vcmcwMwYIKwYBBQUHMAKGJ2h0dHA6Ly9jZXJ0LnN0Zy1p
|
||||
bnQteDEubGV0c2VuY3J5cHQub3JnLzArBgNVHREEJDAighAqLmRvY21pcnJvci5j
|
||||
bHVigg5kb2NtaXJyb3IuY2x1YjBMBgNVHSAERTBDMAgGBmeBDAECATA3BgsrBgEE
|
||||
AYLfEwEBATAoMCYGCCsGAQUFBwIBFhpodHRwOi8vY3BzLmxldHNlbmNyeXB0Lm9y
|
||||
ZzCCAQQGCisGAQQB1nkCBAIEgfUEgfIA8AB1ABboacHRlerXw/iXGuPwdgH3jOG2
|
||||
nTGoUhi2g38xqBUIAAABdmI3LM4AAAQDAEYwRAIgaiNqXSEq+sxp8eqlJXp/KFdO
|
||||
so5mT50MoRsLF8Inu0ACIDP46+ekng7I0BlmyIPmbqFcZgnZFVWLLCdLYijhVyOL
|
||||
AHcA3Zk0/KXnJIDJVmh9gTSZCEmySfe1adjHvKs/XMHzbmQAAAF2YjcuxwAABAMA
|
||||
SDBGAiEAxpeB8/w4YkHZ62nH20h128VtuTSmYDCnF7EK2fQyeZYCIQDbJlF2wehZ
|
||||
sF1BeE7qnYYqCTP0dYIrQ9HWtBa/MbGOKTANBgkqhkiG9w0BAQsFAAOCAQEAL2di
|
||||
HKh6XcZtGk0BFxJa51sCZ3MLu9+Zy90kCRD4ooP5x932WxVM25+LBRd+xSzx+TRL
|
||||
UVrlKp9GdMYX1JXL4Vf2NwzuFO3snPDe/qizD/3+D6yo8eKJ/LD82t5kLWAD2rto
|
||||
YfVSTKwfNIBBJwHUnjviBPJmheHHCKmz8Ct6/6QxFAeta9TAMn0sFeVCQnmAq7HL
|
||||
jrunq0tNHR/EKG0ITPLf+6P7MxbmpYNnq918766l0tKsW8oo8ZSGEwKU2LMaSiAa
|
||||
hasyl/2gMnYXjtKOjDcnR8oLpbrOg0qpVbynmJin1HP835oHPPAZ1gLsqYTTizNz
|
||||
AHxTaXliTVvS83dogw==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEqzCCApOgAwIBAgIRAIvhKg5ZRO08VGQx8JdhT+UwDQYJKoZIhvcNAQELBQAw
|
||||
GjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDUyMzIyMDc1OVoXDTM2
|
||||
MDUyMzIyMDc1OVowIjEgMB4GA1UEAwwXRmFrZSBMRSBJbnRlcm1lZGlhdGUgWDEw
|
||||
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtWKySDn7rWZc5ggjz3ZB0
|
||||
8jO4xti3uzINfD5sQ7Lj7hzetUT+wQob+iXSZkhnvx+IvdbXF5/yt8aWPpUKnPym
|
||||
oLxsYiI5gQBLxNDzIec0OIaflWqAr29m7J8+NNtApEN8nZFnf3bhehZW7AxmS1m0
|
||||
ZnSsdHw0Fw+bgixPg2MQ9k9oefFeqa+7Kqdlz5bbrUYV2volxhDFtnI4Mh8BiWCN
|
||||
xDH1Hizq+GKCcHsinDZWurCqder/afJBnQs+SBSL6MVApHt+d35zjBD92fO2Je56
|
||||
dhMfzCgOKXeJ340WhW3TjD1zqLZXeaCyUNRnfOmWZV8nEhtHOFbUCU7r/KkjMZO9
|
||||
AgMBAAGjgeMwgeAwDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAw
|
||||
HQYDVR0OBBYEFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHoGCCsGAQUFBwEBBG4wbDA0
|
||||
BggrBgEFBQcwAYYoaHR0cDovL29jc3Auc3RnLXJvb3QteDEubGV0c2VuY3J5cHQu
|
||||
b3JnLzA0BggrBgEFBQcwAoYoaHR0cDovL2NlcnQuc3RnLXJvb3QteDEubGV0c2Vu
|
||||
Y3J5cHQub3JnLzAfBgNVHSMEGDAWgBTBJnSkikSg5vogKNhcI5pFiBh54DANBgkq
|
||||
hkiG9w0BAQsFAAOCAgEABYSu4Il+fI0MYU42OTmEj+1HqQ5DvyAeyCA6sGuZdwjF
|
||||
UGeVOv3NnLyfofuUOjEbY5irFCDtnv+0ckukUZN9lz4Q2YjWGUpW4TTu3ieTsaC9
|
||||
AFvCSgNHJyWSVtWvB5XDxsqawl1KzHzzwr132bF2rtGtazSqVqK9E07sGHMCf+zp
|
||||
DQVDVVGtqZPHwX3KqUtefE621b8RI6VCl4oD30Olf8pjuzG4JKBFRFclzLRjo/h7
|
||||
IkkfjZ8wDa7faOjVXx6n+eUQ29cIMCzr8/rNWHS9pYGGQKJiY2xmVC9h12H99Xyf
|
||||
zWE9vb5zKP3MVG6neX1hSdo7PEAb9fqRhHkqVsqUvJlIRmvXvVKTwNCP3eCjRCCI
|
||||
PTAvjV+4ni786iXwwFYNz8l3PmPLCyQXWGohnJ8iBm+5nk7O2ynaPVW0U2W+pt2w
|
||||
SVuvdDM5zGv2f9ltNWUiYZHJ1mmO97jSY/6YfdOUH66iRtQtDkHBRdkNBsMbD+Em
|
||||
2TgBldtHNSJBfB3pm9FblgOcJ0FSWcUDWJ7vO0+NTXlgrRofRT6pVywzxVo6dND0
|
||||
WzYlTWeUVsO40xJqhgUQRER9YLOLxJ0O6C8i0xFxAMKOtSdodMB3RIwt7RFQ0uyt
|
||||
n5Z5MqkYhlMI3J1tPRTp1nEt9fyGspBOO05gi148Qasp+3N+svqKomoQglNoAxU=
|
||||
-----END CERTIFICATE-----`;
|
||||
30
packages/core/pipeline/test/echo-plugin.ts
Normal file
30
packages/core/pipeline/test/echo-plugin.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Autowire, ILogger, IsTaskPlugin, ITaskPlugin, TaskInput, TaskOutput } from "../src";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "EchoPlugin",
|
||||
title: "测试插件【echo】",
|
||||
})
|
||||
export class EchoPlugin implements ITaskPlugin {
|
||||
@TaskInput({
|
||||
title: "cert",
|
||||
component: {
|
||||
name: "pi-output-selector",
|
||||
},
|
||||
helper: "输出选择",
|
||||
})
|
||||
cert!: any;
|
||||
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
|
||||
@TaskOutput({
|
||||
title: "cert info",
|
||||
})
|
||||
certInfo!: any;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
async onInstance(): Promise<void> {}
|
||||
async execute(): Promise<void> {
|
||||
console.log("input :cert", this.cert);
|
||||
}
|
||||
}
|
||||
16
packages/core/pipeline/test/index.test.ts
Normal file
16
packages/core/pipeline/test/index.test.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { EchoPlugin } from "./echo-plugin";
|
||||
describe("task_plugin", function () {
|
||||
it("#taskplugin", function () {
|
||||
console.log("before new plugin");
|
||||
const echoPlugin = new EchoPlugin();
|
||||
console.log("before set property", echoPlugin);
|
||||
echoPlugin.cert = { test: 1 };
|
||||
console.log("before execute");
|
||||
// @ts-ignore
|
||||
echoPlugin.execute();
|
||||
console.log("after execute");
|
||||
expect(echoPlugin.cert.test).eq(1);
|
||||
});
|
||||
});
|
||||
10
packages/core/pipeline/test/pipeline/access-service-test.ts
Normal file
10
packages/core/pipeline/test/pipeline/access-service-test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IAccess, IAccessService } from "../../src";
|
||||
// @ts-ignore
|
||||
import { aliyunSecret } from "../user.secret";
|
||||
export class AccessServiceTest implements IAccessService {
|
||||
async getById(id: any): Promise<IAccess> {
|
||||
return {
|
||||
...aliyunSecret,
|
||||
} as any;
|
||||
}
|
||||
}
|
||||
15
packages/core/pipeline/test/pipeline/init.test.ts
Normal file
15
packages/core/pipeline/test/pipeline/init.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ContextFactory } from "../../src/core/context";
|
||||
import { FileStorage } from "../../src/core/storage";
|
||||
import { AccessServiceTest } from "./access-service-test";
|
||||
import { logger } from "../../src/utils/util.log";
|
||||
|
||||
const contextFactory = new ContextFactory(new FileStorage());
|
||||
|
||||
const userContext = contextFactory.getContext("user", "test");
|
||||
const pipelineContext = contextFactory.getContext("pipeline", "test");
|
||||
export const pluginInitProps = {
|
||||
accessService: new AccessServiceTest(),
|
||||
pipelineContext: pipelineContext,
|
||||
userContext: userContext,
|
||||
logger: logger,
|
||||
};
|
||||
66
packages/core/pipeline/test/pipeline/pipeline.define.ts
Normal file
66
packages/core/pipeline/test/pipeline/pipeline.define.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { ConcurrencyStrategy, NextStrategy, Pipeline, RunStrategy } from "../../src";
|
||||
|
||||
let idIndex = 0;
|
||||
function generateId() {
|
||||
idIndex++;
|
||||
return idIndex + "";
|
||||
}
|
||||
export const pipeline: Pipeline = {
|
||||
version: 1,
|
||||
id: generateId(),
|
||||
title: "测试管道",
|
||||
userId: 1,
|
||||
triggers: [],
|
||||
stages: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "证书申请阶段",
|
||||
concurrency: ConcurrencyStrategy.Serial,
|
||||
next: NextStrategy.AllSuccess,
|
||||
tasks: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "申请证书任务",
|
||||
steps: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "申请证书",
|
||||
type: "CertApply",
|
||||
input: {
|
||||
domains: ["*.docmirror.cn"],
|
||||
email: "xiaojunnuo@qq.com",
|
||||
dnsProviderType: "aliyun",
|
||||
accessId: "111",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: generateId(),
|
||||
title: "证书部署阶段",
|
||||
concurrency: ConcurrencyStrategy.Serial,
|
||||
next: NextStrategy.AllSuccess,
|
||||
tasks: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "测试输出参数任务",
|
||||
steps: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "输出参数(echo插件)",
|
||||
type: "EchoPlugin",
|
||||
input: {
|
||||
cert: "cert",
|
||||
},
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
18
packages/core/pipeline/test/pipeline/pipeline.test.ts
Normal file
18
packages/core/pipeline/test/pipeline/pipeline.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
//import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { Executor, RunHistory } from "../../src";
|
||||
import { pipeline } from "./pipeline.define";
|
||||
import { AccessServiceTest } from "./access-service-test";
|
||||
import { FileStorage } from "../../src/core/storage";
|
||||
describe("pipeline", function () {
|
||||
it("#pipeline", async function () {
|
||||
this.timeout(120000);
|
||||
async function onChanged(history: RunHistory) {
|
||||
console.log("changed:");
|
||||
}
|
||||
|
||||
const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() });
|
||||
await executor.run(1, "user");
|
||||
// expect(define.name).eq("EchoPlugin");
|
||||
});
|
||||
});
|
||||
20
packages/core/pipeline/tsconfig.json
Normal file
20
packages/core/pipeline/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"outDir": "./dist/ts"
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue","test/**/*.ts"],
|
||||
}
|
||||
35
packages/core/pipeline/vite.config.js
Normal file
35
packages/core/pipeline/vite.config.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { defineConfig } from "vite";
|
||||
import typescript from "@rollup/plugin-typescript";
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [],
|
||||
build: {
|
||||
lib: {
|
||||
entry: "src/index.ts",
|
||||
name: "pipeline",
|
||||
},
|
||||
rollupOptions: {
|
||||
plugins: [
|
||||
typescript({
|
||||
target: "esnext",
|
||||
rootDir: "src",
|
||||
declaration: true,
|
||||
declarationDir: "dist/d",
|
||||
exclude: ["./node_modules/**", "./src/**/*.vue"],
|
||||
allowSyntheticDefaultImports: true,
|
||||
}),
|
||||
],
|
||||
external: ["vue", "lodash", "dayjs", "@fast-crud/fast-crud"],
|
||||
output: {
|
||||
// Provide global variables to use in the UMD build
|
||||
// for externalized deps
|
||||
globals: {
|
||||
vue: "Vue",
|
||||
lodash: "_",
|
||||
dayjs: "dayjs",
|
||||
"@fast-crud/fast-crud": "FastCrud",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
22
packages/plugins/plugin-aliyun/.eslintrc
Normal file
22
packages/plugins/plugin-aliyun/.eslintrc
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
// "no-unused-expressions": "off",
|
||||
"max-len": [0, 160, 2, { "ignoreUrls": true }]
|
||||
}
|
||||
}
|
||||
26
packages/plugins/plugin-aliyun/.gitignore
vendored
Normal file
26
packages/plugins/plugin-aliyun/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
test/user.secret.ts
|
||||
5
packages/plugins/plugin-aliyun/.mocharc.json
Normal file
5
packages/plugins/plugin-aliyun/.mocharc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "test/**/*.test.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
||||
3
packages/plugins/plugin-aliyun/.prettierrc
Normal file
3
packages/plugins/plugin-aliyun/.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printWidth": 160
|
||||
}
|
||||
8
packages/plugins/plugin-aliyun/CHANGELOG.md
Normal file
8
packages/plugins/plugin-aliyun/CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.1](https://github.com/certd/certd/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-aliyun
|
||||
16
packages/plugins/plugin-aliyun/README.md
Normal file
16
packages/plugins/plugin-aliyun/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
|
||||
## Type Support For `.vue` Imports in TS
|
||||
|
||||
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
|
||||
|
||||
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
|
||||
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
|
||||
|
||||
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
|
||||
1
packages/plugins/plugin-aliyun/index.ts
Normal file
1
packages/plugins/plugin-aliyun/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src";
|
||||
56
packages/plugins/plugin-aliyun/package.json
Normal file
56
packages/plugins/plugin-aliyun/package.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "@certd/plugin-aliyun",
|
||||
"private": false,
|
||||
"version": "1.0.1",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"publishConfig": {
|
||||
"main": "./dist/plugin-aliyun.umd.js",
|
||||
"module": "./dist/plugin-aliyun.mjs",
|
||||
"types": "./dist/es/plugin-aliyun.d.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alicloud/cs20151215": "^3.0.3",
|
||||
"@alicloud/openapi-client": "^0.4.0",
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@certd/acme-client": "^1.0.1",
|
||||
"@certd/pipeline": "^1.0.1",
|
||||
"@certd/plugin-cert": "^1.0.1",
|
||||
"@certd/plugin-util": "^1.0.1",
|
||||
"dayjs": "^1.11.6",
|
||||
"lodash": "^4.17.21",
|
||||
"node-forge": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@alicloud/cs20151215": "^3.0.3",
|
||||
"@alicloud/openapi-client": "^0.4.0",
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@midwayjs/core": "^3.0.0",
|
||||
"@midwayjs/decorator": "^3.0.0",
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/lodash": "^4.14.186",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node-forge": "^1.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||
"@typescript-eslint/parser": "^5.38.1",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"log4js": "^6.7.1",
|
||||
"mocha": "^10.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.4",
|
||||
"vite": "^3.1.0",
|
||||
"vue-tsc": "^0.38.9"
|
||||
},
|
||||
"gitHead": "5950e1cae7cf30ebfc5128c15c7d1b0d101cbbb8"
|
||||
}
|
||||
27
packages/plugins/plugin-aliyun/src/access/aliyun-access.ts
Normal file
27
packages/plugins/plugin-aliyun/src/access/aliyun-access.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { IsAccess, AccessInput } from "@certd/pipeline";
|
||||
|
||||
@IsAccess({
|
||||
name: "aliyun",
|
||||
title: "阿里云授权",
|
||||
desc: "",
|
||||
})
|
||||
export class AliyunAccess {
|
||||
@AccessInput({
|
||||
title: "accessKeyId",
|
||||
component: {
|
||||
placeholder: "accessKeyId",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessKeyId = "";
|
||||
@AccessInput({
|
||||
title: "accessKeySecret",
|
||||
component: {
|
||||
placeholder: "accessKeySecret",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessKeySecret = "";
|
||||
}
|
||||
|
||||
new AliyunAccess();
|
||||
1
packages/plugins/plugin-aliyun/src/access/index.ts
Normal file
1
packages/plugins/plugin-aliyun/src/access/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./aliyun-access";
|
||||
@@ -0,0 +1,124 @@
|
||||
import Core from "@alicloud/pop-core";
|
||||
import _ from "lodash";
|
||||
import { CreateRecordOptions, IDnsProvider, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, ILogger } from "@certd/pipeline";
|
||||
import { AliyunAccess } from "../access";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: "aliyun",
|
||||
title: "阿里云",
|
||||
desc: "阿里云DNS解析提供商",
|
||||
accessType: "aliyun",
|
||||
})
|
||||
export class AliyunDnsProvider implements IDnsProvider {
|
||||
client: any;
|
||||
@Autowire()
|
||||
access!: AliyunAccess;
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
async onInstance() {
|
||||
const access: any = this.access;
|
||||
this.client = new Core({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
endpoint: "https://alidns.aliyuncs.com",
|
||||
apiVersion: "2015-01-09",
|
||||
});
|
||||
}
|
||||
|
||||
async getDomainList() {
|
||||
const params = {
|
||||
RegionId: "cn-hangzhou",
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
const ret = await this.client.request("DescribeDomains", params, requestOption);
|
||||
return ret.Domains.Domain;
|
||||
}
|
||||
|
||||
async matchDomain(dnsRecord: string) {
|
||||
const list = await this.getDomainList();
|
||||
let domain = null;
|
||||
for (const item of list) {
|
||||
if (_.endsWith(dnsRecord, item.DomainName)) {
|
||||
domain = item.DomainName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!domain) {
|
||||
throw new Error("can not find Domain ," + dnsRecord);
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
async getRecords(domain: string, rr: string, value: string) {
|
||||
const params: any = {
|
||||
RegionId: "cn-hangzhou",
|
||||
DomainName: domain,
|
||||
RRKeyWord: rr,
|
||||
ValueKeyWord: undefined,
|
||||
};
|
||||
if (value) {
|
||||
params.ValueKeyWord = value;
|
||||
}
|
||||
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
const ret = await this.client.request("DescribeDomainRecords", params, requestOption);
|
||||
return ret.DomainRecords.Record;
|
||||
}
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value);
|
||||
const domain = await this.matchDomain(fullRecord);
|
||||
const rr = fullRecord.replace("." + domain, "");
|
||||
|
||||
const params = {
|
||||
RegionId: "cn-hangzhou",
|
||||
DomainName: domain,
|
||||
RR: rr,
|
||||
Type: type,
|
||||
Value: value,
|
||||
// Line: 'oversea' // 海外
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
try {
|
||||
const ret = await this.client.request("AddDomainRecord", params, requestOption);
|
||||
this.logger.info("添加域名解析成功:", value, value, ret.RecordId);
|
||||
return ret.RecordId;
|
||||
} catch (e: any) {
|
||||
if (e.code === "DomainRecordDuplicate") {
|
||||
return;
|
||||
}
|
||||
this.logger.info("添加域名解析出错", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
async removeRecord(options: RemoveRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, record } = options;
|
||||
const params = {
|
||||
RegionId: "cn-hangzhou",
|
||||
RecordId: record,
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
const ret = await this.client.request("DeleteDomainRecord", params, requestOption);
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value, ret.RecordId);
|
||||
return ret.RecordId;
|
||||
}
|
||||
}
|
||||
|
||||
new AliyunDnsProvider();
|
||||
1
packages/plugins/plugin-aliyun/src/dns-provider/index.ts
Normal file
1
packages/plugins/plugin-aliyun/src/dns-provider/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
import "./aliyun-dns-provider";
|
||||
3
packages/plugins/plugin-aliyun/src/index.ts
Normal file
3
packages/plugins/plugin-aliyun/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./access";
|
||||
export * from "./dns-provider";
|
||||
export * from "./plugin";
|
||||
@@ -0,0 +1,230 @@
|
||||
import { AbstractTaskPlugin, Autowire, IAccessService, ILogger, IsTaskPlugin, RunStrategy, TaskInput, utils } from "@certd/pipeline";
|
||||
// @ts-ignore
|
||||
import { ROAClient } from "@alicloud/pop-core";
|
||||
import { AliyunAccess } from "../../access";
|
||||
import { K8sClient } from "@certd/plugin-util";
|
||||
import { appendTimeSuffix } from "../../utils";
|
||||
import { CertInfo } from "@certd/plugin-cert";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "DeployCertToAliyunAckIngress",
|
||||
title: "部署到阿里云AckIngress",
|
||||
input: {},
|
||||
output: {},
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class DeployCertToAliyunAckIngressPlugin extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: "集群id",
|
||||
component: {
|
||||
placeholder: "集群id",
|
||||
},
|
||||
})
|
||||
clusterId!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "保密字典Id",
|
||||
component: {
|
||||
placeholder: "保密字典Id",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
secretName!: string | string[];
|
||||
|
||||
@TaskInput({
|
||||
title: "大区",
|
||||
value: "cn-shanghai",
|
||||
component: {
|
||||
placeholder: "集群所属大区",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
regionId!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "命名空间",
|
||||
value: "default",
|
||||
component: {
|
||||
placeholder: "命名空间",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
namespace!: string;
|
||||
@TaskInput({
|
||||
title: "ingress名称",
|
||||
value: "",
|
||||
component: {
|
||||
placeholder: "ingress名称",
|
||||
},
|
||||
required: true,
|
||||
helper: "可以传入一个数组",
|
||||
})
|
||||
ingressName!: string;
|
||||
@TaskInput({
|
||||
title: "ingress类型",
|
||||
value: "nginx",
|
||||
component: {
|
||||
placeholder: "暂时只支持nginx类型",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
ingressClass!: string;
|
||||
@TaskInput({
|
||||
title: "是否私网ip",
|
||||
value: false,
|
||||
component: {
|
||||
placeholder: "集群连接端点是否是私网ip",
|
||||
},
|
||||
helper: "如果您当前certd运行在同一个私网下,可以选择是。",
|
||||
required: true,
|
||||
})
|
||||
isPrivateIpAddress!: boolean;
|
||||
@TaskInput({
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: "pi-output-selector",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: CertInfo;
|
||||
@TaskInput({
|
||||
title: "Access授权",
|
||||
helper: "阿里云授权AccessKeyId、AccessKeySecret",
|
||||
component: {
|
||||
name: "pi-access-selector",
|
||||
type: "aliyun",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
@Autowire()
|
||||
accessService!: IAccessService;
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
|
||||
async execute(): Promise<void> {
|
||||
console.log("开始部署证书到阿里云cdn");
|
||||
const { regionId, ingressClass, clusterId, isPrivateIpAddress, cert } = this;
|
||||
const access = (await this.accessService.getById(this.accessId)) as AliyunAccess;
|
||||
const client = this.getClient(access, regionId);
|
||||
const kubeConfigStr = await this.getKubeConfig(client, clusterId, isPrivateIpAddress);
|
||||
|
||||
this.logger.info("kubeconfig已成功获取");
|
||||
const k8sClient = new K8sClient(kubeConfigStr);
|
||||
const ingressType = ingressClass || "qcloud";
|
||||
if (ingressType === "qcloud") {
|
||||
throw new Error("暂未实现");
|
||||
// await this.patchQcloudCertSecret({ k8sClient, props, context })
|
||||
} else {
|
||||
await this.patchNginxCertSecret({ cert, k8sClient });
|
||||
}
|
||||
|
||||
await utils.sleep(3000); // 停留2秒,等待secret部署完成
|
||||
// await this.restartIngress({ k8sClient, props })
|
||||
}
|
||||
|
||||
async restartIngress(options: { k8sClient: any }) {
|
||||
const { k8sClient } = options;
|
||||
const { namespace } = this;
|
||||
|
||||
const body = {
|
||||
metadata: {
|
||||
labels: {
|
||||
certd: appendTimeSuffix("certd"),
|
||||
},
|
||||
},
|
||||
};
|
||||
const ingressList = await k8sClient.getIngressList({ namespace });
|
||||
console.log("ingressList:", ingressList);
|
||||
if (!ingressList || !ingressList.body || !ingressList.body.items) {
|
||||
return;
|
||||
}
|
||||
const ingressNames = ingressList.body.items
|
||||
.filter((item: any) => {
|
||||
if (!item.spec.tls) {
|
||||
return false;
|
||||
}
|
||||
for (const tls of item.spec.tls) {
|
||||
if (tls.secretName === this.secretName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.map((item: any) => {
|
||||
return item.metadata.name;
|
||||
});
|
||||
for (const ingress of ingressNames) {
|
||||
await k8sClient.patchIngress({ namespace, ingressName: ingress, body });
|
||||
this.logger.info(`ingress已重启:${ingress}`);
|
||||
}
|
||||
}
|
||||
|
||||
async patchNginxCertSecret(options: { cert: any; k8sClient: any }) {
|
||||
const { cert, k8sClient } = options;
|
||||
const crt = cert.crt;
|
||||
const key = cert.key;
|
||||
const crtBase64 = Buffer.from(crt).toString("base64");
|
||||
const keyBase64 = Buffer.from(key).toString("base64");
|
||||
|
||||
const { namespace, secretName } = this;
|
||||
|
||||
const body = {
|
||||
data: {
|
||||
"tls.crt": crtBase64,
|
||||
"tls.key": keyBase64,
|
||||
},
|
||||
metadata: {
|
||||
labels: {
|
||||
certd: appendTimeSuffix("certd"),
|
||||
},
|
||||
},
|
||||
};
|
||||
let secretNames: any = secretName;
|
||||
if (typeof secretName === "string") {
|
||||
secretNames = [secretName];
|
||||
}
|
||||
for (const secret of secretNames) {
|
||||
await k8sClient.patchSecret({ namespace, secretName: secret, body });
|
||||
this.logger.info(`CertSecret已更新:${secret}`);
|
||||
}
|
||||
}
|
||||
|
||||
getClient(aliyunProvider: any, regionId: string) {
|
||||
return new ROAClient({
|
||||
accessKeyId: aliyunProvider.accessKeyId,
|
||||
accessKeySecret: aliyunProvider.accessKeySecret,
|
||||
endpoint: `https://cs.${regionId}.aliyuncs.com`,
|
||||
apiVersion: "2015-12-15",
|
||||
});
|
||||
}
|
||||
|
||||
async getKubeConfig(client: any, clusterId: string, isPrivateIpAddress = false) {
|
||||
const httpMethod = "GET";
|
||||
const uriPath = `/k8s/${clusterId}/user_config`;
|
||||
const queries = {
|
||||
PrivateIpAddress: isPrivateIpAddress,
|
||||
};
|
||||
const body = "{}";
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
const requestOption = {};
|
||||
|
||||
try {
|
||||
const res = await client.request(httpMethod, uriPath, queries, body, headers, requestOption);
|
||||
return res.config;
|
||||
} catch (e) {
|
||||
console.error("请求出错:", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new DeployCertToAliyunAckIngressPlugin();
|
||||
106
packages/plugins/plugin-aliyun/src/plugin/deploy-to-cdn/index.ts
Normal file
106
packages/plugins/plugin-aliyun/src/plugin/deploy-to-cdn/index.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { AbstractTaskPlugin, Autowire, IAccessService, ILogger, IsTaskPlugin, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||
import dayjs from "dayjs";
|
||||
import Core from "@alicloud/pop-core";
|
||||
import RPCClient from "@alicloud/pop-core";
|
||||
import { AliyunAccess } from "../../access";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "DeployCertToAliyunCDN",
|
||||
title: "部署证书至阿里云CDN",
|
||||
desc: "依赖证书申请前置任务,自动部署域名证书至阿里云CDN",
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class DeployCertToAliyunCDN extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: "CDN加速域名",
|
||||
helper: "你在阿里云上配置的CDN加速域名,比如certd.docmirror.cn",
|
||||
required: true,
|
||||
})
|
||||
domainName!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "证书名称",
|
||||
helper: "上传后将以此名称作为前缀备注",
|
||||
})
|
||||
certName!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: "pi-output-selector",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "Access授权",
|
||||
helper: "阿里云授权AccessKeyId、AccessKeySecret",
|
||||
component: {
|
||||
name: "pi-access-selector",
|
||||
type: "aliyun",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
@Autowire()
|
||||
accessService!: IAccessService;
|
||||
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
async onInstance() {}
|
||||
async execute(): Promise<void> {
|
||||
console.log("开始部署证书到阿里云cdn");
|
||||
const access = (await this.accessService.getById(this.accessId)) as AliyunAccess;
|
||||
const client = this.getClient(access);
|
||||
const params = await this.buildParams();
|
||||
await this.doRequest(client, params);
|
||||
console.log("部署完成");
|
||||
}
|
||||
|
||||
getClient(access: AliyunAccess) {
|
||||
return new Core({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
endpoint: "https://cdn.aliyuncs.com",
|
||||
apiVersion: "2018-05-10",
|
||||
});
|
||||
}
|
||||
|
||||
async buildParams() {
|
||||
const CertName = (this.certName ?? "certd") + "-" + dayjs().format("YYYYMMDDHHmmss");
|
||||
const cert: any = this.cert;
|
||||
return {
|
||||
RegionId: "cn-hangzhou",
|
||||
DomainName: this.domainName,
|
||||
ServerCertificateStatus: "on",
|
||||
CertName: CertName,
|
||||
CertType: "upload",
|
||||
ServerCertificate: cert.crt,
|
||||
PrivateKey: cert.key,
|
||||
};
|
||||
}
|
||||
|
||||
async doRequest(client: RPCClient, params: any) {
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
const ret: any = await client.request("SetDomainServerCertificate", params, requestOption);
|
||||
this.checkRet(ret);
|
||||
this.logger.info("设置cdn证书成功:", ret.RequestId);
|
||||
}
|
||||
|
||||
checkRet(ret: any) {
|
||||
if (ret.code != null) {
|
||||
throw new Error("执行失败:" + ret.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
new DeployCertToAliyunCDN();
|
||||
3
packages/plugins/plugin-aliyun/src/plugin/index.ts
Normal file
3
packages/plugins/plugin-aliyun/src/plugin/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./deploy-to-cdn";
|
||||
export * from "./deploy-to-ack-ingress";
|
||||
export * from "./upload-to-aliyun";
|
||||
@@ -0,0 +1,105 @@
|
||||
import { AbstractTaskPlugin, Autowire, IAccessService, IsTaskPlugin, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
|
||||
import Core from "@alicloud/pop-core";
|
||||
import { AliyunAccess } from "../../access";
|
||||
import { appendTimeSuffix, checkRet, ZoneOptions } from "../../utils";
|
||||
import { Logger } from "log4js";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "uploadCertToAliyun",
|
||||
title: "上传证书到阿里云",
|
||||
desc: "",
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class UploadCertToAliyun extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: "证书名称",
|
||||
helper: "证书上传后将以此参数作为名称前缀",
|
||||
})
|
||||
name!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "大区",
|
||||
value: "cn-hangzhou",
|
||||
component: {
|
||||
name: "a-select",
|
||||
vModel: "value",
|
||||
options: ZoneOptions,
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
regionId!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: "pi-output-selector",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: any;
|
||||
|
||||
@TaskInput({
|
||||
title: "Access授权",
|
||||
helper: "阿里云授权AccessKeyId、AccessKeySecret",
|
||||
component: {
|
||||
name: "pi-access-selector",
|
||||
type: "aliyun",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
@TaskOutput({
|
||||
title: "上传成功后的阿里云CertId",
|
||||
})
|
||||
aliyunCertId!: string;
|
||||
|
||||
@Autowire()
|
||||
accessService!: IAccessService;
|
||||
|
||||
@Autowire()
|
||||
logger!: Logger;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
async onInstance() {}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
console.log("开始部署证书到阿里云cdn");
|
||||
const access = (await this.accessService.getById(this.accessId)) as AliyunAccess;
|
||||
const client = this.getClient(access);
|
||||
const certName = appendTimeSuffix(this.name);
|
||||
const params = {
|
||||
RegionId: this.regionId || "cn-hangzhou",
|
||||
Name: certName,
|
||||
Cert: this.cert.crt,
|
||||
Key: this.cert.key,
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
const ret = (await client.request("CreateUserCertificate", params, requestOption)) as any;
|
||||
checkRet(ret);
|
||||
this.logger.info("证书上传成功:aliyunCertId=", ret.CertId);
|
||||
|
||||
//output
|
||||
this.aliyunCertId = ret.CertId;
|
||||
}
|
||||
|
||||
getClient(aliyunProvider: AliyunAccess) {
|
||||
return new Core({
|
||||
accessKeyId: aliyunProvider.accessKeyId,
|
||||
accessKeySecret: aliyunProvider.accessKeySecret,
|
||||
endpoint: "https://cas.aliyuncs.com",
|
||||
apiVersion: "2018-07-13",
|
||||
});
|
||||
}
|
||||
}
|
||||
//注册插件
|
||||
new UploadCertToAliyun();
|
||||
15
packages/plugins/plugin-aliyun/src/utils/index.ts
Normal file
15
packages/plugins/plugin-aliyun/src/utils/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const ZoneOptions = [{ value: "cn-hangzhou" }];
|
||||
export function appendTimeSuffix(name: string) {
|
||||
if (name == null) {
|
||||
name = "certd";
|
||||
}
|
||||
return name + "-" + dayjs().format("YYYYMMDD-HHmmss");
|
||||
}
|
||||
|
||||
export function checkRet(ret: any) {
|
||||
if (ret.code != null) {
|
||||
throw new Error("执行失败:" + ret.Message);
|
||||
}
|
||||
}
|
||||
18
packages/plugins/plugin-aliyun/tsconfig.json
Normal file
18
packages/plugins/plugin-aliyun/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue","test/**/*.ts"],
|
||||
}
|
||||
24
packages/plugins/plugin-aliyun/vite.config.ts
Normal file
24
packages/plugins/plugin-aliyun/vite.config.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineConfig } from "vite";
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [],
|
||||
build: {
|
||||
lib: {
|
||||
entry: "src/index.ts",
|
||||
name: "pipeline",
|
||||
},
|
||||
rollupOptions: {
|
||||
external: ["vue", "lodash", "dayjs", "@fast-crud/fast-crud"],
|
||||
output: {
|
||||
// Provide global variables to use in the UMD build
|
||||
// for externalized deps
|
||||
globals: {
|
||||
vue: "Vue",
|
||||
"lodash": "_",
|
||||
dayjs: "dayjs",
|
||||
"@fast-crud/fast-crud": "FastCrud",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
22
packages/plugins/plugin-all/.eslintrc
Normal file
22
packages/plugins/plugin-all/.eslintrc
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
// "no-unused-expressions": "off",
|
||||
"max-len": [0, 160, 2, { "ignoreUrls": true }]
|
||||
}
|
||||
}
|
||||
26
packages/plugins/plugin-all/.gitignore
vendored
Normal file
26
packages/plugins/plugin-all/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
test/user.secret.ts
|
||||
5
packages/plugins/plugin-all/.mocharc.json
Normal file
5
packages/plugins/plugin-all/.mocharc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "test/**/*.test.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
||||
3
packages/plugins/plugin-all/.prettierrc
Normal file
3
packages/plugins/plugin-all/.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printWidth": 160
|
||||
}
|
||||
8
packages/plugins/plugin-all/CHANGELOG.md
Normal file
8
packages/plugins/plugin-all/CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.1](https://github.com/certd/certd/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-all
|
||||
16
packages/plugins/plugin-all/README.md
Normal file
16
packages/plugins/plugin-all/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
|
||||
## Type Support For `.vue` Imports in TS
|
||||
|
||||
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
|
||||
|
||||
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
|
||||
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
|
||||
|
||||
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
|
||||
1
packages/plugins/plugin-all/index.ts
Normal file
1
packages/plugins/plugin-all/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./src";
|
||||
52
packages/plugins/plugin-all/package.json
Normal file
52
packages/plugins/plugin-all/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@certd/plugin-all",
|
||||
"private": false,
|
||||
"version": "1.0.1",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"publishConfig": {
|
||||
"main": "./dist/plugin-all.umd.js",
|
||||
"module": "./dist/plugin-all.mjs",
|
||||
"types": "./dist/es/plugin-all.d.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@certd/plugin-aliyun": "^1.0.1",
|
||||
"@certd/plugin-cert": "^1.0.1",
|
||||
"@certd/plugin-host": "^1.0.1",
|
||||
"@certd/plugin-huawei": "^1.0.1",
|
||||
"@certd/plugin-tencent": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@alicloud/cs20151215": "^3.0.3",
|
||||
"@alicloud/openapi-client": "^0.4.0",
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@certd/pipeline": "^1.0.1",
|
||||
"@midwayjs/core": "^3.0.0",
|
||||
"@midwayjs/decorator": "^3.0.0",
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/lodash": "^4.14.186",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node-forge": "^1.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||
"@typescript-eslint/parser": "^5.38.1",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"log4js": "^6.7.1",
|
||||
"mocha": "^10.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.4",
|
||||
"vite": "^3.1.0",
|
||||
"vue-tsc": "^0.38.9"
|
||||
},
|
||||
"gitHead": "5950e1cae7cf30ebfc5128c15c7d1b0d101cbbb8"
|
||||
}
|
||||
5
packages/plugins/plugin-all/src/index.ts
Normal file
5
packages/plugins/plugin-all/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from "@certd/plugin-cert";
|
||||
export * from "@certd/plugin-aliyun";
|
||||
export * from "@certd/plugin-tencent";
|
||||
export * from "@certd/plugin-host";
|
||||
export * from "@certd/plugin-huawei";
|
||||
58
packages/plugins/plugin-all/test/cert.fake.test.ts
Normal file
58
packages/plugins/plugin-all/test/cert.fake.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
export const fakeCrt = `-----BEGIN CERTIFICATE-----
|
||||
MIIFSTCCBDGgAwIBAgITAPoZZk/LhVIyXoic2NnJyxubezANBgkqhkiG9w0BAQsF
|
||||
ADAiMSAwHgYDVQQDDBdGYWtlIExFIEludGVybWVkaWF0ZSBYMTAeFw0yMDEyMTQx
|
||||
NjA1NTFaFw0yMTAzMTQxNjA1NTFaMBsxGTAXBgNVBAMMECouZG9jbWlycm9yLmNs
|
||||
dWIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC75tGrYjly+RpcZehQ
|
||||
my1EpaXElT4L60pINKV2YDKnBrcSSo1c6rO7nFh12eC/ju4WwYUep0RVmBDF8xD0
|
||||
I1Sd1uuDTQWP0UT1X9yqdXtjvxpUqoCHAzG633f3sJRFul7mDLuC9tRCuae9o7qP
|
||||
EZ827XOmjBR35dso9I2GEE4828J3YE3tSKtobZlM+30jozLEcsO0PTyM5mq5PPjP
|
||||
VI3fGLcEaBmLZf5ixz4XkcY9IAhyAMYf03cT2wRoYPBaDdXblgCYL6sFtIMbzl3M
|
||||
Di94PB8NyoNSsC2nmBdWi54wFOgBvY/4ljsX/q7X3EqlSvcA0/M6/c/J9kJ3eupv
|
||||
jV8nAgMBAAGjggJ9MIICeTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYB
|
||||
BQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFAkdTjSCV3KD
|
||||
x28sf98MrwVfyFYgMB8GA1UdIwQYMBaAFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHcG
|
||||
CCsGAQUFBwEBBGswaTAyBggrBgEFBQcwAYYmaHR0cDovL29jc3Auc3RnLWludC14
|
||||
MS5sZXRzZW5jcnlwdC5vcmcwMwYIKwYBBQUHMAKGJ2h0dHA6Ly9jZXJ0LnN0Zy1p
|
||||
bnQteDEubGV0c2VuY3J5cHQub3JnLzArBgNVHREEJDAighAqLmRvY21pcnJvci5j
|
||||
bHVigg5kb2NtaXJyb3IuY2x1YjBMBgNVHSAERTBDMAgGBmeBDAECATA3BgsrBgEE
|
||||
AYLfEwEBATAoMCYGCCsGAQUFBwIBFhpodHRwOi8vY3BzLmxldHNlbmNyeXB0Lm9y
|
||||
ZzCCAQQGCisGAQQB1nkCBAIEgfUEgfIA8AB1ABboacHRlerXw/iXGuPwdgH3jOG2
|
||||
nTGoUhi2g38xqBUIAAABdmI3LM4AAAQDAEYwRAIgaiNqXSEq+sxp8eqlJXp/KFdO
|
||||
so5mT50MoRsLF8Inu0ACIDP46+ekng7I0BlmyIPmbqFcZgnZFVWLLCdLYijhVyOL
|
||||
AHcA3Zk0/KXnJIDJVmh9gTSZCEmySfe1adjHvKs/XMHzbmQAAAF2YjcuxwAABAMA
|
||||
SDBGAiEAxpeB8/w4YkHZ62nH20h128VtuTSmYDCnF7EK2fQyeZYCIQDbJlF2wehZ
|
||||
sF1BeE7qnYYqCTP0dYIrQ9HWtBa/MbGOKTANBgkqhkiG9w0BAQsFAAOCAQEAL2di
|
||||
HKh6XcZtGk0BFxJa51sCZ3MLu9+Zy90kCRD4ooP5x932WxVM25+LBRd+xSzx+TRL
|
||||
UVrlKp9GdMYX1JXL4Vf2NwzuFO3snPDe/qizD/3+D6yo8eKJ/LD82t5kLWAD2rto
|
||||
YfVSTKwfNIBBJwHUnjviBPJmheHHCKmz8Ct6/6QxFAeta9TAMn0sFeVCQnmAq7HL
|
||||
jrunq0tNHR/EKG0ITPLf+6P7MxbmpYNnq918766l0tKsW8oo8ZSGEwKU2LMaSiAa
|
||||
hasyl/2gMnYXjtKOjDcnR8oLpbrOg0qpVbynmJin1HP835oHPPAZ1gLsqYTTizNz
|
||||
AHxTaXliTVvS83dogw==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEqzCCApOgAwIBAgIRAIvhKg5ZRO08VGQx8JdhT+UwDQYJKoZIhvcNAQELBQAw
|
||||
GjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDUyMzIyMDc1OVoXDTM2
|
||||
MDUyMzIyMDc1OVowIjEgMB4GA1UEAwwXRmFrZSBMRSBJbnRlcm1lZGlhdGUgWDEw
|
||||
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtWKySDn7rWZc5ggjz3ZB0
|
||||
8jO4xti3uzINfD5sQ7Lj7hzetUT+wQob+iXSZkhnvx+IvdbXF5/yt8aWPpUKnPym
|
||||
oLxsYiI5gQBLxNDzIec0OIaflWqAr29m7J8+NNtApEN8nZFnf3bhehZW7AxmS1m0
|
||||
ZnSsdHw0Fw+bgixPg2MQ9k9oefFeqa+7Kqdlz5bbrUYV2volxhDFtnI4Mh8BiWCN
|
||||
xDH1Hizq+GKCcHsinDZWurCqder/afJBnQs+SBSL6MVApHt+d35zjBD92fO2Je56
|
||||
dhMfzCgOKXeJ340WhW3TjD1zqLZXeaCyUNRnfOmWZV8nEhtHOFbUCU7r/KkjMZO9
|
||||
AgMBAAGjgeMwgeAwDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAw
|
||||
HQYDVR0OBBYEFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHoGCCsGAQUFBwEBBG4wbDA0
|
||||
BggrBgEFBQcwAYYoaHR0cDovL29jc3Auc3RnLXJvb3QteDEubGV0c2VuY3J5cHQu
|
||||
b3JnLzA0BggrBgEFBQcwAoYoaHR0cDovL2NlcnQuc3RnLXJvb3QteDEubGV0c2Vu
|
||||
Y3J5cHQub3JnLzAfBgNVHSMEGDAWgBTBJnSkikSg5vogKNhcI5pFiBh54DANBgkq
|
||||
hkiG9w0BAQsFAAOCAgEABYSu4Il+fI0MYU42OTmEj+1HqQ5DvyAeyCA6sGuZdwjF
|
||||
UGeVOv3NnLyfofuUOjEbY5irFCDtnv+0ckukUZN9lz4Q2YjWGUpW4TTu3ieTsaC9
|
||||
AFvCSgNHJyWSVtWvB5XDxsqawl1KzHzzwr132bF2rtGtazSqVqK9E07sGHMCf+zp
|
||||
DQVDVVGtqZPHwX3KqUtefE621b8RI6VCl4oD30Olf8pjuzG4JKBFRFclzLRjo/h7
|
||||
IkkfjZ8wDa7faOjVXx6n+eUQ29cIMCzr8/rNWHS9pYGGQKJiY2xmVC9h12H99Xyf
|
||||
zWE9vb5zKP3MVG6neX1hSdo7PEAb9fqRhHkqVsqUvJlIRmvXvVKTwNCP3eCjRCCI
|
||||
PTAvjV+4ni786iXwwFYNz8l3PmPLCyQXWGohnJ8iBm+5nk7O2ynaPVW0U2W+pt2w
|
||||
SVuvdDM5zGv2f9ltNWUiYZHJ1mmO97jSY/6YfdOUH66iRtQtDkHBRdkNBsMbD+Em
|
||||
2TgBldtHNSJBfB3pm9FblgOcJ0FSWcUDWJ7vO0+NTXlgrRofRT6pVywzxVo6dND0
|
||||
WzYlTWeUVsO40xJqhgUQRER9YLOLxJ0O6C8i0xFxAMKOtSdodMB3RIwt7RFQ0uyt
|
||||
n5Z5MqkYhlMI3J1tPRTp1nEt9fyGspBOO05gi148Qasp+3N+svqKomoQglNoAxU=
|
||||
-----END CERTIFICATE-----`;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { IAccessService } from "@certd/pipeline";
|
||||
import { hauweiSecret } from "../user.secret";
|
||||
import { HuaweiAccess } from "@certd/plugin-huawei";
|
||||
export class AccessServiceTest implements IAccessService {
|
||||
async getById(id: any): Promise<any> {
|
||||
return {
|
||||
...hauweiSecret,
|
||||
} as HuaweiAccess;
|
||||
}
|
||||
}
|
||||
69
packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts
Normal file
69
packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ConcurrencyStrategy, NextStrategy, Pipeline, RunStrategy } from "@certd/pipeline";
|
||||
|
||||
let idIndex = 0;
|
||||
function generateId() {
|
||||
idIndex++;
|
||||
return idIndex + "";
|
||||
}
|
||||
export const pipeline: Pipeline = {
|
||||
version: 1,
|
||||
id: "huawei.test",
|
||||
title: "华为管道测试",
|
||||
userId: 1,
|
||||
triggers: [],
|
||||
stages: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "证书申请阶段",
|
||||
concurrency: ConcurrencyStrategy.Serial,
|
||||
next: NextStrategy.AllSuccess,
|
||||
tasks: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "申请证书任务",
|
||||
steps: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "申请证书",
|
||||
type: "CertApply",
|
||||
input: {
|
||||
domains: ["powerleader.chat", "*.powerleader.chat", "*.test.powerleader.chat", "*.ai.powerleader.chat"],
|
||||
email: "xiaojunnuo@qq.com",
|
||||
dnsProviderType: "huawei",
|
||||
accessId: "333",
|
||||
},
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: generateId(),
|
||||
title: "证书部署阶段",
|
||||
concurrency: ConcurrencyStrategy.Serial,
|
||||
next: NextStrategy.AllSuccess,
|
||||
tasks: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "测试输出参数任务",
|
||||
steps: [
|
||||
{
|
||||
id: generateId(),
|
||||
title: "输出参数(echo插件)",
|
||||
type: "EchoPlugin",
|
||||
input: {
|
||||
cert: "cert",
|
||||
},
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
19
packages/plugins/plugin-all/test/huawei/pipeline.test.ts
Normal file
19
packages/plugins/plugin-all/test/huawei/pipeline.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
//import { expect } from "chai";
|
||||
import "mocha";
|
||||
import { Executor, RunHistory, FileStorage } from "@certd/pipeline";
|
||||
import { pipeline } from "./pipeline.huawei";
|
||||
import { AccessServiceTest } from "./access-service-test";
|
||||
import "../../src";
|
||||
import "../plugin/echo-plugin";
|
||||
describe("pipeline-hauwei-test", function () {
|
||||
it("#pipeline", async function () {
|
||||
this.timeout(120000);
|
||||
async function onChanged(history: RunHistory) {
|
||||
console.log("changed:");
|
||||
}
|
||||
|
||||
const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() });
|
||||
await executor.run(2, "user");
|
||||
// expect(define.name).eq("EchoPlugin");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { IAccessService } from "@certd/pipeline";
|
||||
import { AliyunAccess } from "@certd/plugin-aliyun";
|
||||
import { aliyunSecret } from "../user.secret";
|
||||
export class AccessServiceTest implements IAccessService {
|
||||
async getById(id: any): Promise<any> {
|
||||
return {
|
||||
...aliyunSecret,
|
||||
} as AliyunAccess;
|
||||
}
|
||||
}
|
||||
13
packages/plugins/plugin-all/test/pipeline/init.test.ts
Normal file
13
packages/plugins/plugin-all/test/pipeline/init.test.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ContextFactory, FileStorage, logger } from "@certd/pipeline";
|
||||
import { AccessServiceTest } from "./access-service-test";
|
||||
|
||||
const contextFactory = new ContextFactory(new FileStorage());
|
||||
|
||||
const userContext = contextFactory.getContext("user", "test");
|
||||
const pipelineContext = contextFactory.getContext("pipeline", "test");
|
||||
export const pluginInitProps = {
|
||||
accessService: new AccessServiceTest(),
|
||||
pipelineContext: pipelineContext,
|
||||
userContext: userContext,
|
||||
logger: logger,
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user