Skip to content

Commit

Permalink
Oss Changes Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
divyaac committed Dec 2, 2024
1 parent 4b456ff commit 4c3b040
Show file tree
Hide file tree
Showing 14 changed files with 706 additions and 823 deletions.
8 changes: 5 additions & 3 deletions builtin/logical/pki/acme_billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ func TestACMEBilling(t *testing.T) {
expectedCount = validateClientCount(t, client, "ns2/pki", expectedCount+1, "unique identifier in a different namespace")

// Check the current fragment
fragment := cluster.Cores[0].Core.ResetActivityLog()[0]
if fragment == nil {
localFragment, globalFragment := cluster.Cores[0].Core.ResetActivityLog()
if globalFragment == nil || localFragment == nil {
t.Fatal("no fragment created")
}
validateAcmeClientTypes(t, fragment, expectedCount)
validateAcmeClientTypes(t, localFragment[0], 0)
validateAcmeClientTypes(t, globalFragment[0], expectedCount)
}

func validateAcmeClientTypes(t *testing.T, fragment *activity.LogFragment, expectedCount int64) {
t.Helper()

if int64(len(fragment.Clients)) != expectedCount {
t.Fatalf("bad number of entities, expected %v: got %v, entities are: %v", expectedCount, len(fragment.Clients), fragment.Clients)
}
Expand Down
2 changes: 1 addition & 1 deletion command/command_testonly/operator_usage_testonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestOperatorUsageCommandRun(t *testing.T) {

now := time.Now().UTC()

_, _, _, err = clientcountutil.NewActivityLogData(client).
_, _, err = clientcountutil.NewActivityLogData(client).
NewPreviousMonthData(1).
NewClientsSeen(6, clientcountutil.WithClientType("entity")).
NewClientsSeen(4, clientcountutil.WithClientType("non-entity-token")).
Expand Down
27 changes: 9 additions & 18 deletions sdk/helper/clientcountutil/clientcountutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,39 +280,30 @@ func (d *ActivityLogDataGenerator) ToProto() *generation.ActivityLogMockInput {
}

// Write writes the data to the API with the given write options. The method
// returns the new paths that have been written. Note that the API endpoint will
// returns the new local and global paths that have been written. Note that the API endpoint will
// only be present when Vault has been compiled with the "testonly" flag.
func (d *ActivityLogDataGenerator) Write(ctx context.Context, writeOptions ...generation.WriteOptions) ([]string, []string, []string, error) {
func (d *ActivityLogDataGenerator) Write(ctx context.Context, writeOptions ...generation.WriteOptions) ([]string, []string, error) {
d.data.Write = writeOptions
err := VerifyInput(d.data)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
data, err := d.ToJSON()
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
resp, err := d.client.Logical().WriteWithContext(ctx, "sys/internal/counters/activity/write", map[string]interface{}{"input": string(data)})
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
if resp.Data == nil {
return nil, nil, nil, fmt.Errorf("received no data")
}
paths := resp.Data["paths"]
castedPaths, ok := paths.([]interface{})
if !ok {
return nil, nil, nil, fmt.Errorf("invalid paths data: %v", paths)
}
returnPaths := make([]string, 0, len(castedPaths))
for _, path := range castedPaths {
returnPaths = append(returnPaths, path.(string))
return nil, nil, fmt.Errorf("received no data")
}

localPaths := resp.Data["local_paths"]
localCastedPaths, ok := localPaths.([]interface{})
if !ok {
return nil, nil, nil, fmt.Errorf("invalid local paths data: %v", localPaths)
return nil, nil, fmt.Errorf("invalid local paths data: %v", localPaths)
}
returnLocalPaths := make([]string, 0, len(localCastedPaths))
for _, path := range localCastedPaths {
Expand All @@ -322,13 +313,13 @@ func (d *ActivityLogDataGenerator) Write(ctx context.Context, writeOptions ...ge
globalPaths := resp.Data["global_paths"]
globalCastedPaths, ok := globalPaths.([]interface{})
if !ok {
return nil, nil, nil, fmt.Errorf("invalid global paths data: %v", globalPaths)
return nil, nil, fmt.Errorf("invalid global paths data: %v", globalPaths)
}
returnGlobalPaths := make([]string, 0, len(globalCastedPaths))
for _, path := range globalCastedPaths {
returnGlobalPaths = append(returnGlobalPaths, path.(string))
}
return returnPaths, returnLocalPaths, returnGlobalPaths, nil
return returnLocalPaths, returnGlobalPaths, nil
}

// VerifyInput checks that the input data is valid
Expand Down
5 changes: 2 additions & 3 deletions sdk/helper/clientcountutil/clientcountutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestNewCurrentMonthData_AddClients(t *testing.T) {
// sent to the server is correct.
func TestWrite(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := io.WriteString(w, `{"data":{"paths":["path1","path2"],"global_paths":["path2","path3"], "local_paths":["path3","path4"]}}`)
_, err := io.WriteString(w, `{"data":{"global_paths":["path2","path3"], "local_paths":["path3","path4"]}}`)
require.NoError(t, err)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
Expand All @@ -131,7 +131,7 @@ func TestWrite(t *testing.T) {
Address: ts.URL,
})
require.NoError(t, err)
paths, localPaths, globalPaths, err := NewActivityLogData(client).
localPaths, globalPaths, err := NewActivityLogData(client).
NewPreviousMonthData(3).
NewClientSeen().
NewPreviousMonthData(2).
Expand All @@ -140,7 +140,6 @@ func TestWrite(t *testing.T) {
NewCurrentMonthData().Write(context.Background(), generation.WriteOptions_WRITE_ENTITIES)

require.NoError(t, err)
require.Equal(t, []string{"path1", "path2"}, paths)
require.Equal(t, []string{"path2", "path3"}, globalPaths)
require.Equal(t, []string{"path3", "path4"}, localPaths)
}
Expand Down
Loading

0 comments on commit 4c3b040

Please sign in to comment.