Create User Service Handler and SDK (#106)

* Create user handler stuff.

* Fixing Not Found errors from DB.

* Fixing param names.

* Update the proto's go package generation.

* Generate the user resource.

* Adding SDK methods for users.

* Fix the base type of Users and add tests.

* Connect user service to the controller handler.

* Attach the default org to the Test Controller's client.

* Take into account the provided request paths when the client builds the org/project path prefix.

* Adding comments to the API.

* rename repo function to repoFn.

* Fix typo in update mask errors.

* Clean up tests.

* Remove special checks for request url content in the api client and fix CORS test.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-06-09 11:20:59 -07:00
1 parent 2c3fbe3024
commit df6ca5289f
25 files changed
+3845 -9

No files matched your search

@@ -0,0 +1,32 @@
syntax = "proto3";
package controller.api.resources.users.v1;
option go_package = "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/users;users";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
// User contains all fields related to a User resource
message User {
// The ID of the Project
// Output only.
string id = 1;
// Optional name for identification purposes
google.protobuf.StringValue name = 2;
// Optional user-set descripton for identification purposes
google.protobuf.StringValue description = 3;
// The time this resource was created
// Output only.
google.protobuf.Timestamp created_time = 4 [json_name="created_time"];
// The time this resource was last updated.
// Output only.
google.protobuf.Timestamp updated_time = 5 [json_name="updated_time"];
// Whether the resource is disabled
google.protobuf.BoolValue disabled = 6;
}
@@ -0,0 +1,139 @@
syntax = "proto3";
package controller.api.services.v1;
option go_package = "github.com/hashicorp/watchtower/internal/gen/controller/api/services;services";
import "protoc-gen-swagger/options/annotations.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/wrappers.proto";
import "controller/api/resources/users/v1/user.proto";
service UserService {
// GetUser returns a stored User if present. The provided request
// must include the org and user id for the user being retrieved. If
// any of those ids are missing, malformed or reference a non existing
// resource an error is returned.
rpc GetUser(GetUserRequest) returns (GetUserResponse) {
option (google.api.http) = {
get: "/v1/orgs/{org_id}/users/{id}"
response_body: "item"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Gets a single User"
};
}
// ListUsers returns a list of stored users which exist inside the org
// referenced inside the request. The request must include the org id for
// the users being retrieved. If the org id is missing, malformed, or
// reference a non existing organization, an error is returned.
rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) {
option (google.api.http) = {
get: "/v1/orgs/{org_id}/users"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Lists all Users"
};
}
// CreateUser creates and stores a user in watchtower. The provided
// request must include the org id in which the user will be created.
// If the org id is missing, malformed or references a non existing
// organization, an error is returned. If a name is provided that is in
// use in another user in the same organization, an error is returned.
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) {
option (google.api.http) = {
post: "/v1/orgs/{org_id}/users"
body: "item"
response_body: "item"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Creates a single User"
};
}
// UpdateUser updates an existing user in watchtower. The provided
// user must not have any read only fields set. The update mask must be
// included in the request and contain at least 1 mutable field. To unset
// a field's value, include the field in the update mask and don't set it
// in the provided user. An error is returned if either the organization
// or user ids are missing or reference a non existing resource. An error
// is also returned if the request attempts to update the name to one that is
// already in use in this organization.
rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse) {
option (google.api.http) = {
patch: "/v1/orgs/{org_id}/users/{id}"
body: "item"
response_body: "item"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Updates a User"
};
}
// DeleteUser removes a user from Watchtower. If the provided org or user ids
// are malformed or not provided an error is returned. No error is returned
// if either ids reference resources that do not exist as the response itself
// specifies if the resource existed before the DeleteUser request was
// received.
rpc DeleteUser(DeleteUserRequest) returns (DeleteUserResponse) {
option (google.api.http) = {
delete: "/v1/orgs/{org_id}/users/{id}"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
summary: "Deletes a User"
};
}
}
message GetUserRequest {
string org_id = 1;
string id = 2;
string view = 3;
}
message GetUserResponse {
resources.users.v1.User item = 1;
}
message ListUsersRequest {
string org_id = 1;
string view = 2;
}
message ListUsersResponse {
repeated resources.users.v1.User items = 1;
}
message CreateUserRequest {
string org_id = 1;
resources.users.v1.User item = 2;
}
message CreateUserResponse {
string uri = 1;
resources.users.v1.User item = 2;
}
message UpdateUserRequest {
string org_id = 1;
string id = 2;
resources.users.v1.User item = 3;
google.protobuf.FieldMask update_mask = 4;
}
message UpdateUserResponse {
resources.users.v1.User item = 1;
}
message DeleteUserRequest {
string org_id = 1;
string id = 2;
}
message DeleteUserResponse {
bool existed = 1;
}