Skip to content

Commit

Permalink
Merge pull request #2348 from openziti/add-verify-traffic-verify-network
Browse files Browse the repository at this point in the history
Add verify traffic verify network
  • Loading branch information
dovholuknf authored Aug 26, 2024
2 parents b025ed3 + d85d1c0 commit ec54c97
Show file tree
Hide file tree
Showing 6 changed files with 991 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* Includes a performance update ([Issue #2340](https://github.com/openziti/ziti/issues/2340)) which should improve
connection ramp times. Previously circuits would start with a relatively low window size and ramp slowly. Circuits
will now start with a large initial window size and scale back if they can't keep up
* Added `ziti ops verify-network`. A command to aid when configuring the overlay network, this command will check config
files for obvious mistakes
* Added `ziti ops verify-traffic`. Another command to aid when configuring the overlay network, this command will ensure
the overlay network is able to pass traffic

## Component Updates and Bug Fixes

Expand Down
83 changes: 83 additions & 0 deletions internal/rest/mgmt/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright NetFoundry Inc.
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
https://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.
*/
package mgmt

import (
"context"
"github.com/openziti/edge-api/rest_management_api_client"
"github.com/openziti/edge-api/rest_management_api_client/identity"
"github.com/openziti/edge-api/rest_management_api_client/service"
"github.com/openziti/edge-api/rest_management_api_client/service_policy"
"github.com/openziti/edge-api/rest_model"
log "github.com/sirupsen/logrus"
"time"
)

func IdentityFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.IdentityDetail {
params := &identity.ListIdentitiesParams{
Filter: &filter,
Context: context.Background(),
}
params.SetTimeout(5 * time.Second)
resp, err := client.Identity.ListIdentities(params, nil)
if err != nil {
log.Debugf("Could not obtain an ID for the identity with filter %s: %v", filter, err)
return nil
}

if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
return nil
}
return resp.Payload.Data[0]
}

func ServiceFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.ServiceDetail {
params := &service.ListServicesParams{
Filter: &filter,
Context: context.Background(),
}
params.SetTimeout(5 * time.Second)
resp, err := client.Service.ListServices(params, nil)
if err != nil {
log.Debugf("Could not obtain an ID for the service with filter %s: %v", filter, err)
return nil
}
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
return nil
}
return resp.Payload.Data[0]
}

func ServicePolicyFromFilter(client *rest_management_api_client.ZitiEdgeManagement, filter string) *rest_model.ServicePolicyDetail {
params := &service_policy.ListServicePoliciesParams{
Filter: &filter,
Context: context.Background(),
}
params.SetTimeout(5 * time.Second)
resp, err := client.ServicePolicy.ListServicePolicies(params, nil)
if err != nil {
log.Errorf("Could not obtain an ID for the service with filter %s: %v", filter, err)
return nil
}
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
return nil
}
return resp.Payload.Data[0]
}

func NameFilter(name string) string {
return `name="` + name + `"`
}
5 changes: 4 additions & 1 deletion ziti/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/openziti/ziti/ziti/cmd/fabric"
"github.com/openziti/ziti/ziti/cmd/pki"
"github.com/openziti/ziti/ziti/cmd/templates"
"github.com/openziti/ziti/ziti/cmd/verify"
c "github.com/openziti/ziti/ziti/constants"
"github.com/openziti/ziti/ziti/controller"
"github.com/openziti/ziti/ziti/internal/log"
Expand Down Expand Up @@ -134,13 +135,15 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com
demoCmd := demo.NewDemoCmd(p)

opsCommands := &cobra.Command{
Use: "ops ",
Use: "ops",
Short: "Various utilities useful when operating a Ziti network",
}

opsCommands.AddCommand(database.NewCmdDb(out, err))
opsCommands.AddCommand(NewCmdLogFormat(out, err))
opsCommands.AddCommand(NewUnwrapIdentityFileCommand(out, err))
opsCommands.AddCommand(verify.NewVerifyNetwork())
opsCommands.AddCommand(verify.NewVerifyTraffic())

groups := templates.CommandGroups{
{
Expand Down
49 changes: 49 additions & 0 deletions ziti/cmd/verify/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright NetFoundry Inc.
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
https://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.
*/
package verify

import (
"github.com/sirupsen/logrus"
"runtime"
)

type controller struct {
user string
pass string
host string
port string
}

func configureLogFormat(level logrus.Level) {
logrus.SetLevel(level)
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
DisableColors: false,
ForceQuote: false,
DisableQuote: false,
EnvironmentOverrideColors: false,
DisableTimestamp: true,
FullTimestamp: false,
TimestampFormat: "",
DisableSorting: true,
SortingFunc: nil,
DisableLevelTruncation: true,
PadLevelText: true,
QuoteEmptyFields: false,
FieldMap: nil,
CallerPrettyfier: func(frame *runtime.Frame) (function string, file string) { return "", "" },
})
}
Loading

0 comments on commit ec54c97

Please sign in to comment.