-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move generic client APIs into pkg/apis/
This makes much more visible which APIs are supported by the generic client, makes it easier to have generic client supporting APIs not sharing any code with existing old clients and is a place where other big projects place their API definitions. Also adds code generator comments to the objects and fixes lbaasv1.Frontend (which wasn't an object anymore - code gen test catched it).
- Loading branch information
1 parent
6e6d43e
commit 32ca322
Showing
24 changed files
with
445 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
"github.com/anexia-it/go-anxcloud/pkg/api" | ||
"github.com/anexia-it/go-anxcloud/pkg/api/types" | ||
"github.com/go-logr/logr" | ||
) | ||
|
||
func (i Info) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
u, err := url.ParseRequestURI("/api/core/v1/resource.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op, err := types.OperationFromContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
switch op { | ||
// OperationCreate is not supported because the API does not exist in the engine. | ||
// OperationDestroy and OperationUpdate is not yet implemented | ||
case types.OperationCreate, types.OperationDestroy, types.OperationUpdate: | ||
return nil, api.ErrOperationNotSupported | ||
} | ||
|
||
if op == types.OperationList { | ||
query := u.Query() | ||
|
||
if len(i.Tags) > 1 { | ||
logr.FromContextOrDiscard(ctx).Info("Listing with multiple tags isn't supported. Only first one used") | ||
} | ||
|
||
if len(i.Tags) > 0 { | ||
query.Add("tag_name", i.Tags[0]) | ||
} | ||
u.RawQuery = query.Encode() | ||
} | ||
return u, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package v1 | ||
|
||
// Type is part of info. | ||
type Type struct { | ||
Identifier string `json:"identifier"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// anxcloud:object | ||
|
||
// Info contains all information about a resource. | ||
type Info struct { | ||
Identifier string `json:"identifier" anxcloud:"identifier"` | ||
Name string `json:"name"` | ||
Type Type `json:"resource_type"` | ||
Tags []string `json:"tags"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package v1 | ||
|
||
import ( | ||
. "github.com/anexia-it/go-anxcloud/pkg/utils/test/gomega" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/anexia-it/go-anxcloud/pkg/api/types" | ||
) | ||
|
||
var _ = Describe("Object Info", func() { | ||
It("implements the interface types.Object", func() { | ||
var i types.Object | ||
o := Info{} | ||
Expect(&o).To(ImplementInterface(&i)) | ||
}) | ||
}) |
Oops, something went wrong.