-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E Encryption support to the golang API
Summary: TSIA, reuse some common code. Note, the moving of uuid helpers makes this a breaking API change and we should rev the version number. Test Plan: Added tests, ran the encryption example, ran the cli. Reviewers: zasgar, michelle Reviewed By: zasgar JIRA Issues: PC-1099 Differential Revision: https://phab.corp.pixielabs.ai/D9403 GitOrigin-RevId: 079ad7d482d89e7349c930466721a00a70f01d1d
- Loading branch information
1 parent
9dbe6f6
commit 5eee6c6
Showing
16 changed files
with
386 additions
and
22 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
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
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,41 @@ | ||
# Copyright 2018- The Pixie 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "encryption_example_lib", | ||
srcs = ["example.go"], | ||
importpath = "px.dev/pxapi/examples/encryption_example", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"//src/api/go/pxapi", | ||
"//src/api/go/pxapi/errdefs", | ||
"//src/api/go/pxapi/types", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "encryption_example", | ||
embed = [":encryption_example_lib"], | ||
visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
filegroup( | ||
name = "encryption_example_group", | ||
srcs = glob(["*.go"]), | ||
visibility = ["//src:__subpackages__"], | ||
) |
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,109 @@ | ||
/* | ||
* Copyright 2018- The Pixie 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"px.dev/pxapi" | ||
"px.dev/pxapi/errdefs" | ||
"px.dev/pxapi/types" | ||
) | ||
|
||
var ( | ||
pxl = ` | ||
import px | ||
df = px.DataFrame('http_events') | ||
df = df[['upid', 'req_path', 'remote_addr', 'req_method']] | ||
df = df.head(10) | ||
px.display(df, 'http') | ||
` | ||
) | ||
|
||
type tablePrinter struct{} | ||
|
||
func (t *tablePrinter) HandleInit(ctx context.Context, metadata types.TableMetadata) error { | ||
return nil | ||
} | ||
|
||
func (t *tablePrinter) HandleRecord(ctx context.Context, r *types.Record) error { | ||
for _, d := range r.Data { | ||
fmt.Printf("%s ", d.String()) | ||
} | ||
fmt.Printf("\n") | ||
return nil | ||
} | ||
|
||
func (t *tablePrinter) HandleDone(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
type tableMux struct { | ||
} | ||
|
||
func (s *tableMux) AcceptTable(ctx context.Context, metadata types.TableMetadata) (pxapi.TableRecordHandler, error) { | ||
return &tablePrinter{}, nil | ||
} | ||
|
||
func main() { | ||
apiKey, ok := os.LookupEnv("PX_API_KEY") | ||
if !ok { | ||
panic("please set PX_API_KEY") | ||
} | ||
clusterID, ok := os.LookupEnv("PX_CLUSTER_ID") | ||
if !ok { | ||
panic("please set PX_CLUSTER_ID") | ||
} | ||
|
||
ctx := context.Background() | ||
client, err := pxapi.NewClient(ctx, pxapi.WithAPIKey(apiKey), pxapi.WithE2EEncryption(true)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Running on Cluster: %s\n", clusterID) | ||
|
||
tm := &tableMux{} | ||
|
||
fmt.Println("Running script") | ||
vz, err := client.NewVizierClient(ctx, clusterID) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
resultSet, err := vz.ExecuteScript(ctx, pxl, tm) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer resultSet.Close() | ||
if err := resultSet.Stream(); err != nil { | ||
if errdefs.IsCompilationError(err) { | ||
fmt.Printf("Got compiler error: \n %s\n", err.Error()) | ||
} else { | ||
fmt.Printf("Got error : %+v, while streaming\n", err) | ||
} | ||
} | ||
|
||
stats := resultSet.Stats() | ||
fmt.Printf("Execution Time: %v\n", stats.ExecutionTime) | ||
fmt.Printf("Bytes received: %v\n", stats.TotalBytes) | ||
} |
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
Oops, something went wrong.