Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): Public key settings to allow name and creation date to… #805

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/proto/neoshowcase/protobuf/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ message UserKey {
string id = 1;
string user_id = 2;
string public_key = 3;
string name = 4;
google.protobuf.Timestamp created_at = 5;
}

// -- Repository
Expand Down Expand Up @@ -288,6 +290,7 @@ message GetUserKeysResponse {

message CreateUserKeyRequest {
string public_key = 1;
string name = 2;
}

message DeleteUserKeyRequest {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/api/neoshowcase/protobuf/gateway_connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-connect-es v1.1.3 with parameter "target=ts"
// @generated by protoc-gen-connect-es v1.1.4 with parameter "target=ts"
// @generated from file neoshowcase/protobuf/gateway.proto (package neoshowcase.protobuf, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down
18 changes: 18 additions & 0 deletions dashboard/src/api/neoshowcase/protobuf/gateway_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@ export class UserKey extends Message<UserKey> {
*/
publicKey = "";

/**
* @generated from field: string name = 4;
*/
name = "";

/**
* @generated from field: google.protobuf.Timestamp created_at = 5;
*/
createdAt?: Timestamp;

constructor(data?: PartialMessage<UserKey>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -422,6 +432,8 @@ export class UserKey extends Message<UserKey> {
{ no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "public_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "created_at", kind: "message", T: Timestamp },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): UserKey {
Expand Down Expand Up @@ -1987,6 +1999,11 @@ export class CreateUserKeyRequest extends Message<CreateUserKeyRequest> {
*/
publicKey = "";

/**
* @generated from field: string name = 2;
*/
name = "";

constructor(data?: PartialMessage<CreateUserKeyRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -1996,6 +2013,7 @@ export class CreateUserKeyRequest extends Message<CreateUserKeyRequest> {
static readonly typeName = "neoshowcase.protobuf.CreateUserKeyRequest";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "public_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): CreateUserKeyRequest {
Expand Down
4 changes: 3 additions & 1 deletion docs/dbschema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| [repository_auth](repository_auth.md) | 5 | Gitリポジトリ認証情報テーブル | BASE TABLE |
| [repository_owners](repository_owners.md) | 2 | リポジトリ所有者テーブル | BASE TABLE |
| [users](users.md) | 3 | ユーザーテーブル | BASE TABLE |
| [user_keys](user_keys.md) | 3 | ユーザーSSHキーテーブル | BASE TABLE |
| [user_keys](user_keys.md) | 5 | ユーザーSSHキーテーブル | BASE TABLE |
| [websites](websites.md) | 9 | Webサイトテーブル | BASE TABLE |

## Relations
Expand Down Expand Up @@ -126,6 +126,8 @@ erDiagram
char_22_ id PK
char_22_ user_id FK
text public_key
varchar_255_ name
datetime_6_ created_at
}
"websites" {
char_22_ id PK
Expand Down
6 changes: 6 additions & 0 deletions docs/dbschema/user_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CREATE TABLE `user_keys` (
`id` char(22) NOT NULL COMMENT 'ID',
`user_id` char(22) NOT NULL COMMENT 'ユーザーID',
`public_key` text NOT NULL COMMENT 'SSH Public Key',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'キー名',
`created_at` datetime(6) NOT NULL DEFAULT '1970-01-01 00:00:00.000000' COMMENT '作成日時',
PRIMARY KEY (`id`),
KEY `fk_user_keys_user_id` (`user_id`),
CONSTRAINT `fk_user_keys_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
Expand All @@ -27,6 +29,8 @@ CREATE TABLE `user_keys` (
| id | char(22) | | false | | | ID |
| user_id | char(22) | | false | | [users](users.md) | ユーザーID |
| public_key | text | | false | | | SSH Public Key |
| name | varchar(255) | '' | false | | | キー名 |
| created_at | datetime(6) | '1970-01-01 00:00:00.000000' | false | | | 作成日時 |

## Constraints

Expand All @@ -53,6 +57,8 @@ erDiagram
char_22_ id PK
char_22_ user_id FK
text public_key
varchar_255_ name
datetime_6_ created_at
}
"users" {
char_22_ id PK
Expand Down
2 changes: 2 additions & 0 deletions docs/dbschema/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ erDiagram
char_22_ id PK
char_22_ user_id FK
text public_key
varchar_255_ name
datetime_6_ created_at
}
```

Expand Down
2 changes: 2 additions & 0 deletions migrations/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CREATE TABLE `user_keys`
`id` CHAR(22) NOT NULL COMMENT 'ID',
`user_id` CHAR(22) NOT NULL COMMENT 'ユーザーID',
`public_key` TEXT NOT NULL COMMENT 'SSH Public Key',
`name` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'キー名',
`created_at` DATETIME(6) NOT NULL DEFAULT '1970-01-01 00:00:00.000000' COMMENT '作成日時',
PRIMARY KEY (`id`),
CONSTRAINT `fk_user_keys_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE = InnoDB
Expand Down
8 changes: 7 additions & 1 deletion pkg/domain/app_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package domain

import (
"time"

"github.com/friendsofgo/errors"
"golang.org/x/crypto/ssh"
)
Expand Down Expand Up @@ -29,13 +31,17 @@ type UserKey struct {
ID string
UserID string
PublicKey string
Name string
CreatedAt time.Time
}

func NewUserKey(userID string, publicKey string) (*UserKey, error) {
func NewUserKey(userID string, publicKey string, name string) (*UserKey, error) {
key := &UserKey{
ID: NewID(),
UserID: userID,
PublicKey: publicKey,
Name: name,
CreatedAt: time.Now(),
}
if err := key.Validate(); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/infrastructure/grpc/api_user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *APIService) GetUsers(ctx context.Context, _ *connect.Request[emptypb.Em
}

func (s *APIService) CreateUserKey(ctx context.Context, c *connect.Request[pb.CreateUserKeyRequest]) (*connect.Response[pb.UserKey], error) {
key, err := s.svc.CreateUserKey(ctx, c.Msg.PublicKey)
key, err := s.svc.CreateUserKey(ctx, c.Msg.PublicKey, c.Msg.Name)
if err != nil {
return nil, handleUseCaseError(err)
}
Expand Down
Loading