Skip to content

Commit

Permalink
Add the core/v3 API, minor improvements to core/v2 (#3808)
Browse files Browse the repository at this point in the history
* Refactor core/v2 protos

This commit refactors the import paths of the core/v2 protos so
that they're easier to use from outside of the package.

* Add core/v3 API

This commit adds the beginnings of the core/v3 API. It includes
the EntityConfig and EntityState resources.

The core/v3 API expands on the ideas introduced in the core/v2 API,
and refines the Resource concept. A new core/v3.Resource interface
has been defined, and it's expected that all resources in the
core/v3 package will conform to this interface.

We've had a lot of experience developing the core/v2 API over the
last couple of years, and as a result it's been possible to
generalize that experience into code generation. Developers can
now create core/v3.Resource implementations by doing nothing more
than authoring a .proto file.

The automatically generated code has automatically generated tests
to go along with it, which should ensure that changes and updates
to the code generation over time will not cause breakage.

UnmarshalJSON has been automatically generated for all types, so
that the common pitfall of nil labels and annotations can be
avoided. All types that have ObjectMeta are therefore guaranteed
to have non-nil labels and annotations after being unmarshalled
from JSON.

Most of the automatically generated methods that implement Resource
can be overridden by writing a custom unexported method for the
type in question. See the code documentation for more details.

Validation works more cooperatively, with the automatically
generated method only checking the metadata, and then optionally
invoking the unexported validate() method, if it is present.

Any core/v3.Resource can be converted to a core/v2.Resource with
the V3ResourceToV2 function. This should allow for gradual code
repair throughout the sensu-go codebase over time.

The EntityConfig and EntityState types are a split of the original
core/v2.Entity type. These types have been introduced because we
want to start treating these data different from a storage
perspective.

Functions have been included to convert between core/v2.Entity, and
core/v3.{EntityConfig, EntityState}. This will allow developers to
gradually use EntityConfig and EntityState in the codebase without
worrying too much about compatibility.

Signed-off-by: Eric Chlebek <[email protected]>
  • Loading branch information
echlebek authored Jun 1, 2020
1 parent 494af3d commit 2c567fc
Show file tree
Hide file tree
Showing 103 changed files with 6,285 additions and 1,284 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IndentWidth: 2
ColumnLimit: 200
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Versioning](http://semver.org/spec/v2.0.0.html).
reset-password`
- The user resource now has a `password_hash` field to specify the password
hash, in place of the cleartext password
- Added the beginnings of the core/v3 API.
- Added automatically generated tests for the core/v2 API.

### Fixed
- The password verification logic when running `sensuctl user change-password`
Expand Down
51 changes: 28 additions & 23 deletions api/core/v2/adhoc.pb.go

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

13 changes: 7 additions & 6 deletions api/core/v2/adhoc.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";

import "github.com/gogo/[email protected]/gogoproto/gogo.proto";
import "meta.proto";
import "github.com/sensu/sensu-go/api/core/v2/meta.proto";

package sensu.core.v2;

Expand All @@ -15,14 +15,15 @@ option (gogoproto.testgen_all) = true;

message AdhocRequest {
// Subscriptions is the list of entity subscriptions.
repeated string subscriptions = 2 [(gogoproto.nullable) = true];
repeated string subscriptions = 2 [ (gogoproto.nullable) = true ];

// Creator is the author of the adhoc request.
string creator = 3 [(gogoproto.nullable) = true];
string creator = 3 [ (gogoproto.nullable) = true ];

// Reason is used to provide context to the request.
string reason = 4 [(gogoproto.nullable) = true];
string reason = 4 [ (gogoproto.nullable) = true ];

// Metadata contains the name, namespace, labels and annotations of the AdhocCheck
ObjectMeta metadata = 5 [(gogoproto.jsontag) = "metadata", (gogoproto.embed) = true, (gogoproto.nullable) = false];
// Metadata contains the name, namespace, labels and annotations of the
// AdhocCheck
ObjectMeta metadata = 5 [ (gogoproto.jsontag) = "metadata", (gogoproto.embed) = true, (gogoproto.nullable) = false ];
}
2 changes: 1 addition & 1 deletion api/core/v2/adhocpb_test.go

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

37 changes: 20 additions & 17 deletions api/core/v2/any.pb.go

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

2 changes: 1 addition & 1 deletion api/core/v2/anypb_test.go

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

51 changes: 28 additions & 23 deletions api/core/v2/apikey.pb.go

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

7 changes: 4 additions & 3 deletions api/core/v2/apikey.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";

import "github.com/gogo/[email protected]/gogoproto/gogo.proto";
import "meta.proto";
import "github.com/sensu/sensu-go/api/core/v2/meta.proto";

package sensu.core.v2;

Expand All @@ -18,8 +18,9 @@ message APIKey {
option (gogoproto.face) = true;
option (gogoproto.goproto_getters) = false;

// Metadata contains the name, namespace (N/A), labels and annotations of the APIKey.
ObjectMeta metadata = 1 [(gogoproto.jsontag) = "metadata,omitempty", (gogoproto.embed) = true, (gogoproto.nullable) = false];
// Metadata contains the name, namespace (N/A), labels and annotations of
// the APIKey.
ObjectMeta metadata = 1 [ (gogoproto.jsontag) = "metadata,omitempty", (gogoproto.embed) = true, (gogoproto.nullable) = false ];

// Username is the username associated with the API key.
string username = 2;
Expand Down
2 changes: 1 addition & 1 deletion api/core/v2/apikeypb_test.go

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

Loading

0 comments on commit 2c567fc

Please sign in to comment.