mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-30 01:17:21 +02:00
very bad demo code
This commit is contained in:
parent
b4aa275403
commit
d588135b3a
30 changed files with 1308 additions and 248 deletions
43
pkg/envoy/extract_embed.go
Normal file
43
pkg/envoy/extract_embed.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
//go:build !debug_local_envoy
|
||||
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/envoy/files"
|
||||
)
|
||||
|
||||
func extract(dstName string) (err error) {
|
||||
checksum, err := hex.DecodeString(strings.Fields(files.Checksum())[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("checksum %s: %w", files.Checksum(), err)
|
||||
}
|
||||
|
||||
hr := &hashReader{
|
||||
Hash: sha256.New(),
|
||||
r: bytes.NewReader(files.Binary()),
|
||||
}
|
||||
|
||||
dst, err := os.OpenFile(dstName, os.O_CREATE|os.O_WRONLY, ownerRX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { err = dst.Close() }()
|
||||
|
||||
if _, err = io.Copy(dst, io.LimitReader(hr, maxExpandedEnvoySize)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sum := hr.Sum(nil)
|
||||
if !bytes.Equal(sum, checksum) {
|
||||
return fmt.Errorf("expected %x, got %x checksum", checksum, sum)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue