-
Notifications
You must be signed in to change notification settings - Fork 0
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: Christoph Hartmann <[email protected]> Signed-off-by: Christoph Hartmann <[email protected]>
- Loading branch information
1 parent
cff95c3
commit 5faaff8
Showing
45 changed files
with
2,691 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
pb "go.mondoo.com/ranger-rpc/examples/rangerguard" | ||
"go.mondoo.com/ranger-rpc/plugins/authentication/cert" | ||
"go.mondoo.com/ranger-rpc/plugins/rangerguard/crypto" | ||
) | ||
|
||
func main() { | ||
// inefficient, just for testing | ||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) | ||
|
||
tlsconfig := &tls.Config{ | ||
InsecureSkipVerify: true, | ||
} | ||
|
||
tr := &http.Transport{ | ||
MaxIdleConns: 10, | ||
IdleConnTimeout: 30 * time.Second, | ||
DisableCompression: true, | ||
TLSClientConfig: tlsconfig, | ||
} | ||
|
||
// key for signing the requests | ||
privateKey, err := crypto.PrivateKeyFromFile("../server/private-key.p8") | ||
if err != nil { | ||
log.Error().Err(err).Msg("could not read private key") | ||
} | ||
|
||
plugin, err := cert.NewRangerPlugin(cert.ClientConfig{ | ||
PrivateKey: privateKey, | ||
Issuer: "ranger_guard", | ||
Subject: "ranger_guard_client", | ||
Kid: "1", | ||
}) | ||
if err != nil { | ||
log.Error().Err(err).Msg("could not create signer plugin") | ||
} | ||
|
||
log.Info().Msgf("start proto cLient") | ||
protoClient, err := pb.NewHelloWorldClient("https://localhost:8443/hello/", &http.Client{Transport: tr}, plugin) | ||
if err != nil { | ||
log.Error().Err(err).Msg("could not create hello world client") | ||
} | ||
|
||
data := &pb.HelloReq{Subject: "World"} | ||
protoResp, err := protoClient.Hello(context.Background(), data) | ||
if err == nil { | ||
log.Info().Msgf("Response %s", protoResp.Text) // prints "Hello World" | ||
} else { | ||
log.Error().Err(err).Msg("Could not get the response") | ||
} | ||
} |
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,6 @@ | ||
package rangerguard | ||
|
||
// To regenerate the protocol buffer output for this package, run | ||
// go generate | ||
|
||
//go:generate protoc --go_out=. --go_opt=paths=source_relative --rangerrpc_out=. hello.proto |
Oops, something went wrong.