Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Acme Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Geant DevOps
Acme Downloader
Commits
da1afd96
Unverified
Commit
da1afd96
authored
4 years ago
by
Max Adamo
Browse files
Options
Downloads
Patches
Plain Diff
minor
parent
40128ee7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+23
-23
23 additions, 23 deletions
main.go
with
23 additions
and
23 deletions
main.go
+
23
−
23
View file @
da1afd96
...
...
@@ -49,7 +49,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
certPEM
,
err
:=
ioutil
.
ReadFile
(
certificate
)
if
err
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] %v
\n
"
,
err
)
fmt
.
Printf
(
"[ERR] %v
\n
"
,
err
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -59,7 +59,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
certFullchainPEM
,
err
:=
ioutil
.
ReadFile
(
fullchain
)
if
err
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] %v
\n
"
,
err
)
fmt
.
Printf
(
"[ERR] %v
\n
"
,
err
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -69,7 +69,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
rootPEM
,
err
:=
ioutil
.
ReadFile
(
ca
)
if
err
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] %v
\n
"
,
err
)
fmt
.
Printf
(
"[ERR] %v
\n
"
,
err
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -80,7 +80,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
ok
:=
roots
.
AppendCertsFromPEM
([]
byte
(
rootPEM
))
if
!
ok
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse root certificate
\n
"
)
fmt
.
Printf
(
"[ERR] failed to parse root certificate
\n
"
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -90,7 +90,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
block
,
_
:=
pem
.
Decode
([]
byte
(
certPEM
))
if
block
==
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate PEM
\n
"
)
fmt
.
Printf
(
"[ERR] failed to parse certificate PEM
\n
"
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -99,7 +99,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
cert
,
err
:=
x509
.
ParseCertificate
(
block
.
Bytes
)
if
err
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate %v
\n
"
,
err
)
fmt
.
Printf
(
"[ERR] failed to parse certificate %v
\n
"
,
err
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -109,7 +109,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
fullchainBlock
,
_
:=
pem
.
Decode
([]
byte
(
certFullchainPEM
))
if
fullchainBlock
==
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate PEM
\n
"
)
fmt
.
Printf
(
"[ERR] failed to parse certificate PEM
\n
"
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -118,7 +118,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
fullchainCert
,
fullchainErr
:=
x509
.
ParseCertificate
(
fullchainBlock
.
Bytes
)
if
fullchainErr
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate %v
\n
"
,
fullchainErr
)
fmt
.
Printf
(
"[ERR] failed to parse certificate %v
\n
"
,
fullchainErr
)
appExit
(
255
)
}
else
{
return
false
...
...
@@ -134,7 +134,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
if
_
,
err
:=
cert
.
Verify
(
opts
);
err
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate %v
\n
"
,
err
.
Error
())
fmt
.
Printf
(
"[ERR] failed to parse certificate %v
\n
"
,
err
.
Error
())
appExit
(
255
)
}
else
{
return
false
...
...
@@ -142,7 +142,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
}
if
_
,
fullchainErr
:=
fullchainCert
.
Verify
(
opts
);
fullchainErr
!=
nil
{
if
fail
==
true
{
fmt
.
Printf
(
"[ERR
OR
] failed to parse certificate %v
\n
"
,
err
.
Error
())
fmt
.
Printf
(
"[ERR] failed to parse certificate %v
\n
"
,
err
.
Error
())
}
else
{
return
false
}
...
...
@@ -156,19 +156,19 @@ func GetRedisKey(redisurl string, redistoken string) string {
client
:=
&
http
.
Client
{}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
redisurl
,
nil
)
if
err
!=
nil
{
fmt
.
Printf
(
"[ERR
OR
] Fail to read %v: %v
\n
"
,
redisurl
,
err
)
fmt
.
Printf
(
"[ERR] Fail to read %v: %v
\n
"
,
redisurl
,
err
)
appExit
(
255
)
}
req
.
SetBasicAuth
(
"redis"
,
redistoken
)
resp
,
err
:=
client
.
Do
(
req
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
resp
.
StatusCode
<
200
||
resp
.
StatusCode
>
299
{
fmt
.
Printf
(
"[ERR
OR
] Fail to fetch %v
\n
"
,
redisurl
)
fmt
.
Printf
(
"[ERR] Fail to fetch %v
\n
"
,
redisurl
)
appExit
(
255
)
}
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
fmt
.
Printf
(
"[ERR
OR
] Fail to read %v: %v
\n
"
,
redisurl
,
err
)
fmt
.
Printf
(
"[ERR] Fail to read %v: %v
\n
"
,
redisurl
,
err
)
appExit
(
255
)
}
return
fmt
.
Sprintf
(
string
(
body
))
...
...
@@ -179,19 +179,19 @@ func GetVaultKey(vaulturl string, vaulttoken string) string {
vaultClient
:=
&
http
.
Client
{}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
vaulturl
,
nil
)
if
err
!=
nil
{
fmt
.
Printf
(
"[ERR
OR
] Fail to read %v: %v
\n
"
,
vaulturl
,
err
)
fmt
.
Printf
(
"[ERR] Fail to read %v: %v
\n
"
,
vaulturl
,
err
)
appExit
(
255
)
}
req
.
Header
.
Add
(
"X-vault-token"
,
vaulttoken
)
resp
,
err
:=
vaultClient
.
Do
(
req
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
resp
.
StatusCode
<
200
||
resp
.
StatusCode
>
299
{
fmt
.
Printf
(
"[ERR
OR
] Fail to fetch %v
\n
"
,
vaulturl
)
fmt
.
Printf
(
"[ERR] Fail to fetch %v
\n
"
,
vaulturl
)
appExit
(
255
)
}
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
fmt
.
Printf
(
"[ERR
OR
] Fail to read %v: %v
\n
"
,
vaulturl
,
err
)
fmt
.
Printf
(
"[ERR] Fail to read %v: %v
\n
"
,
vaulturl
,
err
)
appExit
(
255
)
}
return
gjson
.
Get
(
string
(
body
),
"data.value"
)
.
String
()
...
...
@@ -207,7 +207,7 @@ func WriteToFile(content string, destination string, groupname string, filemode
file
,
err
:=
os
.
OpenFile
(
destination
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
filemode
)
if
err
!=
nil
{
fmt
.
Printf
(
"[ERR
OR
] %v cannot be created
\n
"
,
destination
)
fmt
.
Printf
(
"[ERR] %v cannot be created
\n
"
,
destination
)
appExit
(
255
)
}
...
...
@@ -291,7 +291,7 @@ Options:
DayString
:=
arguments
[
"--days"
]
.
(
string
)
Days
,
daysErr
:=
strconv
.
Atoi
(
DayString
)
if
daysErr
!=
nil
{
fmt
.
Printf
(
"Days mut be an integer
\n
"
)
fmt
.
Printf
(
"
[ERR]
Days mut be an integer
\n
"
)
appExit
(
255
)
}
RedisBaseURL
=
"https://redis.geant.org/GET"
...
...
@@ -325,7 +325,7 @@ Options:
// check if there is a certificate installed and it is valid
existingCert
:=
checkCerificates
(
CertName
,
certificateDestination
,
fullchainDestination
,
caDestination
,
keyDestination
,
Days
,
false
)
if
existingCert
==
true
{
fmt
.
Printf
(
"the certificates are still valid
\n
"
)
fmt
.
Printf
(
"
[INFO]
the certificates are still valid
\n
"
)
appExit
(
0
)
}
certificate
:=
GetRedisKey
(
RedisCertURL
,
RedisToken
)
...
...
@@ -350,10 +350,10 @@ Options:
WriteToFile
(
ca
,
caDestination
,
GroupName
,
0644
,
0755
)
WriteToFile
(
privKey
,
keyDestination
,
GroupName
,
0640
,
0750
)
fmt
.
Printf
(
"installed: %v
\n
"
,
certificateDestination
)
fmt
.
Printf
(
"installed: %v
\n
"
,
caDestination
)
fmt
.
Printf
(
"installed: %v
\n
"
,
fullchainDestination
)
fmt
.
Printf
(
"installed: %v
\n
"
,
keyDestination
)
fmt
.
Printf
(
"
[INFO]
installed: %v
\n
"
,
certificateDestination
)
fmt
.
Printf
(
"
[INFO]
installed: %v
\n
"
,
caDestination
)
fmt
.
Printf
(
"
[INFO]
installed: %v
\n
"
,
fullchainDestination
)
fmt
.
Printf
(
"
[INFO]
installed: %v
\n
"
,
keyDestination
)
// Exit 1 means application needs to be reloaded
appExit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment