Skip to content

Commit ec54c97

Browse files
authored
Merge pull request #2348 from openziti/add-verify-traffic-verify-network
Add verify traffic verify network
2 parents b025ed3 + d85d1c0 commit ec54c97

File tree

6 files changed

+991
-1
lines changed

6 files changed

+991
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* Includes a performance update ([Issue #2340](https://github.com/openziti/ziti/issues/2340)) which should improve
77
connection ramp times. Previously circuits would start with a relatively low window size and ramp slowly. Circuits
88
will now start with a large initial window size and scale back if they can't keep up
9+
* Added `ziti ops verify-network`. A command to aid when configuring the overlay network, this command will check config
10+
files for obvious mistakes
11+
* Added `ziti ops verify-traffic`. Another command to aid when configuring the overlay network, this command will ensure
12+
the overlay network is able to pass traffic
913

1014
## Component Updates and Bug Fixes
1115

internal/rest/mgmt/helpers.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright NetFoundry Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package mgmt
17+
18+
import (
19+
"context"
20+
"github.com/openziti/edge-api/rest_management_api_client"
21+
"github.com/openziti/edge-api/rest_management_api_client/identity"
22+
"github.com/openziti/edge-api/rest_management_api_client/service"
23+
"github.com/openziti/edge-api/rest_management_api_client/service_policy"
24+
"github.com/openziti/edge-api/rest_model"
25+
log "github.com/sirupsen/logrus"
26+
"time"
27+
)
28+
29+
func IdentityFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.IdentityDetail {
30+
params := &identity.ListIdentitiesParams{
31+
Filter: &filter,
32+
Context: context.Background(),
33+
}
34+
params.SetTimeout(5 * time.Second)
35+
resp, err := client.Identity.ListIdentities(params, nil)
36+
if err != nil {
37+
log.Debugf("Could not obtain an ID for the identity with filter %s: %v", filter, err)
38+
return nil
39+
}
40+
41+
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
42+
return nil
43+
}
44+
return resp.Payload.Data[0]
45+
}
46+
47+
func ServiceFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.ServiceDetail {
48+
params := &service.ListServicesParams{
49+
Filter: &filter,
50+
Context: context.Background(),
51+
}
52+
params.SetTimeout(5 * time.Second)
53+
resp, err := client.Service.ListServices(params, nil)
54+
if err != nil {
55+
log.Debugf("Could not obtain an ID for the service with filter %s: %v", filter, err)
56+
return nil
57+
}
58+
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
59+
return nil
60+
}
61+
return resp.Payload.Data[0]
62+
}
63+
64+
func ServicePolicyFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.ServicePolicyDetail {
65+
params := &service_policy.ListServicePoliciesParams{
66+
Filter: &filter,
67+
Context: context.Background(),
68+
}
69+
params.SetTimeout(5 * time.Second)
70+
resp, err := client.ServicePolicy.ListServicePolicies(params, nil)
71+
if err != nil {
72+
log.Errorf("Could not obtain an ID for the service with filter %s: %v", filter, err)
73+
return nil
74+
}
75+
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
76+
return nil
77+
}
78+
return resp.Payload.Data[0]
79+
}
80+
81+
func NameFilter(name string) string {
82+
return `name="` + name + `"`
83+
}

ziti/cmd/cmd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/openziti/ziti/ziti/cmd/fabric"
3434
"github.com/openziti/ziti/ziti/cmd/pki"
3535
"github.com/openziti/ziti/ziti/cmd/templates"
36+
"github.com/openziti/ziti/ziti/cmd/verify"
3637
c "github.com/openziti/ziti/ziti/constants"
3738
"github.com/openziti/ziti/ziti/controller"
3839
"github.com/openziti/ziti/ziti/internal/log"
@@ -134,13 +135,15 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com
134135
demoCmd := demo.NewDemoCmd(p)
135136

136137
opsCommands := &cobra.Command{
137-
Use: "ops ",
138+
Use: "ops",
138139
Short: "Various utilities useful when operating a Ziti network",
139140
}
140141

141142
opsCommands.AddCommand(database.NewCmdDb(out, err))
142143
opsCommands.AddCommand(NewCmdLogFormat(out, err))
143144
opsCommands.AddCommand(NewUnwrapIdentityFileCommand(out, err))
145+
opsCommands.AddCommand(verify.NewVerifyNetwork())
146+
opsCommands.AddCommand(verify.NewVerifyTraffic())
144147

145148
groups := templates.CommandGroups{
146149
{

ziti/cmd/verify/common.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright NetFoundry Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package verify
17+
18+
import (
19+
"github.com/sirupsen/logrus"
20+
"runtime"
21+
)
22+
23+
type controller struct {
24+
user string
25+
pass string
26+
host string
27+
port string
28+
}
29+
30+
func configureLogFormat(level logrus.Level) {
31+
logrus.SetLevel(level)
32+
logrus.SetFormatter(&logrus.TextFormatter{
33+
ForceColors: true,
34+
DisableColors: false,
35+
ForceQuote: false,
36+
DisableQuote: false,
37+
EnvironmentOverrideColors: false,
38+
DisableTimestamp: true,
39+
FullTimestamp: false,
40+
TimestampFormat: "",
41+
DisableSorting: true,
42+
SortingFunc: nil,
43+
DisableLevelTruncation: true,
44+
PadLevelText: true,
45+
QuoteEmptyFields: false,
46+
FieldMap: nil,
47+
CallerPrettyfier: func(frame *runtime.Frame) (function string, file string) { return "", "" },
48+
})
49+
}

0 commit comments

Comments
 (0)