Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ack to cli

- it's been deprecated/archived so not getting updates
- and it was using ginkgo v1
- bumped to ginkgo v2
- attempted to fix networking_connection.go to use errors.As since that's a go 1.20 thing we fixed in 325af3c
- but it only fixed one test and I don't understand why the other is failing
- still seed flag errors
  • Loading branch information
moleske committed Feb 5, 2024
1 parent 17d801a commit a92362c
Show file tree
Hide file tree
Showing 50 changed files with 3,811 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion actor/cfnetworkingaction/networking_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cfnetworkingaction

import "code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1"
import "code.cloudfoundry.org/cli/api/cfnetworking/cfnetv1"

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . NetworkingClient

Expand Down
2 changes: 1 addition & 1 deletion actor/cfnetworkingaction/policy.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cfnetworkingaction

import (
"code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cfnetworking/cfnetv1"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/resources"
Expand Down
2 changes: 1 addition & 1 deletion actor/cfnetworkingaction/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/util/batcher"

"code.cloudfoundry.org/cfnetworking-cli-api/cfnetworking/cfnetv1"
"code.cloudfoundry.org/cli/actor/actionerror"
. "code.cloudfoundry.org/cli/actor/cfnetworkingaction"
"code.cloudfoundry.org/cli/actor/cfnetworkingaction/cfnetworkingactionfakes"
"code.cloudfoundry.org/cli/api/cfnetworking/cfnetv1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
56 changes: 56 additions & 0 deletions api/cfnetworking/cfnetv1/cfnetv1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cfnetv1_test

import (
"bytes"
"log"

. "code.cloudfoundry.org/cli/api/cfnetworking/cfnetv1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/ghttp"

"testing"
)

func TestCFNetV1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CF Networking V1 Client Suite")
}

var server *Server

var _ = SynchronizedBeforeSuite(func() []byte {
return []byte{}
}, func(data []byte) {
server = NewTLSServer()

// Suppresses ginkgo server logs
server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
})

var _ = SynchronizedAfterSuite(func() {
server.Close()
}, func() {})

var _ = BeforeEach(func() {
server.Reset()
})

func NewTestClient(passed ...Config) *Client {
var config Config
if len(passed) > 0 {
config = passed[0]
} else {
config = Config{}
}
config.AppName = "CF Networking V1 Test"
config.AppVersion = "Unknown"
config.SkipSSLValidation = true

if config.URL == "" {
config.URL = server.URL()
}

return NewClient(config)
}
162 changes: 162 additions & 0 deletions api/cfnetworking/cfnetv1/cfnetv1fakes/fake_connection_wrapper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions api/cfnetworking/cfnetv1/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Package cfnetv1 represents a CF Networking V1 client.
//
// These sets of packages are still under development/pre-pre-pre...alpha. Use
// at your own risk! Functionality and design may change without warning.
//
// For more information on the CF Networking API see
// https://github.com/cloudfoundry-incubator/cf-networking-release/blob/develop/docs/API.md
//
// # Method Naming Conventions
//
// The client takes a '<Action Name><Top Level Endpoint><Return Value>'
// approach to method names. If the <Top Level Endpoint> and <Return Value>
// are similar, they do not need to be repeated. If a GUID is required for the
// <Top Level Endpoint>, the pluralization is removed from said endpoint in the
// method name.
//
// For Example:
//
// Method Name: GetApplication
// Endpoint: /v2/applications/:guid
// Action Name: Get
// Top Level Endpoint: applications
// Return Value: Application
//
// Method Name: GetServiceInstances
// Endpoint: /v2/service_instances
// Action Name: Get
// Top Level Endpoint: service_instances
// Return Value: []ServiceInstance
//
// Method Name: GetSpaceServiceInstances
// Endpoint: /v2/spaces/:guid/service_instances
// Action Name: Get
// Top Level Endpoint: spaces
// Return Value: []ServiceInstance
//
// Use the following table to determine which HTTP Command equates to which
// Action Name:
//
// HTTP Command -> Action Name
// POST -> Create
// GET -> Get
// PUT -> Update
// DELETE -> Delete
//
// # Method Locations
//
// Methods exist in the same file as their return type, regardless of which
// endpoint they use.
//
// # Error Handling
//
// All error handling that requires parsing the error_code/code returned back
// from the Cloud Controller should be placed in the errorWrapper. Everything
// else can be handled in the individual operations. All parsed cloud
// controller errors should exist in errors.go, all generic HTTP errors should
// exist in the cloudcontroller's errors.go. Errors related to the individaul
// operation should exist at the top of that operation's file.
//
// # No inline-relations-depth And summary Endpoints
//
// This package will not use ever use 'inline-relations-depth' or the
// '/summary' endpoints for any operations. These requests can be extremely
// taxing on the Cloud Controller and are avoided at all costs. Additionally,
// the objects returned back from these requests can become extremely
// inconsistant across versions and are problematic to deal with in general.
package cfnetv1

import (
"fmt"
"runtime"
"time"

"code.cloudfoundry.org/cli/api/cfnetworking"
"code.cloudfoundry.org/cli/api/cfnetworking/cfnetv1/internal"

"github.com/tedsuo/rata"
)

// Client is a client that can be used to talk to a CF Networking API.
type Client struct {
connection cfnetworking.Connection
router *rata.RequestGenerator
url string
userAgent string
}

// Config allows the Client to be configured
type Config struct {
// AppName is the name of the application/process using the client.
AppName string

// AppVersion is the version of the application/process using the client.
AppVersion string

// DialTimeout is the DNS timeout used to make all requests to the Cloud
// Controller.
DialTimeout time.Duration

// SkipSSLValidation controls whether a client verifies the server's
// certificate chain and host name. If SkipSSLValidation is true, TLS accepts
// any certificate presented by the server and any host name in that
// certificate for *all* client requests going forward.
//
// In this mode, TLS is susceptible to man-in-the-middle attacks. This should
// be used only for testing.
SkipSSLValidation bool

// URL is a fully qualified URL to the CF Networking API.
URL string

// Wrappers that apply to the client connection.
Wrappers []ConnectionWrapper
}

// NewClient returns a new CF Networking client.
func NewClient(config Config) *Client {
userAgent := fmt.Sprintf("%s/%s (%s; %s %s)", config.AppName, config.AppVersion, runtime.Version(), runtime.GOARCH, runtime.GOOS)

connection := cfnetworking.NewConnection(cfnetworking.Config{
DialTimeout: config.DialTimeout,
SkipSSLValidation: config.SkipSSLValidation,
})

wrappedConnection := cfnetworking.NewErrorWrapper().Wrap(connection)
for _, wrapper := range config.Wrappers {
wrappedConnection = wrapper.Wrap(wrappedConnection)
}

client := &Client{
connection: wrappedConnection,
router: rata.NewRequestGenerator(config.URL, internal.Routes),
url: config.URL,
userAgent: userAgent,
}

return client
}
Loading

0 comments on commit a92362c

Please sign in to comment.