Merge pull request #4401 from hashicorp/jefferai-linter-fixes
Fix linter warnings, parts 1 and 2
This commit is contained in:
91 files changed
+472
-411
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/test/bufconn"
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ type grpcServerListener interface {
|
||||
|
||||
func gatewayDialOptions(lis grpcServerListener) []grpc.DialOption {
|
||||
return []grpc.DialOption{
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||
return lis.Dial()
|
||||
}),
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"os"
|
||||
@@ -702,7 +702,7 @@ func wrapHandlerWithCallbackInterceptor(h http.Handler, c *Controller) http.Hand
|
||||
}
|
||||
}
|
||||
bytesReader := bytes.NewReader(attrBytes)
|
||||
req.Body = ioutil.NopCloser(bytesReader)
|
||||
req.Body = io.NopCloser(bytesReader)
|
||||
req.ContentLength = int64(bytesReader.Len())
|
||||
req.Header.Set(textproto.CanonicalMIMEHeaderKey("content-type"), "application/json")
|
||||
req.Method = http.MethodPost
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -50,7 +49,7 @@ func TestAuthenticationHandler(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode, "Got response: %v", resp)
|
||||
|
||||
b, err = ioutil.ReadAll(resp.Body)
|
||||
b, err = io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
body := make(map[string]any)
|
||||
require.NoError(t, json.Unmarshal(b, &body))
|
||||
@@ -71,7 +70,7 @@ func TestAuthenticationHandler(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode, "Got response: %v", resp)
|
||||
|
||||
b, err = ioutil.ReadAll(resp.Body)
|
||||
b, err = io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
body = make(map[string]any)
|
||||
require.NoError(t, json.Unmarshal(b, &body))
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -1126,7 +1125,7 @@ func TestAuthenticate_Ldap(t *testing.T) {
|
||||
assert.Equal(tc.wantType, resp.GetType())
|
||||
sinkFileName := c.ObservationEvents.Name()
|
||||
defer func() { _ = os.WriteFile(sinkFileName, nil, 0o666) }()
|
||||
b, err := ioutil.ReadFile(sinkFileName)
|
||||
b, err := os.ReadFile(sinkFileName)
|
||||
require.NoError(err)
|
||||
gotRes := &cloudevents.Event{}
|
||||
err = json.Unmarshal(b, gotRes)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -251,7 +251,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
resp := w.Result()
|
||||
assert.EqualValues(tc.expected.Status, resp.StatusCode)
|
||||
|
||||
got, err := ioutil.ReadAll(resp.Body)
|
||||
got, err := io.ReadAll(resp.Body)
|
||||
require.NoError(err)
|
||||
|
||||
gotErr := &pb.Error{}
|
||||
|
||||
@@ -1428,7 +1428,7 @@ func TestUpdate(t *testing.T) {
|
||||
|
||||
var orgVersion uint32 = 2
|
||||
var projVersion uint32 = 2
|
||||
var globalVersion uint32 = global.Version
|
||||
globalVersion := global.Version
|
||||
|
||||
resetOrg := func() {
|
||||
orgVersion++
|
||||
|
||||
@@ -1716,16 +1716,17 @@ func validateGetRequest(req *pbs.GetTargetRequest) error {
|
||||
}
|
||||
|
||||
func validateCreateRequest(req *pbs.CreateTargetRequest) error {
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
item := req.GetItem()
|
||||
return handlers.ValidateCreateRequest(item, func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetItem().GetScopeId()), scope.Project.Prefix()) {
|
||||
if !handlers.ValidId(handlers.Id(item.GetScopeId()), scope.Project.Prefix()) {
|
||||
badFields[globals.ScopeIdField] = "This field is required to have a properly formatted project scope id."
|
||||
}
|
||||
if req.GetItem().GetName() == nil || req.GetItem().GetName().GetValue() == "" {
|
||||
if item.GetName() == nil || item.GetName().GetValue() == "" {
|
||||
badFields[globals.NameField] = "This field is required."
|
||||
}
|
||||
if req.GetItem().GetSessionConnectionLimit() != nil {
|
||||
val := req.GetItem().GetSessionConnectionLimit().GetValue()
|
||||
if item.GetSessionConnectionLimit() != nil {
|
||||
val := item.GetSessionConnectionLimit().GetValue()
|
||||
switch {
|
||||
case val == -1:
|
||||
case val > 0:
|
||||
@@ -1733,29 +1734,29 @@ func validateCreateRequest(req *pbs.CreateTargetRequest) error {
|
||||
badFields[globals.SessionConnectionLimitField] = "This must be -1 (unlimited) or greater than zero."
|
||||
}
|
||||
}
|
||||
if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 {
|
||||
if item.GetSessionMaxSeconds() != nil && item.GetSessionMaxSeconds().GetValue() == 0 {
|
||||
badFields[globals.SessionMaxSecondsField] = "This must be greater than zero."
|
||||
}
|
||||
if req.GetItem().GetType() == "" {
|
||||
if item.GetType() == "" {
|
||||
badFields[globals.TypeField] = "This is a required field."
|
||||
} else if target.SubtypeFromType(req.GetItem().GetType()) == "" {
|
||||
} else if target.SubtypeFromType(item.GetType()) == "" {
|
||||
badFields[globals.TypeField] = "Unknown type provided."
|
||||
}
|
||||
if workerFilter := req.GetItem().GetWorkerFilter(); workerFilter != nil {
|
||||
if workerFilter := item.GetWorkerFilter(); workerFilter != nil {
|
||||
badFields[globals.WorkerFilterField] = WorkerFilterDeprecationMessage
|
||||
}
|
||||
if egressFilter := req.GetItem().GetEgressWorkerFilter(); egressFilter != nil {
|
||||
if egressFilter := item.GetEgressWorkerFilter(); egressFilter != nil {
|
||||
if _, err := bexpr.CreateEvaluator(egressFilter.GetValue()); err != nil {
|
||||
badFields[globals.EgressWorkerFilterField] = "Unable to successfully parse egress filter expression."
|
||||
}
|
||||
}
|
||||
if ingressFilter := req.GetItem().GetIngressWorkerFilter(); ingressFilter != nil {
|
||||
if ingressFilter := item.GetIngressWorkerFilter(); ingressFilter != nil {
|
||||
err := ValidateIngressWorkerFilterFn(ingressFilter.GetValue())
|
||||
if err != nil {
|
||||
badFields[globals.IngressWorkerFilterField] = err.Error()
|
||||
}
|
||||
}
|
||||
if address := req.GetItem().GetAddress(); address != nil {
|
||||
if address := item.GetAddress(); address != nil {
|
||||
if len(address.GetValue()) < static.MinHostAddressLength ||
|
||||
len(address.GetValue()) > static.MaxHostAddressLength {
|
||||
badFields[globals.AddressField] = fmt.Sprintf("Address length must be between %d and %d characters.", static.MinHostAddressLength, static.MaxHostAddressLength)
|
||||
@@ -1769,12 +1770,12 @@ func validateCreateRequest(req *pbs.CreateTargetRequest) error {
|
||||
badFields[globals.AddressField] = fmt.Sprintf("Error parsing address: %v.", err)
|
||||
}
|
||||
}
|
||||
subtype := target.SubtypeFromType(req.GetItem().GetType())
|
||||
subtype := target.SubtypeFromType(item.GetType())
|
||||
_, err := subtypeRegistry.get(subtype)
|
||||
if err != nil {
|
||||
badFields[globals.TypeField] = "Unknown type provided."
|
||||
} else {
|
||||
a, err := subtypeRegistry.newAttribute(subtype, req.GetItem().GetAttrs())
|
||||
a, err := subtypeRegistry.newAttribute(subtype, item.GetAttrs())
|
||||
if err != nil {
|
||||
badFields[globals.AttributesField] = "Attribute fields do not match the expected format."
|
||||
} else {
|
||||
@@ -1788,14 +1789,15 @@ func validateCreateRequest(req *pbs.CreateTargetRequest) error {
|
||||
}
|
||||
|
||||
func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
item := req.GetItem()
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
paths := req.GetUpdateMask().GetPaths()
|
||||
if handlers.MaskContains(paths, globals.NameField) && req.GetItem().GetName().GetValue() == "" {
|
||||
if handlers.MaskContains(paths, globals.NameField) && item.GetName().GetValue() == "" {
|
||||
badFields[globals.NameField] = "This field cannot be set to empty."
|
||||
}
|
||||
if req.GetItem().GetSessionConnectionLimit() != nil {
|
||||
val := req.GetItem().GetSessionConnectionLimit().GetValue()
|
||||
if item.GetSessionConnectionLimit() != nil {
|
||||
val := item.GetSessionConnectionLimit().GetValue()
|
||||
switch {
|
||||
case val == -1:
|
||||
case val > 0:
|
||||
@@ -1803,18 +1805,18 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
badFields[globals.SessionConnectionLimitField] = "This must be -1 (unlimited) or greater than zero."
|
||||
}
|
||||
}
|
||||
if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 {
|
||||
if item.GetSessionMaxSeconds() != nil && item.GetSessionMaxSeconds().GetValue() == 0 {
|
||||
badFields[globals.SessionMaxSecondsField] = "This must be greater than zero."
|
||||
}
|
||||
// worker_filter is mutually exclusive from ingress and egress filter
|
||||
workerFilterFound := false
|
||||
if workerFilter := req.GetItem().GetWorkerFilter(); workerFilter != nil {
|
||||
if workerFilter := item.GetWorkerFilter(); workerFilter != nil {
|
||||
if _, err := bexpr.CreateEvaluator(workerFilter.GetValue()); err != nil {
|
||||
badFields[globals.WorkerFilterField] = "Unable to successfully parse filter expression."
|
||||
}
|
||||
workerFilterFound = true
|
||||
}
|
||||
if egressFilter := req.GetItem().GetEgressWorkerFilter(); egressFilter != nil {
|
||||
if egressFilter := item.GetEgressWorkerFilter(); egressFilter != nil {
|
||||
if workerFilterFound {
|
||||
badFields[globals.EgressWorkerFilterField] = fmt.Sprintf("Cannot set %s and %s; they are mutually exclusive fields.", globals.WorkerFilterField, globals.EgressWorkerFilterField)
|
||||
}
|
||||
@@ -1822,7 +1824,7 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
badFields[globals.EgressWorkerFilterField] = "Unable to successfully parse egress filter expression."
|
||||
}
|
||||
}
|
||||
if ingressFilter := req.GetItem().GetIngressWorkerFilter(); ingressFilter != nil {
|
||||
if ingressFilter := item.GetIngressWorkerFilter(); ingressFilter != nil {
|
||||
if workerFilterFound {
|
||||
badFields[globals.IngressWorkerFilterField] = fmt.Sprintf("Cannot set %s and %s; they are mutually exclusive fields.", globals.WorkerFilterField, globals.IngressWorkerFilterField)
|
||||
}
|
||||
@@ -1831,7 +1833,7 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
badFields[globals.IngressWorkerFilterField] = err.Error()
|
||||
}
|
||||
}
|
||||
if address := req.GetItem().GetAddress(); address != nil {
|
||||
if address := item.GetAddress(); address != nil {
|
||||
if len(address.GetValue()) < static.MinHostAddressLength ||
|
||||
len(address.GetValue()) > static.MaxHostAddressLength {
|
||||
badFields[globals.AddressField] = fmt.Sprintf("Address length must be between %d and %d characters.", static.MinHostAddressLength, static.MaxHostAddressLength)
|
||||
@@ -1850,11 +1852,11 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
if err != nil {
|
||||
badFields[globals.TypeField] = "Unknown type provided."
|
||||
} else {
|
||||
if req.GetItem().GetType() != "" && target.SubtypeFromType(req.GetItem().GetType()) != subtype {
|
||||
if item.GetType() != "" && target.SubtypeFromType(item.GetType()) != subtype {
|
||||
badFields[globals.TypeField] = "Cannot modify the resource type."
|
||||
}
|
||||
|
||||
a, err := subtypeRegistry.newAttribute(subtype, req.GetItem().GetAttrs())
|
||||
a, err := subtypeRegistry.newAttribute(subtype, item.GetAttrs())
|
||||
if err != nil {
|
||||
badFields[globals.AttributesField] = "Attribute fields do not match the expected format."
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/workers"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/workers"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"github.com/hashicorp/nodeenrollment"
|
||||
@@ -1269,7 +1268,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: "invalid-scope",
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
},
|
||||
@@ -1283,7 +1282,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
},
|
||||
},
|
||||
@@ -1296,7 +1295,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
Id: "invalid-id",
|
||||
@@ -1311,7 +1310,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
Address: "invalid-address",
|
||||
@@ -1326,7 +1325,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
ConfigTags: map[string]*structpb.ListValue{
|
||||
@@ -1345,7 +1344,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
CanonicalTags: map[string]*structpb.ListValue{
|
||||
@@ -1364,7 +1363,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
LastStatusTime: timestamppb.Now(),
|
||||
@@ -1379,7 +1378,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
AuthorizedActions: []string{"invalid-authorized-actions"},
|
||||
@@ -1394,7 +1393,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
CreatedTime: timestamppb.Now(),
|
||||
@@ -1409,7 +1408,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
UpdatedTime: timestamppb.Now(),
|
||||
@@ -1424,7 +1423,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
Version: 1,
|
||||
@@ -1439,7 +1438,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: "splat-auth-scope",
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
},
|
||||
@@ -1452,7 +1451,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: "invalid;semicolon"},
|
||||
},
|
||||
@@ -1465,7 +1464,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: "notNodeCreds"},
|
||||
},
|
||||
@@ -1485,7 +1484,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
}(),
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1518,7 +1517,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
}(),
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1533,7 +1532,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateWorkerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1541,7 +1540,7 @@ func TestCreateWorkerLed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
res: &pbs.CreateWorkerLedResponse{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1652,7 +1651,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: "invalid-scope",
|
||||
},
|
||||
},
|
||||
@@ -1665,7 +1664,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
WorkerGeneratedAuthToken: &wrapperspb.StringValue{Value: fetchReqFn()},
|
||||
},
|
||||
@@ -1679,7 +1678,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Id: "invalid-id",
|
||||
},
|
||||
@@ -1693,7 +1692,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Address: "invalid-address",
|
||||
},
|
||||
@@ -1707,7 +1706,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
ConfigTags: map[string]*structpb.ListValue{
|
||||
"invalid": {Values: []*structpb.Value{
|
||||
@@ -1725,7 +1724,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
CanonicalTags: map[string]*structpb.ListValue{
|
||||
"invalid": {Values: []*structpb.Value{
|
||||
@@ -1743,7 +1742,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
LastStatusTime: timestamppb.Now(),
|
||||
},
|
||||
@@ -1757,7 +1756,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
AuthorizedActions: []string{"invalid-authorized-actions"},
|
||||
},
|
||||
@@ -1771,7 +1770,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
CreatedTime: timestamppb.Now(),
|
||||
},
|
||||
@@ -1785,7 +1784,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
UpdatedTime: timestamppb.Now(),
|
||||
},
|
||||
@@ -1799,7 +1798,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Version: 1,
|
||||
},
|
||||
@@ -1813,7 +1812,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: "splat-auth-scope",
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
},
|
||||
},
|
||||
@@ -1832,7 +1831,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
}(),
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1864,7 +1863,7 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
}(),
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
@@ -1878,14 +1877,14 @@ func TestCreateControllerLed(t *testing.T) {
|
||||
service: testSrv,
|
||||
scopeId: scope.Global.String(),
|
||||
req: &pbs.CreateControllerLedRequest{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
},
|
||||
},
|
||||
res: &pbs.CreateControllerLedResponse{
|
||||
Item: &workers.Worker{
|
||||
Item: &pb.Worker{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "success"},
|
||||
Description: &wrapperspb.StringValue{Value: "success-description"},
|
||||
|
||||
@@ -355,10 +355,12 @@ func TestStopClusterGrpcServerAndListener(t *testing.T) {
|
||||
go grpcServer.Serve(l)
|
||||
|
||||
// Make sure it's up
|
||||
_, err = grpc.Dial(l.Addr().String(),
|
||||
grpc.WithInsecure(),
|
||||
grpcCtx, grpcCtxCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
t.Cleanup(grpcCtxCancel)
|
||||
_, err = grpc.DialContext(grpcCtx,
|
||||
l.Addr().String(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithTimeout(5*time.Second),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -557,11 +559,13 @@ func TestStopApiGrpcServerAndListener(t *testing.T) {
|
||||
go grpcServer.Serve(l)
|
||||
|
||||
// Make sure it's up
|
||||
_, err := grpc.Dial("",
|
||||
grpc.WithInsecure(),
|
||||
grpcCtx, grpcCtxCancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
t.Cleanup(grpcCtxCancel)
|
||||
_, err := grpc.DialContext(grpcCtx,
|
||||
"",
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithTimeout(10*time.Second),
|
||||
grpc.WithDialer(func(s string, d time.Duration) (net.Conn, error) {
|
||||
grpc.WithContextDialer(func(ctx context.Context, s string) (net.Conn, error) {
|
||||
return l.Dial()
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/test/bufconn"
|
||||
)
|
||||
|
||||
@@ -978,7 +979,7 @@ func startTestGreeterService(t testing.TB, greeter interceptor.GreeterServiceSer
|
||||
|
||||
conn, _ := grpc.DialContext(dialCtx, "", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||
return listener.Dial()
|
||||
}), grpc.WithInsecure())
|
||||
}), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
|
||||
t.Cleanup(func() {
|
||||
listener.Close()
|
||||
|
||||
@@ -25,7 +25,8 @@ const (
|
||||
terminationInterval = 1 * time.Minute
|
||||
)
|
||||
|
||||
// This is exported so it can be tweaked in tests
|
||||
// NonceCleanupInterval is the interval to wait between nonce cleanups. This is
|
||||
// exported so it can be tweaked in tests
|
||||
var NonceCleanupInterval = 2 * time.Minute
|
||||
|
||||
func (c *Controller) startStatusTicking(cancelCtx context.Context) {
|
||||
@@ -116,10 +117,9 @@ func (c *Controller) startTerminateCompletedSessionsTicking(cancelCtx context.Co
|
||||
if err != nil {
|
||||
event.WriteError(cancelCtx, op, err, event.WithInfoMsg("error fetching repository for terminating completed sessions"))
|
||||
} else {
|
||||
terminationCount, err := repo.TerminateCompletedSessions(cancelCtx)
|
||||
_, err := repo.TerminateCompletedSessions(cancelCtx)
|
||||
if err != nil {
|
||||
event.WriteError(cancelCtx, op, err, event.WithInfoMsg("error performing termination of completed sessions"))
|
||||
} else if terminationCount > 0 {
|
||||
}
|
||||
}
|
||||
timer.Reset(getRandomInterval())
|
||||
|
||||
Reference in new issue
Block a user