forked from Venafi/vcert
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Richard Wall <[email protected]>
- Loading branch information
Showing
10 changed files
with
186 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Fake TPP Server | ||
|
||
|
||
```terminal | ||
$ go run ./test/tpp/... | ||
I0930 18:00:58.750488 174501 main.go:15] "started" url="https://127.0.0.1:35103" | ||
``` | ||
|
||
|
||
```terminal | ||
$ vcert getcred --insecure -u https://127.0.0.1:45817 -t foo --verbose --username user1 --password pass1 | ||
vCert: 2022/09/30 18:21:24 Getting credentials... | ||
vCert: 2022/09/30 18:21:24 Got 400 Bad Request status for POST https://127.0.0.1:45817/vedauth/authorize/token | ||
vCert: 2022/09/30 18:21:24 unexpected status code on TPP Authorize. Status: 400 Bad Request | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"k8s.io/klog/v2" | ||
|
||
"github.com/Venafi/vcert/v4/test/tpp/fake" | ||
"github.com/Venafi/vcert/v4/test/tpp/signals" | ||
) | ||
|
||
func main() { | ||
ctx := signals.SetupSignalHandler() | ||
log := klog.NewKlogr() | ||
tpp := fake.New(log) | ||
tpp.Start() | ||
log.Info("started", "url", tpp.URL) | ||
<-ctx.Done() | ||
tpp.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package signals contains libraries for handling signals to gracefully | ||
// shutdown the manager in combination with Kubernetes pod graceful termination | ||
// policy. | ||
package signals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package signals | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
var onlyOneSignalHandler = make(chan struct{}) | ||
|
||
// SetupSignalHandler registers for SIGTERM and SIGINT. A context is returned | ||
// which is canceled on one of these signals. If a second signal is caught, the program | ||
// is terminated with exit code 1. | ||
func SetupSignalHandler() context.Context { | ||
close(onlyOneSignalHandler) // panics when called twice | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
c := make(chan os.Signal, 2) | ||
signal.Notify(c, shutdownSignals...) | ||
go func() { | ||
<-c | ||
cancel() | ||
<-c | ||
os.Exit(1) // second signal. Exit directly. | ||
}() | ||
|
||
return ctx | ||
} |
Oops, something went wrong.