Skip to content

Commit

Permalink
Cleanup code, add license headers
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak committed Jul 14, 2023
1 parent 0b7432e commit faefa72
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 40 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

// Copyright 2021 PANTHEON.tech
// Copyright 2023 PANTHEON.tech
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -221,4 +221,4 @@ func containsPrefix(strs []string, prefix string) (string, bool) {
}
}
return "", false
}
}
18 changes: 17 additions & 1 deletion client/component.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// SPDX-License-Identifier: Apache-2.0

// Copyright 2023 PANTHEON.tech
//
// 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
//
// http://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 client

import (
Expand Down Expand Up @@ -88,4 +104,4 @@ func cnfModeToCompoMode(cm cnfregpb.CnfMode) ComponentMode {
default:
return ComponentForeign
}
}
}
16 changes: 16 additions & 0 deletions client/http.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// SPDX-License-Identifier: Apache-2.0

// Copyright 2023 PANTHEON.tech
//
// 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
//
// http://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 client

import (
Expand Down
24 changes: 3 additions & 21 deletions cmd/swctl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func NewCli(opt ...CliOption) (*CLI, error) {
}

func (cli *CLI) Initialize(opts Options) (err error) {
// clientCfg, err := agentcli.MakeConfig()
cli.client, err = initClient()
cli.client, err = initClient(opts)
if err != nil {
return fmt.Errorf("init error: %w", err)
}
Expand All @@ -87,25 +86,8 @@ func (cli *CLI) Initialize(opts Options) (err error) {
return nil
}

func initClient() (*client.Client, error) {
// cfg, err := agentcli.MakeConfig()
// if err != nil {
// return nil, err
// }
opts := []client.Option{
// client.WithHost(cfg.Host),
// client.WithGRPCPort(uint16(cfg.GRPCPort)),
// client.WithHTTPPort(uint16(cfg.HTTPPort)),
}
// if cfg.ShouldUseSecureGRPC() {
// opts = append(opts, client.WithGRPCTLS(
// cfg.GRPCSecure.CertFile,
// cfg.GRPCSecure.KeyFile,
// cfg.GRPCSecure.CAFile,
// cfg.GRPCSecure.SkipVerify,
// ))
// }
c, err := client.NewClient(opts...)
func initClient(opts Options) (*client.Client, error) {
c, err := client.NewClient()
if err != nil {
return nil, err
}
Expand Down
24 changes: 17 additions & 7 deletions cmd/swctl/cmd_status.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// SPDX-License-Identifier: Apache-2.0

// Copyright 2023 PANTHEON.tech
//
// 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
//
// http://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 main

import (
Expand All @@ -19,12 +35,6 @@ import (
"go.pantheon.tech/stonework/client"
)

// TODO: improve status overview, show status of components (CNFs)
// - instead of using raw output from vpp-probe, retrieve the important info
// about the running/deployed components of StoneWork and show those by default
// - optionally allow user to set more details which shows the more detailed output
// similar to vpp-probe discover

const statusExample = `
<white># Show status for all components</>
$ <yellow>swctl status</>
Expand Down Expand Up @@ -290,4 +300,4 @@ func (c configCounts) color() int {
return tablewriter.FgGreenColor
}
return 0
}
}
15 changes: 7 additions & 8 deletions plugins/cnfreg/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ type swModule struct {
grpcPort int
httpPort int
grpcConn *grpc.ClientConn
// grpcConn grpc.ClientConnInterface
cnfClient pb.CnfDiscoveryClient
cfgClient client.GenericClient
cnfModels []cnfModel
cnfClient pb.CnfDiscoveryClient
cfgClient client.GenericClient
cnfModels []cnfModel
}

// Attributes specific to StoneWork Module (i.e. not used by standalone CNF or StoneWork itself).
Expand Down Expand Up @@ -244,10 +243,6 @@ func (p *Plugin) Init() (err error) {
p.Log.Infof("Discovered management IP address: %v", p.ipAddress)
}

grpcServer := p.GRPCPlugin.GetServer()
if grpcServer == nil {
return errors.New("gRPC server is not initialized")
}
switch p.cnfMode {
case pb.CnfMode_STONEWORK_MODULE:
// inject gRPC and HTTP ports to use by SW-Module
Expand All @@ -257,6 +252,10 @@ func (p *Plugin) Init() (err error) {
}

// serve CnfDiscovery methods
grpcServer := p.GRPCPlugin.GetServer()
if grpcServer == nil {
return errors.New("gRPC server is not initialized")
}
pb.RegisterCnfDiscoveryServer(grpcServer, p)

case pb.CnfMode_STONEWORK:
Expand Down
2 changes: 1 addition & 1 deletion plugins/cnfreg/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ func (p *Plugin) statusHandler(formatter *render.Render) http.HandlerFunc {
p.Log.Error(err)
}
}
}
}

0 comments on commit faefa72

Please sign in to comment.