-
Notifications
You must be signed in to change notification settings - Fork 41
Examples
Ilya Sher edited this page Dec 21, 2018
·
9 revisions
ngs -pi 'globals().filterv(Fun)'
-
globals()
returns aHash
of all global variables -
filterv()
filters aHash
by predicate applied to values, resulting a newHash
-
Fun
- the function type (callable) - A type
t
, when used as predicate act asF(x) x is t
, a predicate
Get all certificates from a certificate chain
certs = read(fileName) ~~ /-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/ms
-
read(fileName)
returns the whole content of the file -
~
- match operator, returns a subtype ofMatchResult
(eitherMatchSuccess
orMatchFailure
) -
~~
- match all operator, returns possibly empty array ofMatchSuccess
objects
subject = (`echo ${cert} | openssl x509 -subject -noout` - Sfx("\n") - Pfx("subject= /")).split("/").map(split(X, "=")).Hash()
-
`...`
runs a command and captures the output, similar to bash -
- Sfx("\n")
removes newline at the end. See Sfx type. -
- Pfx("subject= /")
removes undesired prefix of the string. See Pfx type -
.split("/")
splits the line by/
, resulting an array of strings. See split method -
.map(split(X, "="))
splits each string in the array, resulting an array of the form[["k1", "v1"], ["k2, "v2"]]
. See map method -
.Hash()
converts array of the form[["k1", "v1"], ["k2, "v2"]]
to a Hash
ngs -e '``aws acm list-certificates --region us-east-1``.filter({"DomainName": /MYREGEX/}).CertificateArn.each(F(arn) $(aws acm delete-certificate --certificate-arn $arn --region us-east-1))'
-
``aws acm list-certificates --region us-east-1``
- run AWS CLI and parse the output. Result is in array of hashes. This differs from the regular JSON output structure from AWS tools which is{"SomeKey": [array, with, interesting, data]}
. It's the[array, with, interesting, data]
. -
.filter({"DomainName": /MYREGEX/})
- filter elements. Only keep elements of the array (in our case each element is a hash) in whichDomainName
matchesMYREGEX
regular expression -
.CertificateArn
- convert array of hashes (describing each certificate) to array of strings containing ARNs of the certificates. Same as.map(F(x) x.CertificateArn)
. -
.each(...)
- execute the passed function for each element, passing the element as the argument.-
F(arn) ...
- the function to be executed for each ARN-
$(...)
- run external program
-
-
NGS official website is at https://ngs-lang.org/