Change connection limit to -1 for unlimited so it works with TF (#383)

* Migrate connection limit unlimited value to -1

* Fix authorization check
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-20 15:53:49 -04:00
1 parent 5214f14105
commit edffc7863d
18 files changed
+152 -124

No files matched your search

@@ -652,8 +652,8 @@ func toProto(in target.Target, m []*target.TargetSet) (*pb.Target, error) {
UpdatedTime: in.GetUpdateTime().GetTimestamp(),
Version: in.GetVersion(),
Type: target.TcpTargetType.String(),
SessionMaxSeconds: &wrapperspb.UInt32Value{Value: in.GetSessionMaxSeconds()},
SessionConnectionLimit: &wrapperspb.UInt32Value{Value: in.GetSessionConnectionLimit()},
SessionMaxSeconds: wrapperspb.UInt32(in.GetSessionMaxSeconds()),
SessionConnectionLimit: wrapperspb.Int32(in.GetSessionConnectionLimit()),
}
if in.GetDescription() != "" {
out.Description = wrapperspb.String(in.GetDescription())
@@ -698,6 +698,18 @@ func validateCreateRequest(req *pbs.CreateTargetRequest) error {
if req.GetItem().GetName() == nil || req.GetItem().GetName().GetValue() == "" {
badFields["name"] = "This field is required."
}
if req.GetItem().GetSessionConnectionLimit() != nil {
val := req.GetItem().GetSessionConnectionLimit().GetValue()
switch {
case val == -1:
case val > 0:
default:
badFields["session_connection_limit"] = "This must be -1 (unlimited) or greater than zero."
}
}
if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 {
badFields["session_max_seconds"] = "This must be greater than zero."
}
switch target.SubtypeFromType(req.GetItem().GetType()) {
case target.TcpSubType:
tcpAttrs := &pb.TcpTargetAttributes{}
@@ -725,6 +737,18 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), "name") && req.GetItem().GetName().GetValue() == "" {
badFields["name"] = "This field cannot be set to empty."
}
if req.GetItem().GetSessionConnectionLimit() != nil {
val := req.GetItem().GetSessionConnectionLimit().GetValue()
switch {
case val == -1:
case val > 0:
default:
badFields["session_connection_limit"] = "This must be -1 (unlimited) or greater than zero."
}
}
if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 {
badFields["session_max_seconds"] = "This must be greater than zero."
}
switch target.SubtypeFromType(req.GetItem().GetType()) {
case target.TcpSubType:
tcpAttrs := &pb.TcpTargetAttributes{}
@@ -77,8 +77,8 @@ func TestGet(t *testing.T) {
Type: target.TcpTargetType.String(),
HostSetIds: []string{hs[0].GetPublicId(), hs[1].GetPublicId()},
Attributes: new(structpb.Struct),
SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800},
SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(1),
}
for _, ihs := range hs {
pTar.HostSets = append(pTar.HostSets, &pb.HostSet{Id: ihs.GetPublicId(), HostCatalogId: ihs.GetCatalogId()})
@@ -157,8 +157,8 @@ func TestList(t *testing.T) {
Version: tar.GetVersion(),
Type: target.TcpTargetType.String(),
Attributes: new(structpb.Struct),
SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800},
SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(1),
})
}
@@ -308,8 +308,8 @@ func TestCreate(t *testing.T) {
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
"default_port": structpb.NewNumberValue(2),
}},
SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800},
SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(1),
},
},
errCode: codes.OK,
@@ -458,7 +458,7 @@ func TestUpdate(t *testing.T) {
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
res: &pbs.UpdateTargetResponse{
@@ -476,7 +476,7 @@ func TestUpdate(t *testing.T) {
HostSetIds: hsIds,
HostSets: hostSets,
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
errCode: codes.OK,
@@ -507,7 +507,7 @@ func TestUpdate(t *testing.T) {
HostSetIds: hsIds,
HostSets: hostSets,
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
errCode: codes.OK,
@@ -592,7 +592,7 @@ func TestUpdate(t *testing.T) {
HostSetIds: hsIds,
HostSets: hostSets,
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
errCode: codes.OK,
@@ -623,7 +623,7 @@ func TestUpdate(t *testing.T) {
HostSetIds: hsIds,
HostSets: hostSets,
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
errCode: codes.OK,
@@ -654,7 +654,7 @@ func TestUpdate(t *testing.T) {
HostSetIds: hsIds,
HostSets: hostSets,
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.UInt32(5),
SessionConnectionLimit: wrapperspb.Int32(5),
},
},
errCode: codes.OK,