Skip to content

Commit 2a2cde3

Browse files
committed
fix: add proper migration, start service account api
1 parent 73121c5 commit 2a2cde3

File tree

7 files changed

+49
-15
lines changed

7 files changed

+49
-15
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateServiceAccounts < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :service_accounts, id: false do |t|
4+
t.uuid :id, primary_key: true, null: false
5+
t.string :description
6+
t.uuid :creator_id, null: false
7+
end
8+
9+
add_foreign_key :service_accounts, :users, column: :id, on_delete: :cascade
10+
add_foreign_key :service_accounts, :users, column: :creator_id, on_delete: :nullify
11+
end
12+
end

guard/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,6 @@ endif
141141
/home/protoc/source/encryptor.proto
142142
docker run --rm -v $(PWD):/home/protoc/code -v $(TMP_INTERNAL_REPO_DIR):/home/protoc/source renderedtext/protoc:$(RT_PROTOC_IMG_VSN) protoc -I /home/protoc/source -I /home/protoc/source/include --elixir_out=plugins=grpc:$(RELATIVE_INTERNAL_PB_OUTPUT_DIR) --plugin=/root/.mix/escripts/protoc-gen-elixir \
143143
/home/protoc/source/instance_config.proto
144+
docker run --rm -v $(PWD):/home/protoc/code -v $(TMP_INTERNAL_REPO_DIR):/home/protoc/source renderedtext/protoc:$(RT_PROTOC_IMG_VSN) protoc -I /home/protoc/source -I /home/protoc/source/include --elixir_out=plugins=grpc:$(RELATIVE_INTERNAL_PB_OUTPUT_DIR) --plugin=/root/.mix/escripts/protoc-gen-elixir \
145+
/home/protoc/source/service_account.proto
144146
rm -rf $(TMP_INTERNAL_REPO_DIR)

guard/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ services:
5050
START_GPRC_GUARD_API: "true"
5151
START_GRPC_AUTH_API: "true"
5252
START_GRPC_USER_API: "true"
53+
START_GRPC_SERVICE_ACCOUNT_API: "true"
5354
START_GRPC_ORGANIZATION_API: "true"
5455
START_GRPC_INSTANCE_CONFIG_API: "true"
5556
INSTANCE_CONFIG_API: "true"

guard/helm/templates/service.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ spec:
100100
---
101101
apiVersion: v1
102102
kind: Service
103+
metadata:
104+
name: "{{ .Chart.Name }}-service-account-api"
105+
namespace: {{ .Release.Namespace }}
106+
spec:
107+
type: NodePort
108+
selector:
109+
{{- if .Values.global.development.minimalDeployment }}
110+
app: "{{ .Chart.Name }}"
111+
{{- else }}
112+
app: "{{ .Chart.Name }}-user-api"
113+
{{- end }}
114+
ports:
115+
- name: grpc
116+
port: 50051
117+
targetPort: 50051
118+
protocol: TCP
119+
---
120+
apiVersion: v1
121+
kind: Service
103122
metadata:
104123
name: "{{ .Chart.Name }}-organization-api"
105124
namespace: {{ .Release.Namespace }}

guard/helm/templates/user-api-dpl.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ spec:
8989
value: "false"
9090
- name: START_GRPC_USER_API
9191
value: "true"
92+
- name: START_GRPC_SERVICE_ACCOUNT_API
93+
value: "true"
9294
- name: START_GPRC_HEALTH_CHECK
9395
value: "true"
9496
- name: RABBIT_CONSUMER
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Guard.FrontRepo.Migrations.CreateServiceAccounts do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:service_accounts, primary_key: false) do
6+
add :id, references(:users, type: :binary_id, on_delete: :delete_all),
7+
primary_key: true, null: false
8+
add :description, :string
9+
add :creator_id, references(:users, type: :binary_id, on_delete: :nilify_all),
10+
null: false
11+
end
12+
end
13+
end

guard/test/guard/front_repo/service_account_test.exs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,6 @@ defmodule Guard.FrontRepo.ServiceAccountTest do
159159
assert {"has already been taken", _} = changeset.errors[:user_id]
160160
end
161161

162-
test "sets timestamps on creation" do
163-
user = create_test_user()
164-
165-
attrs = %{
166-
user_id: user.id,
167-
description: "Test description"
168-
}
169-
170-
changeset = ServiceAccount.changeset(%ServiceAccount{}, attrs)
171-
{:ok, service_account} = FrontRepo.insert(changeset)
172-
173-
assert service_account.created_at != nil
174-
assert service_account.updated_at != nil
175-
assert service_account.created_at == service_account.updated_at
176-
end
177162
end
178163

179164
describe "update_changeset/2" do

0 commit comments

Comments
 (0)