From 97e0e778d520b6f69fc38a077bea454403294daf Mon Sep 17 00:00:00 2001 From: Krrupa <“sudonthineni@gmail.com@users.noreply.github.com”> Date: Wed, 16 Aug 2023 23:05:27 +0530 Subject: [PATCH 01/30] added column to form table --- lib/dbservice/form_schemas/form_schema.ex | 4 +++- lib/dbservice_web/views/form_schema_view.ex | 3 ++- priv/repo/migrations/20230816173334_alter_form_table.exs | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20230816173334_alter_form_table.exs diff --git a/lib/dbservice/form_schemas/form_schema.ex b/lib/dbservice/form_schemas/form_schema.ex index fabaccaa..5ce9608b 100644 --- a/lib/dbservice/form_schemas/form_schema.ex +++ b/lib/dbservice/form_schemas/form_schema.ex @@ -8,6 +8,7 @@ defmodule Dbservice.FormSchemas.FormSchema do schema "form_schema" do field(:name, :string) + field(:meta_data, :map) field(:attributes, :map) timestamps() @@ -20,7 +21,8 @@ defmodule Dbservice.FormSchemas.FormSchema do form_schema |> cast(attrs, [ :name, - :attributes + :attributes, + :meta_data ]) |> validate_required([:name]) end diff --git a/lib/dbservice_web/views/form_schema_view.ex b/lib/dbservice_web/views/form_schema_view.ex index d890b488..5863f0c3 100644 --- a/lib/dbservice_web/views/form_schema_view.ex +++ b/lib/dbservice_web/views/form_schema_view.ex @@ -13,7 +13,8 @@ defmodule DbserviceWeb.FormSchemaView do def render("form_schema.json", %{form_schema: form_schema}) do %{ name: form_schema.name, - attributes: form_schema.attributes + attributes: form_schema.attributes, + meta_data: form_schema.meta_data } end end diff --git a/priv/repo/migrations/20230816173334_alter_form_table.exs b/priv/repo/migrations/20230816173334_alter_form_table.exs new file mode 100644 index 00000000..65d897c3 --- /dev/null +++ b/priv/repo/migrations/20230816173334_alter_form_table.exs @@ -0,0 +1,9 @@ +defmodule Dbservice.Repo.Migrations.AlterFormTable do + use Ecto.Migration + + def change do + alter table(:form_schema) do + add(:meta_data, :map) + end + end +end From 5ea3fd96b21e0502e92cd789f193dc2fd1bdb59b Mon Sep 17 00:00:00 2001 From: Krrupa <25496389+sudheshna-donthineni@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:14:33 +0530 Subject: [PATCH 02/30] Update form_schema_view.ex --- lib/dbservice_web/views/form_schema_view.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dbservice_web/views/form_schema_view.ex b/lib/dbservice_web/views/form_schema_view.ex index 5863f0c3..ab49fd16 100644 --- a/lib/dbservice_web/views/form_schema_view.ex +++ b/lib/dbservice_web/views/form_schema_view.ex @@ -12,6 +12,7 @@ defmodule DbserviceWeb.FormSchemaView do def render("form_schema.json", %{form_schema: form_schema}) do %{ + id: form_schema.id, name: form_schema.name, attributes: form_schema.attributes, meta_data: form_schema.meta_data From aecb9e88fdffab32b31385c2b4d77a41bc40d0d2 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 5 Sep 2023 22:49:51 +0530 Subject: [PATCH 03/30] changed data types --- lib/dbservice/sessions/session.ex | 8 +- lib/dbservice_web/swagger_schemas/session.ex | 8 +- ...925_modify_data_types_in_session_table.exs | 23 + priv/static/swagger.json | 1325 +++++++++-------- 4 files changed, 710 insertions(+), 654 deletions(-) create mode 100644 priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs diff --git a/lib/dbservice/sessions/session.ex b/lib/dbservice/sessions/session.ex index 041ac3b7..0b41437e 100644 --- a/lib/dbservice/sessions/session.ex +++ b/lib/dbservice/sessions/session.ex @@ -25,10 +25,10 @@ defmodule Dbservice.Sessions.Session do field(:platform_id, :string) field(:type, :string) field(:auth_type, :string) - field(:activate_signup, :string) - field(:id_generation, :string) - field(:redirection, :string) - field(:pop_up_form, :string) + field(:activate_signup, :boolean) + field(:id_generation, :boolean) + field(:redirection, :boolean) + field(:pop_up_form, :boolean) field(:number_of_fields_in_pop_form, :string) timestamps() diff --git a/lib/dbservice_web/swagger_schemas/session.ex b/lib/dbservice_web/swagger_schemas/session.ex index 3da2e2cf..4f16ab22 100644 --- a/lib/dbservice_web/swagger_schemas/session.ex +++ b/lib/dbservice_web/swagger_schemas/session.ex @@ -26,10 +26,10 @@ defmodule DbserviceWeb.SwaggerSchema.Session do form_schema_id(:string, "Id for the form schema") type(:string, "Type of session") auth_type(:string, "Authentication methods used for session") - activate_signup(:string, "Is sign up allowed for this session") - id_generation(:string, "Is ID being generated for this session") - redirection(:string, "Is the session redirecting to some other platform") - pop_up_form(:string, "Is the session showing a pop up form") + activate_signup(:boolean, "Is sign up allowed for this session") + id_generation(:boolean, "Is ID being generated for this session") + redirection(:boolean, "Is the session redirecting to some other platform") + pop_up_form(:boolean, "Is the session showing a pop up form") number_of_fields_in_pop_form(:string, "Number of fields in the pop form") end diff --git a/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs b/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs new file mode 100644 index 00000000..eee79e2c --- /dev/null +++ b/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs @@ -0,0 +1,23 @@ +defmodule Dbservice.Repo.Migrations.ModifyDataTypesInSessionTable do + use Ecto.Migration + + def up do + execute(""" + ALTER TABLE session + ALTER COLUMN activate_signup TYPE BOOLEAN USING (activate_signup::boolean), + ALTER COLUMN id_generation TYPE BOOLEAN USING (id_generation::boolean), + ALTER COLUMN redirection TYPE BOOLEAN USING (redirection::boolean), + ALTER COLUMN pop_up_form TYPE BOOLEAN USING (pop_up_form::boolean); + """) + end + + def down do + execute(""" + ALTER TABLE session + ALTER COLUMN activate_signup TYPE VARCHAR, + ALTER COLUMN id_generation TYPE VARCHAR, + ALTER COLUMN redirection TYPE VARCHAR, + ALTER COLUMN pop_up_form TYPE VARCHAR; + """) + end +end diff --git a/priv/static/swagger.json b/priv/static/swagger.json index 52bc5410..03641f41 100644 --- a/priv/static/swagger.json +++ b/priv/static/swagger.json @@ -1,84 +1,66 @@ { "definitions": { - "Teacher": { - "description": "A teacher in the application", - "example": { - "designation": "Vice Principal", - "grade": "12", - "program_manager_id": 3, - "school_id": 2, - "subject": "Maths", - "user_id": 1, - "uuid": "3bc6b53e7bbbc883b9ab" + "BatchPrograms": { + "description": "All batch and program mappings", + "items": { + "$ref": "#/definitions/BatchProgram" }, - "properties": { - "designation": { - "description": "Designation", - "type": "string" - }, - "grade": { - "description": "Grade", - "type": "string" - }, - "program_manager_id": { - "description": "Program manager user ID for the teacher", - "type": "integer" - }, - "school_id": { - "description": "School ID for the teacher", - "type": "integer" - }, - "subject": { - "description": "Core subject", - "type": "string" - }, - "user_id": { - "description": "User ID for the teacher", - "type": "integer" - }, - "uuid": { - "description": "UUID for the teacher", - "type": "string" - } + "title": "BatchPrograms", + "type": "array" + }, + "Students": { + "description": "All students in the application", + "items": { + "$ref": "#/definitions/Student" }, - "title": "Teacher", - "type": "object" + "title": "Students", + "type": "array" }, - "StudentRegistration": { - "description": "A student in the application along with user info", + "Sessions": { + "description": "All the sessions", + "items": { + "$ref": "#/definitions/Session" + }, + "title": "Sessions", + "type": "array" + }, + "UserSessions": { + "description": "All user and session occurence mappings", + "items": { + "$ref": "#/definitions/UserSession" + }, + "title": "UserSessions", + "type": "array" + }, + "User": { + "description": "A user in the application", "example": { "address": "Bandra Complex, Kurla Road", - "category": "general", "city": "Mumbai", + "date_of_birth": "2003-08-22", "district": "Mumbai", "email": "rahul.sharma@example.com", - "father_name": "Narayan Pandey", - "father_phone": "8989898989", - "first_name": "Rahul", + "full_name": "Rahul Sharma", "gender": "Male", - "last_name": "Sharma", - "mother_name": "Lakshmi Pandey", - "mother_phone": "9998887777", "phone": "9998887777", "pincode": "400011", "role": "student", "state": "Maharashtra", - "stream": "PCB", - "student_id": "120180101057" + "whatsapp_phone": "9998887777" }, "properties": { "address": { "description": "Address", "type": "string" }, - "category": { - "description": "Category", - "type": "string" - }, "city": { "description": "City", "type": "string" }, + "date_of_birth": { + "description": "Date of Birth", + "type": "date" + }, "district": { "description": "District", "type": "string" @@ -87,34 +69,14 @@ "description": "Email", "type": "string" }, - "father_name": { - "description": "Father's name", - "type": "string" - }, - "father_phone": { - "description": "Father's phone number", - "type": "string" - }, - "first_name": { - "description": "First name", + "full_name": { + "description": "Full name", "type": "string" }, "gender": { "description": "Gender", "type": "string" }, - "last_name": { - "description": "Last name", - "type": "string" - }, - "mother_name": { - "description": "Mother's name", - "type": "string" - }, - "mother_phone": { - "description": "Mother's phone number", - "type": "string" - }, "phone": { "description": "Phone number", "type": "string" @@ -131,33 +93,54 @@ "description": "State", "type": "string" }, - "stream": { - "description": "Stream", - "type": "string" - }, - "student_id": { - "description": "Id for the student", + "whatsapp_phone": { + "description": "Whatsapp phone", "type": "string" } }, - "title": "Student Registration", + "title": "User", "type": "object" }, - "Schools": { - "description": "All schools in the application", - "items": { - "$ref": "#/definitions/School" + "UserSession": { + "description": "A mapping between user and sesssion-occurence", + "example": { + "data": { + "substitute-teacher-name": "Ms. Poonam" + }, + "end_time": "2022-02-02T11:30:00Z", + "is_user_valid": true, + "session_occurrence_id": 2, + "start_time": "2022-02-02T11:00:00Z", + "user_id": "12213221211" }, - "title": "Schools", - "type": "array" - }, - "Users": { - "description": "All users in the application", - "items": { - "$ref": "#/definitions/User" + "properties": { + "data": { + "description": "Additional data for user session", + "type": "map" + }, + "end_time": { + "description": "User session end time", + "type": "timestamp" + }, + "is_user_valid": { + "description": "Signifies whether the user exist or not", + "type": "boolean" + }, + "session_occurrence_id": { + "description": "The id of the session occurrence", + "type": "integer" + }, + "start_time": { + "description": "User session start time", + "type": "timestamp" + }, + "user_id": { + "description": "The id of the user", + "type": "string" + } }, - "title": "Users", - "type": "array" + "title": "UserSession", + "type": "object" }, "GroupIds": { "example": { @@ -174,271 +157,209 @@ }, "type": "object" }, - "BatchProgram": { - "description": "A mapping between batch and program", + "SessionOccurrence": { + "description": "A session occurrence for a session", "example": { - "batch_id": 1, - "program_id": 1 + "end_time": "2022-02-02T11:30:00Z", + "session_fk": 1, + "session_id": "DelhiStudents_B01_44725_unv-nkyh-hnb", + "start_time": "2022-02-02T11:00:00Z" }, "properties": { - "batch_id": { - "description": "The id of the batch", - "type": "integer" + "end_time": { + "description": "Session occurrence finish time", + "type": "timestamp" }, - "program_id": { - "description": "The id of the program", + "session_fk": { + "description": "The primary key for session's table", "type": "integer" + }, + "session_id": { + "description": "ID of the session", + "type": "string" + }, + "start_time": { + "description": "Session occurrence start time", + "type": "timestamp" } }, - "title": "BatchProgram", + "title": "SessionOccurrence", "type": "object" }, - "UserIds": { - "example": { - "user_ids": [ - 1, - 2 - ] + "Batches": { + "description": "All the batches", + "items": { + "$ref": "#/definitions/Batch" }, - "properties": { - "user_ids": { - "description": "List of user ids", - "type": "array" - } + "title": "Batches", + "type": "array" + }, + "Groups": { + "description": "All the groups", + "items": { + "$ref": "#/definitions/Group" }, - "type": "object" + "title": "Groups", + "type": "array" }, - "FormSchemas": { - "description": "All the form schemas", + "SessionOccurrences": { + "description": "All the session occurrences ", "items": { - "$ref": "#/definitions/FormSchema" + "$ref": "#/definitions/SessionOccurrence" }, - "title": "FormSchemas", + "title": "SessionOccurrences", "type": "array" }, - "Group": { - "description": "A group in the application", - "example": { - "input_schema": {}, - "locale": "hi", - "locale_data": { - "en": { - "title": "Register for session" - }, - "hi": { - "title": "सत्र के लिए पंजीकरण करें" - } - }, - "name": "DelhiStudents" + "Users": { + "description": "All users in the application", + "items": { + "$ref": "#/definitions/User" }, - "properties": { - "input_schema": { - "description": "Input schema", - "type": "map" - }, - "locale": { - "description": "The configured locale for the group", - "type": "string" - }, - "locale_data": { - "description": "Meta data about locale settings for the group", - "type": "map" - }, - "name": { - "description": "Name of a group", - "type": "string" - } - }, - "title": "Group", - "type": "object" - }, - "Groups": { - "description": "All the groups", - "items": { - "$ref": "#/definitions/Group" - }, - "title": "Groups", + "title": "Users", "type": "array" }, - "School": { - "description": "A school in the application", + "Session": { + "description": "A session in the application", "example": { - "block_code": "DOEAIDED", - "board": "CBSE", - "board_medium": "en", - "category": "Government", - "code": "872931", - "district": "NORTH WEST DELHI", - "district_code": "0701", - "name": "Kendriya Vidyalaya - Rajori Garden", - "region": "Urban", - "state": "Delhi", - "state_code": "DL", - "type": "Open", - "udise_code": "05040120901" + "created_by_id": 1, + "end_time": "2022-02-02T11:30:00Z", + "form_schema_id": 1, + "is_active": true, + "meta_data": { + "substitute-teacher-name": "Ms. Poonam" + }, + "name": "Kendriya Vidyalaya - Weekly Maths class 7", + "owner_id": 2, + "platform": "meet", + "platform_link": "https://meet.google.com/asl-skas-qwe", + "portal_link": "https://links.af.org/kv-wmc7", + "repeat_schedule": { + "repeat-till-date": "2022-12-31 11:59:59", + "repeat-type": "weekly" + }, + "session_id": "c714-e1d4-5a42-0f9f-36b3", + "start_time": "2022-02-02T11:00:00Z" }, "properties": { - "block_code": { - "description": "Block Code", + "activate_signup": { + "description": "Is sign up allowed for this session", "type": "string" }, - "block_name": { - "description": "Block Name", + "auth_type": { + "description": "Authentication methods used for session", "type": "string" }, - "board": { - "description": "Board", - "type": "string" + "created_by_id": { + "description": "User ID for the session creator", + "type": "integer" }, - "board_medium": { - "description": "Medium", - "type": "string" + "end_time": { + "description": "Session finish time", + "type": "timestamp" }, - "category": { - "description": "Category", + "form_schema_id": { + "description": "Id for the form schema", "type": "string" }, - "code": { - "description": "Code", + "id_generation": { + "description": "Is ID being generated for this session", "type": "string" }, - "district": { - "description": "District", - "type": "string" + "is_active": { + "description": "Tells whether session is active or not", + "type": "boolean" }, - "district_code": { - "description": "District Code", - "type": "string" + "meta_data": { + "description": "Additional meta data for the session", + "type": "map" }, "name": { - "description": "Name", + "description": "First name", "type": "string" }, - "region": { - "description": "Region", + "number_of_fields_in_pop_form": { + "description": "Number of fields in the pop form", "type": "string" }, - "state": { - "description": "State", + "owner_id": { + "description": "User ID for the session owner", + "type": "integer" + }, + "platform": { + "description": "Platform where session being hosted", "type": "string" }, - "state_code": { - "description": "State Code", + "platform_link": { + "description": "Link for the platform", "type": "string" }, - "type": { - "description": "Type", + "pop_up_form": { + "description": "Is the session showing a pop up form", "type": "string" }, - "udise_code": { - "description": "Udise Code", + "portal_link": { + "description": "Link generated by the portal", + "type": "text" + }, + "redirection": { + "description": "Is the session redirecting to some other platform", "type": "string" - } - }, - "title": "School", - "type": "object" - }, - "Sessions": { - "description": "All the sessions", - "items": { - "$ref": "#/definitions/Session" - }, - "title": "Sessions", - "type": "array" - }, - "Batches": { - "description": "All the batches", - "items": { - "$ref": "#/definitions/Batch" - }, - "title": "Batches", - "type": "array" - }, - "Teachers": { - "description": "All teachers in the application", - "items": { - "$ref": "#/definitions/Teacher" - }, - "title": "Teachers", - "type": "array" - }, - "Programs": { - "description": "All the programs", - "items": { - "$ref": "#/definitions/Program" - }, - "title": "Programs", - "type": "array" - }, - "FormSchema": { - "description": "A form schema in the application", - "example": { - "attributes": { - "label": "First Name" }, - "name": "Registration" - }, - "properties": { - "attributes": { - "description": "Attribute data for form schema", - "type": "map" + "repeat_schedule": { + "description": "Repeat type and repeat till date for session", + "type": "json" }, - "name": { - "description": "Name of a form schema", + "session_id": { + "description": "Id for the session", "type": "string" - } - }, - "title": "FormSchema", - "type": "object" - }, - "Batch": { - "description": "A batch in application", - "example": { - "contact_hours_per_week": 48, - "name": "Delhi-12-NEET" - }, - "properties": { - "contact_hours_per_week": { - "description": "Contact hours per week of a batch", - "type": "integer" }, - "name": { - "description": "The name of a batch", + "start_time": { + "description": "Session start time", + "type": "timestamp" + }, + "type": { + "description": "Type of session", "type": "string" } }, - "title": "Batch", + "title": "Session", "type": "object" }, - "User": { - "description": "A user in the application", + "StudentRegistration": { + "description": "A student in the application along with user info", "example": { "address": "Bandra Complex, Kurla Road", + "category": "general", "city": "Mumbai", - "date_of_birth": "2003-08-22", "district": "Mumbai", "email": "rahul.sharma@example.com", - "full_name": "Rahul Sharma", + "father_name": "Narayan Pandey", + "father_phone": "8989898989", + "first_name": "Rahul", "gender": "Male", + "last_name": "Sharma", + "mother_name": "Lakshmi Pandey", + "mother_phone": "9998887777", "phone": "9998887777", "pincode": "400011", "role": "student", "state": "Maharashtra", - "whatsapp_phone": "9998887777" + "stream": "PCB", + "student_id": "120180101057" }, "properties": { "address": { "description": "Address", "type": "string" }, + "category": { + "description": "Category", + "type": "string" + }, "city": { "description": "City", "type": "string" }, - "date_of_birth": { - "description": "Date of Birth", - "type": "date" - }, "district": { "description": "District", "type": "string" @@ -447,99 +368,182 @@ "description": "Email", "type": "string" }, - "full_name": { - "description": "Full name", + "father_name": { + "description": "Father's name", + "type": "string" + }, + "father_phone": { + "description": "Father's phone number", + "type": "string" + }, + "first_name": { + "description": "First name", "type": "string" }, "gender": { "description": "Gender", "type": "string" }, + "last_name": { + "description": "Last name", + "type": "string" + }, + "mother_name": { + "description": "Mother's name", + "type": "string" + }, + "mother_phone": { + "description": "Mother's phone number", + "type": "string" + }, "phone": { "description": "Phone number", "type": "string" }, - "pincode": { - "description": "Pin code", - "type": "string" + "pincode": { + "description": "Pin code", + "type": "string" + }, + "role": { + "description": "User role", + "type": "string" + }, + "state": { + "description": "State", + "type": "string" + }, + "stream": { + "description": "Stream", + "type": "string" + }, + "student_id": { + "description": "Id for the student", + "type": "string" + } + }, + "title": "Student Registration", + "type": "object" + }, + "Group": { + "description": "A group in the application", + "example": { + "input_schema": {}, + "locale": "hi", + "locale_data": { + "en": { + "title": "Register for session" + }, + "hi": { + "title": "सत्र के लिए पंजीकरण करें" + } + }, + "name": "DelhiStudents" + }, + "properties": { + "input_schema": { + "description": "Input schema", + "type": "map" }, - "role": { - "description": "User role", + "locale": { + "description": "The configured locale for the group", "type": "string" }, - "state": { - "description": "State", - "type": "string" + "locale_data": { + "description": "Meta data about locale settings for the group", + "type": "map" }, - "whatsapp_phone": { - "description": "Whatsapp phone", + "name": { + "description": "Name of a group", "type": "string" } }, - "title": "User", + "title": "Group", "type": "object" }, - "StudentWithUser": { - "description": "A student in the application along with user info", + "TeacherWithUser": { + "description": "A teacher in the application along with user info", "example": { "category": "general", - "father_name": "Narayan Pandey", - "father_phone": "8989898989", - "mother_name": "Lakshmi Pandey", - "mother_phone": "9998887777", + "designation": "Principal", + "grade": "High School", + "school_id": 2, "stream": "PCB", - "student_id": "120180101057", "user": { "address": "Bandra Complex, Kurla Road", "city": "Mumbai", "district": "Mumbai", - "email": "rahul.sharma@example.com", - "first_name": "Rahul", + "email": "aman.bahuguna@example.com", + "full_name": "Aman Bahuguna", "gender": "Male", - "last_name": "Sharma", - "phone": "9998887777", + "phone": "8484515848", "pincode": "400011", - "role": "student", + "role": "principal", "state": "Maharashtra" - } + }, + "uuid": "AF419" }, "properties": { - "category": { - "description": "Category", + "designation": { + "description": "Designation for the teacher", "type": "string" }, - "father_name": { - "description": "Father's name", + "grade": { + "description": "Grade level in which a teacher instructs", "type": "string" }, - "father_phone": { - "description": "Father's phone number", + "subject": { + "description": "Subject taught by the teacher", "type": "string" }, - "mother_name": { - "description": "Mother's name", - "type": "string" + "user": { + "description": "User details associated with the teacher", + "type": "map" }, - "mother_phone": { - "description": "Mother's phone number", + "uuid": { + "description": "UUID of the teacher", "type": "string" + } + }, + "title": "Teacher with User", + "type": "object" + }, + "FormSchema": { + "description": "A form schema in the application", + "example": { + "attributes": { + "label": "First Name" }, - "stream": { - "description": "Stream", - "type": "string" + "name": "Registration" + }, + "properties": { + "attributes": { + "description": "Attribute data for form schema", + "type": "map" }, - "student_id": { - "description": "Id for the student", + "name": { + "description": "Name of a form schema", "type": "string" - }, - "user": { - "description": "User details associated with the student", - "type": "map" } }, - "title": "Student with User", + "title": "FormSchema", "type": "object" }, + "GroupTypes": { + "description": "All the GroupTypes", + "items": { + "$ref": "#/definitions/GroupType" + }, + "title": "GroupTypes", + "type": "array" + }, + "FormSchemas": { + "description": "All the form schemas", + "items": { + "$ref": "#/definitions/FormSchema" + }, + "title": "FormSchemas", + "type": "array" + }, "GroupType": { "description": "A Group type in application", "example": { @@ -573,56 +577,12 @@ "title": "GroupType", "type": "object" }, - "EnrollmentRecord": { - "description": "An enrollment record for the student", - "example": { - "academic_year": "2022", - "board_medium": "English", - "date_of_enrollment": "02/03/2020", - "grade": "7", - "is_current": true, - "school_id": 1, - "student_id": 1 - }, - "properties": { - "academic_year": { - "description": "Academic Year", - "type": "string" - }, - "board_medium": { - "description": "Medium of the board", - "type": "string" - }, - "date_of_enrollment": { - "description": "Date of Enrollment", - "type": "date" - }, - "grade": { - "description": "Grade", - "type": "string" - }, - "is_current": { - "description": "Is current enrollment record for student", - "type": "boolean" - }, - "school_id": { - "description": "School ID that the program enrollment belongs to", - "type": "integer" - }, - "student_id": { - "description": "Student ID that the program enrollment belongs to", - "type": "integer" - } - }, - "title": "EnrollmentRecord", - "type": "object" - }, - "SessionOccurrences": { - "description": "All the session occurrences ", + "EnrollmentRecords": { + "description": "All enrollment records", "items": { - "$ref": "#/definitions/SessionOccurrence" + "$ref": "#/definitions/EnrollmentRecord" }, - "title": "SessionOccurrences", + "title": "EnrollmentRecords", "type": "array" }, "GroupUsers": { @@ -659,13 +619,64 @@ "title": "Group User", "type": "object" }, - "GroupTypes": { - "description": "All the GroupTypes", - "items": { - "$ref": "#/definitions/GroupType" + "SessionIds": { + "example": { + "session_ids": [ + 1, + 2 + ] }, - "title": "GroupTypes", - "type": "array" + "properties": { + "session_ids": { + "description": "List of session ids", + "type": "array" + } + }, + "type": "object" + }, + "Teacher": { + "description": "A teacher in the application", + "example": { + "designation": "Vice Principal", + "grade": "12", + "program_manager_id": 3, + "school_id": 2, + "subject": "Maths", + "user_id": 1, + "uuid": "3bc6b53e7bbbc883b9ab" + }, + "properties": { + "designation": { + "description": "Designation", + "type": "string" + }, + "grade": { + "description": "Grade", + "type": "string" + }, + "program_manager_id": { + "description": "Program manager user ID for the teacher", + "type": "integer" + }, + "school_id": { + "description": "School ID for the teacher", + "type": "integer" + }, + "subject": { + "description": "Core subject", + "type": "string" + }, + "user_id": { + "description": "User ID for the teacher", + "type": "integer" + }, + "uuid": { + "description": "UUID for the teacher", + "type": "string" + } + }, + "title": "Teacher", + "type": "object" }, "GroupSessions": { "description": "Relation between group and session", @@ -686,45 +697,23 @@ "title": "Group Session", "type": "object" }, - "UserSession": { - "description": "A mapping between user and sesssion-occurence", - "example": { - "data": { - "substitute-teacher-name": "Ms. Poonam" - }, - "end_time": "2022-02-02T11:30:00Z", - "is_user_valid": true, - "session_occurrence_id": 2, - "start_time": "2022-02-02T11:00:00Z", - "user_id": "12213221211" + "Batch": { + "description": "A batch in application", + "example": { + "contact_hours_per_week": 48, + "name": "Delhi-12-NEET" }, "properties": { - "data": { - "description": "Additional data for user session", - "type": "map" - }, - "end_time": { - "description": "User session end time", - "type": "timestamp" - }, - "is_user_valid": { - "description": "Signifies whether the user exist or not", - "type": "boolean" - }, - "session_occurrence_id": { - "description": "The id of the session occurrence", + "contact_hours_per_week": { + "description": "Contact hours per week of a batch", "type": "integer" }, - "start_time": { - "description": "User session start time", - "type": "timestamp" - }, - "user_id": { - "description": "The id of the user", + "name": { + "description": "The name of a batch", "type": "string" } }, - "title": "UserSession", + "title": "Batch", "type": "object" }, "Program": { @@ -787,46 +776,25 @@ "title": "Program", "type": "object" }, - "BatchPrograms": { - "description": "All batch and program mappings", - "items": { - "$ref": "#/definitions/BatchProgram" - }, - "title": "BatchPrograms", - "type": "array" - }, - "SessionOccurrenceWithUser": { - "description": "A single session occurrence with user details", + "BatchProgram": { + "description": "A mapping between batch and program", "example": { - "end_time": "2022-02-02T11:30:00Z", - "session_id": 1, - "start_time": "2022-02-02T11:00:00Z" + "batch_id": 1, + "program_id": 1 }, "properties": { - "end_time": { - "description": "Session occurrence finish time", - "type": "timestamp" - }, - "session_id": { - "description": "Session ID", + "batch_id": { + "description": "The id of the batch", "type": "integer" }, - "start_time": { - "description": "Session occurrence start time", - "type": "timestamp" + "program_id": { + "description": "The id of the program", + "type": "integer" } }, - "title": "SessionOccurrenceWithUser", + "title": "BatchProgram", "type": "object" }, - "Students": { - "description": "All students in the application", - "items": { - "$ref": "#/definitions/Student" - }, - "title": "Students", - "type": "array" - }, "Student": { "description": "A student in the application", "example": { @@ -836,7 +804,7 @@ "father_name": "Narayan Pandey", "father_phone": "8989898989", "father_profession": "Unemployed", - "has_internet_access": true, + "has_internet_access": "Yes", "mother_education_level": "UG", "mother_name": "Lakshmi Pandey", "mother_phone": "9998887777", @@ -872,7 +840,7 @@ }, "has_internet_access": { "description": "If the family has internet access", - "type": "boolean" + "type": "string" }, "mother_education_level": { "description": "Mother's education level", @@ -910,6 +878,10 @@ "description": "Id for the student", "type": "string" }, + "time_of_device_availability": { + "description": "Time of device availability for a student", + "type": "string" + }, "user_id": { "description": "User ID for the student", "type": "integer" @@ -918,149 +890,169 @@ "title": "Student", "type": "object" }, - "UserSessions": { - "description": "All user and session occurence mappings", - "items": { - "$ref": "#/definitions/UserSession" - }, - "title": "UserSessions", - "type": "array" - }, - "Session": { - "description": "A session in the application", + "StudentWithUser": { + "description": "A student in the application along with user info", "example": { - "created_by_id": 1, - "end_time": "2022-02-02T11:30:00Z", - "form_schema_id": 1, - "is_active": true, - "meta_data": { - "substitute-teacher-name": "Ms. Poonam" - }, - "name": "Kendriya Vidyalaya - Weekly Maths class 7", - "owner_id": 2, - "platform": "meet", - "platform_link": "https://meet.google.com/asl-skas-qwe", - "portal_link": "https://links.af.org/kv-wmc7", - "repeat_schedule": { - "repeat-till-date": "2022-12-31 11:59:59", - "repeat-type": "weekly" - }, - "session_id": "c714-e1d4-5a42-0f9f-36b3", - "start_time": "2022-02-02T11:00:00Z" + "category": "general", + "father_name": "Narayan Pandey", + "father_phone": "8989898989", + "mother_name": "Lakshmi Pandey", + "mother_phone": "9998887777", + "stream": "PCB", + "student_id": "120180101057", + "user": { + "address": "Bandra Complex, Kurla Road", + "city": "Mumbai", + "district": "Mumbai", + "email": "rahul.sharma@example.com", + "first_name": "Rahul", + "gender": "Male", + "last_name": "Sharma", + "phone": "9998887777", + "pincode": "400011", + "role": "student", + "state": "Maharashtra" + } }, "properties": { - "activate_signup": { - "description": "Is sign up allowed for this session", - "type": "boolean" + "category": { + "description": "Category", + "type": "string" }, - "auth_type": { - "description": "Authentication methods used for session", + "father_name": { + "description": "Father's name", "type": "string" }, - "created_by_id": { - "description": "User ID for the session creator", - "type": "integer" + "father_phone": { + "description": "Father's phone number", + "type": "string" }, - "end_time": { - "description": "Session finish time", - "type": "timestamp" + "mother_name": { + "description": "Mother's name", + "type": "string" }, - "form_schema_id": { - "description": "Id for the form schema", + "mother_phone": { + "description": "Mother's phone number", "type": "string" }, - "id_generation": { - "description": "Is ID being generated for this session", - "type": "boolean" + "stream": { + "description": "Stream", + "type": "string" }, - "is_active": { - "description": "Tells whether session is active or not", - "type": "boolean" + "student_id": { + "description": "Id for the student", + "type": "string" }, - "meta_data": { - "description": "Additional meta data for the session", + "user": { + "description": "User details associated with the student", "type": "map" + } + }, + "title": "Student with User", + "type": "object" + }, + "Teachers": { + "description": "All teachers in the application", + "items": { + "$ref": "#/definitions/Teacher" + }, + "title": "Teachers", + "type": "array" + }, + "Programs": { + "description": "All the programs", + "items": { + "$ref": "#/definitions/Program" + }, + "title": "Programs", + "type": "array" + }, + "Schools": { + "description": "All schools in the application", + "items": { + "$ref": "#/definitions/School" + }, + "title": "Schools", + "type": "array" + }, + "School": { + "description": "A school in the application", + "example": { + "block_code": "DOEAIDED", + "board": "CBSE", + "board_medium": "en", + "category": "Government", + "code": "872931", + "district": "NORTH WEST DELHI", + "district_code": "0701", + "name": "Kendriya Vidyalaya - Rajori Garden", + "region": "Urban", + "state": "Delhi", + "state_code": "DL", + "type": "Open", + "udise_code": "05040120901" + }, + "properties": { + "block_code": { + "description": "Block Code", + "type": "string" }, - "name": { - "description": "First name", + "block_name": { + "description": "Block Name", "type": "string" }, - "owner_id": { - "description": "User ID for the session owner", - "type": "integer" + "board": { + "description": "Board", + "type": "string" }, - "platform": { - "description": "Platform where session being hosted", + "board_medium": { + "description": "Medium", "type": "string" }, - "platform_link": { - "description": "Link for the platform", + "category": { + "description": "Category", "type": "string" }, - "pop_up_form": { - "description": "Is the session showing a pop up form", - "type": "boolean" + "code": { + "description": "Code", + "type": "string" }, - "portal_link": { - "description": "Link generated by the portal", - "type": "text" + "district": { + "description": "District", + "type": "string" }, - "redirection": { - "description": "Is the session redirecting to some other platform", - "type": "boolean" + "district_code": { + "description": "District Code", + "type": "string" + }, + "name": { + "description": "Name", + "type": "string" }, - "repeat_schedule": { - "description": "Repeat type and repeat till date for session", - "type": "json" + "region": { + "description": "Region", + "type": "string" }, - "session_id": { - "description": "Id for the session", + "state": { + "description": "State", "type": "string" }, - "start_time": { - "description": "Session start time", - "type": "timestamp" + "state_code": { + "description": "State Code", + "type": "string" }, "type": { - "description": "Type of session", + "description": "Type", "type": "string" - } - }, - "title": "Session", - "type": "object" - }, - "SessionOccurrence": { - "description": "A session occurrence for a session", - "example": { - "end_time": "2022-02-02T11:30:00Z", - "session_id": 1, - "start_time": "2022-02-02T11:00:00Z" - }, - "properties": { - "end_time": { - "description": "Session occurrence finish time", - "type": "timestamp" - }, - "session_id": { - "description": "Session ID", - "type": "integer" }, - "start_time": { - "description": "Session occurrence start time", - "type": "timestamp" + "udise_code": { + "description": "Udise Code", + "type": "string" } }, - "title": "SessionOccurrence", + "title": "School", "type": "object" }, - "EnrollmentRecords": { - "description": "All enrollment records", - "items": { - "$ref": "#/definitions/EnrollmentRecord" - }, - "title": "EnrollmentRecords", - "type": "array" - }, "TeacherRegistration": { "description": "A teacher in the application along with user info", "example": { @@ -1146,67 +1138,88 @@ "title": "Teacher Registration", "type": "object" }, - "TeacherWithUser": { - "description": "A teacher in the application along with user info", + "SessionOccurrenceWithUser": { + "description": "A single session occurrence with user details", "example": { - "category": "general", - "designation": "Principal", - "grade": "High School", - "school_id": 2, - "stream": "PCB", - "user": { - "address": "Bandra Complex, Kurla Road", - "city": "Mumbai", - "district": "Mumbai", - "email": "aman.bahuguna@example.com", - "full_name": "Aman Bahuguna", - "gender": "Male", - "phone": "8484515848", - "pincode": "400011", - "role": "principal", - "state": "Maharashtra" - }, - "uuid": "AF419" + "end_time": "2022-02-02T11:30:00Z", + "session_id": 1, + "start_time": "2022-02-02T11:00:00Z" }, "properties": { - "designation": { - "description": "Designation for the teacher", - "type": "string" - }, - "grade": { - "description": "Grade level in which a teacher instructs", - "type": "string" - }, - "subject": { - "description": "Subject taught by the teacher", - "type": "string" + "end_time": { + "description": "Session occurrence finish time", + "type": "timestamp" }, - "user": { - "description": "User details associated with the teacher", - "type": "map" + "session_id": { + "description": "Session ID", + "type": "integer" }, - "uuid": { - "description": "UUID of the teacher", - "type": "string" + "start_time": { + "description": "Session occurrence start time", + "type": "timestamp" } }, - "title": "Teacher with User", + "title": "SessionOccurrenceWithUser", "type": "object" }, - "SessionIds": { + "UserIds": { "example": { - "session_ids": [ + "user_ids": [ 1, 2 ] }, "properties": { - "session_ids": { - "description": "List of session ids", + "user_ids": { + "description": "List of user ids", "type": "array" } }, "type": "object" + }, + "EnrollmentRecord": { + "description": "An enrollment record for the student", + "example": { + "academic_year": "2022", + "board_medium": "English", + "date_of_enrollment": "02/03/2020", + "grade": "7", + "is_current": true, + "school_id": 1, + "student_id": 1 + }, + "properties": { + "academic_year": { + "description": "Academic Year", + "type": "string" + }, + "board_medium": { + "description": "Medium of the board", + "type": "string" + }, + "date_of_enrollment": { + "description": "Date of Enrollment", + "type": "date" + }, + "grade": { + "description": "Grade", + "type": "string" + }, + "is_current": { + "description": "Is current enrollment record for student", + "type": "boolean" + }, + "school_id": { + "description": "School ID that the program enrollment belongs to", + "type": "integer" + }, + "student_id": { + "description": "Student ID that the program enrollment belongs to", + "type": "integer" + } + }, + "title": "EnrollmentRecord", + "type": "object" } }, "host": "localhost:4000", @@ -1215,47 +1228,6 @@ "version": "1.0" }, "paths": { - "/api/session?session_id=c714-e1d4-5a42-0f9f-36b3": { - "get": { - "description": "", - "operationId": "DbserviceWeb.SessionController.index", - "parameters": [ - { - "description": "The id the session", - "in": "query", - "name": "session_id", - "required": false, - "type": "string" - }, - { - "description": "The name the session", - "in": "query", - "name": "name", - "required": false, - "type": "string" - }, - { - "description": "The platform id the session", - "in": "query", - "name": "platform_id", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/Sessions" - } - } - }, - "summary": "", - "tags": [ - "Session" - ] - } - }, "/api/program/{programId}": { "delete": { "description": "", @@ -2358,6 +2330,45 @@ } }, "/api/session": { + "get": { + "description": "", + "operationId": "DbserviceWeb.SessionController.index", + "parameters": [ + { + "description": "The id the session", + "in": "query", + "name": "session_id", + "required": false, + "type": "string" + }, + { + "description": "The name the session", + "in": "query", + "name": "name", + "required": false, + "type": "string" + }, + { + "description": "The platform id the session", + "in": "query", + "name": "platform_id", + "required": false, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Sessions" + } + } + }, + "summary": "", + "tags": [ + "Session" + ] + }, "post": { "description": "", "operationId": "DbserviceWeb.SessionController.create", @@ -3352,7 +3363,29 @@ "get": { "description": "", "operationId": "DbserviceWeb.EnrollmentRecordController.index", - "parameters": [], + "parameters": [ + { + "description": "The academic year of the student's enrollment", + "in": "query", + "name": "academic_year", + "required": false, + "type": "string" + }, + { + "description": "The grade of the student's enrollment", + "in": "query", + "name": "grade", + "required": false, + "type": "string" + }, + { + "description": "The board medium of the student's enrollment", + "in": "query", + "name": "board_medium", + "required": false, + "type": "string" + } + ], "responses": { "200": { "description": "OK", From d69890823f7501f29143a072f08b4092c85db896 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Wed, 6 Sep 2023 13:05:06 +0530 Subject: [PATCH 04/30] changed data type of number_of_fields_in_pop_form --- lib/dbservice/sessions/session.ex | 2 +- lib/dbservice_web/swagger_schemas/session.ex | 2 +- ...05164925_modify_data_types_in_session_table.exs | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/dbservice/sessions/session.ex b/lib/dbservice/sessions/session.ex index 0b41437e..3f83c3c1 100644 --- a/lib/dbservice/sessions/session.ex +++ b/lib/dbservice/sessions/session.ex @@ -29,7 +29,7 @@ defmodule Dbservice.Sessions.Session do field(:id_generation, :boolean) field(:redirection, :boolean) field(:pop_up_form, :boolean) - field(:number_of_fields_in_pop_form, :string) + field(:number_of_fields_in_pop_form, :integer) timestamps() diff --git a/lib/dbservice_web/swagger_schemas/session.ex b/lib/dbservice_web/swagger_schemas/session.ex index 4f16ab22..668749ca 100644 --- a/lib/dbservice_web/swagger_schemas/session.ex +++ b/lib/dbservice_web/swagger_schemas/session.ex @@ -30,7 +30,7 @@ defmodule DbserviceWeb.SwaggerSchema.Session do id_generation(:boolean, "Is ID being generated for this session") redirection(:boolean, "Is the session redirecting to some other platform") pop_up_form(:boolean, "Is the session showing a pop up form") - number_of_fields_in_pop_form(:string, "Number of fields in the pop form") + number_of_fields_in_pop_form(:integer, "Number of fields in the pop form") end example(%{ diff --git a/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs b/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs index eee79e2c..1c66b546 100644 --- a/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs +++ b/priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs @@ -7,17 +7,19 @@ defmodule Dbservice.Repo.Migrations.ModifyDataTypesInSessionTable do ALTER COLUMN activate_signup TYPE BOOLEAN USING (activate_signup::boolean), ALTER COLUMN id_generation TYPE BOOLEAN USING (id_generation::boolean), ALTER COLUMN redirection TYPE BOOLEAN USING (redirection::boolean), - ALTER COLUMN pop_up_form TYPE BOOLEAN USING (pop_up_form::boolean); + ALTER COLUMN pop_up_form TYPE BOOLEAN USING (pop_up_form::boolean), + ALTER COLUMN number_of_fields_in_pop_form TYPE INTEGER USING (number_of_fields_in_pop_form::integer); """) end def down do execute(""" - ALTER TABLE session - ALTER COLUMN activate_signup TYPE VARCHAR, - ALTER COLUMN id_generation TYPE VARCHAR, - ALTER COLUMN redirection TYPE VARCHAR, - ALTER COLUMN pop_up_form TYPE VARCHAR; + ALTER TABLE session + ALTER COLUMN activate_signup TYPE VARCHAR, + ALTER COLUMN id_generation TYPE VARCHAR, + ALTER COLUMN redirection TYPE VARCHAR, + ALTER COLUMN pop_up_form TYPE VARCHAR, + ALTER COLUMN number_of_fields_in_pop_form TYPE INTEGER; """) end end From 77fb9bea8188cde6f1b38e686ed54c55cfb455be Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 17:52:34 +0530 Subject: [PATCH 05/30] added authentication middleware --- lib/dbservice_web/endpoint.ex | 1 + .../plugs/authentication_middleware_plug.ex | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 lib/dbservice_web/plugs/authentication_middleware_plug.ex diff --git a/lib/dbservice_web/endpoint.ex b/lib/dbservice_web/endpoint.ex index 2c676f5f..906312f3 100644 --- a/lib/dbservice_web/endpoint.ex +++ b/lib/dbservice_web/endpoint.ex @@ -45,6 +45,7 @@ defmodule DbserviceWeb.Endpoint do plug Plug.Head plug Plug.Session, @session_options plug DbserviceWeb.DomainWhitelistPlug + plug DbserviceWeb.AuthenticationMiddleware plug DbserviceWeb.Router end diff --git a/lib/dbservice_web/plugs/authentication_middleware_plug.ex b/lib/dbservice_web/plugs/authentication_middleware_plug.ex new file mode 100644 index 00000000..29a16f91 --- /dev/null +++ b/lib/dbservice_web/plugs/authentication_middleware_plug.ex @@ -0,0 +1,20 @@ +defmodule DbserviceWeb.AuthenticationMiddleware do + import Plug.Conn + import Dotenvy + + def init(_opts), do: %{} + + def call(conn, _opts) do + source(["config/.env", "config/.env"]) + + api_key = get_req_header(conn, "authorization") + + if api_key == ["Bearer " <> env!("BEARER_TOKEN", :string!)] do + conn + else + conn + |> send_resp(401, "Not Authorized") + |> halt() + end + end +end From f5f4f6b8992031d0f3f70dc4b5ea54d5b9bb8fe0 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 17:57:27 +0530 Subject: [PATCH 06/30] added moduledoc --- .../plugs/authentication_middleware_plug.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/dbservice_web/plugs/authentication_middleware_plug.ex b/lib/dbservice_web/plugs/authentication_middleware_plug.ex index 29a16f91..01b2dace 100644 --- a/lib/dbservice_web/plugs/authentication_middleware_plug.ex +++ b/lib/dbservice_web/plugs/authentication_middleware_plug.ex @@ -1,4 +1,13 @@ defmodule DbserviceWeb.AuthenticationMiddleware do + @moduledoc """ + This module provides a Plug middleware for handling API key-based authentication. + + The middleware checks the 'Authorization' header of incoming HTTP requests to ensure that + it matches a predefined API key stored in the 'BEARER_TOKEN' environment variable. + + If the API key is valid, the request is allowed to proceed; otherwise, a '401 Unauthorized' + response is sent, and further processing is halted. + """ import Plug.Conn import Dotenvy From 2cde2bf8428dc2a522a4b39d78233445855d88cb Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 20:48:57 +0530 Subject: [PATCH 07/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index d56ee0bf..fd307cfe 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -10,23 +10,43 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 Deploy: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Deploy in EC2 + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up environment + run: | + branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + echo "$PRIVATE_KEY" > private_key && chmod 600 private_key env: PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Update environment variables in .env + run: | + cd config + sed -i "s/DATABASE_URL=.*/DATABASE_URL=${{ secrets.DATABASE_URL }}/" .env + sed -i "s/SECRET_KEY_BASE=.*/SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}/" .env + sed -i "s/PHX_HOST=.*/PHX_HOST=${{ secrets.PHX_HOST }}/" .env + sed -i "s/WHITELISTED_DOMAINS=.*/WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}/" .env + sed -i "s/POOL_SIZE=.*/POOL_SIZE=${{ secrets.POOL_SIZE }}/" .env + sed -i "s/PORT=.*/PORT=${{ secrets.PORT }}/" .env + sed -i "s/STAGING_BEARER_TOKEN=.*/STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}/" .env + cd .. + working-directory: ${{ github.workspace }} + + - name: Deploy in EC2 + env: HOSTNAME: ${{ secrets.HOSTNAME }} USER_NAME: ${{ secrets.USER_NAME }} run: | - branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html sudo ./kill_process_on_port_4000.sh From b3ae6b91b0bea5d44b7f0fee795762623a8e7115 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 20:53:46 +0530 Subject: [PATCH 08/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index fd307cfe..7a835338 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -31,13 +31,13 @@ jobs: - name: Update environment variables in .env run: | cd config - sed -i "s/DATABASE_URL=.*/DATABASE_URL=${{ secrets.DATABASE_URL }}/" .env - sed -i "s/SECRET_KEY_BASE=.*/SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}/" .env - sed -i "s/PHX_HOST=.*/PHX_HOST=${{ secrets.PHX_HOST }}/" .env - sed -i "s/WHITELISTED_DOMAINS=.*/WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}/" .env - sed -i "s/POOL_SIZE=.*/POOL_SIZE=${{ secrets.POOL_SIZE }}/" .env - sed -i "s/PORT=.*/PORT=${{ secrets.PORT }}/" .env - sed -i "s/STAGING_BEARER_TOKEN=.*/STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}/" .env + sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" .env + sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" .env + sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" .env + sed -i "s|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|" .env + sed -i "s|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|" .env + sed -i "s|PORT=.*|PORT=${{ secrets.PORT }}|" .env + sed -i "s|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|" .env cd .. working-directory: ${{ github.workspace }} From 5201623bc46bb3a5018af1a8eab6a0da3621fca9 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:00:43 +0530 Subject: [PATCH 09/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 7a835338..59b456bb 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -30,7 +30,7 @@ jobs: - name: Update environment variables in .env run: | - cd config + cd /var/www/html/dbservice/config sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" .env sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" .env sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" .env From 756a2cd2330f8cceaaa03b4bc3922c85e8f6306e Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:02:34 +0530 Subject: [PATCH 10/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 59b456bb..702b9153 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -30,7 +30,7 @@ jobs: - name: Update environment variables in .env run: | - cd /var/www/html/dbservice/config + cd /var/www/html/db-service/config sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" .env sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" .env sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" .env From d271b3b723780899d3669dd7d07e64042a607ccc Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:08:02 +0530 Subject: [PATCH 11/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 30 +++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 702b9153..e39758ce 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -10,26 +10,24 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - uses: actions/checkout@v2 Deploy: needs: build runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up environment - run: | - branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" - echo "$PRIVATE_KEY" > private_key && chmod 600 private_key + - uses: actions/checkout@v2 + - name: Deploy in EC2 env: PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + HOSTNAME: ${{ secrets.HOSTNAME }} + USER_NAME: ${{ secrets.USER_NAME }} - - name: Update environment variables in .env run: | + branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" + echo "$PRIVATE_KEY" > private_key && chmod 600 private_key + ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html/db-service/config sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" .env sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" .env @@ -38,16 +36,6 @@ jobs: sed -i "s|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|" .env sed -i "s|PORT=.*|PORT=${{ secrets.PORT }}|" .env sed -i "s|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|" .env - cd .. - working-directory: ${{ github.workspace }} - - - name: Deploy in EC2 - env: - HOSTNAME: ${{ secrets.HOSTNAME }} - USER_NAME: ${{ secrets.USER_NAME }} - - run: | - ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html sudo ./kill_process_on_port_4000.sh cd /var/www/html/db-service && @@ -61,4 +49,4 @@ jobs: sudo MIX_ENV=prod mix ecto.migrate && sudo MIX_ENV=prod mix phx.swagger.generate && sudo MIX_ENV=prod elixir --erl "-detached" -S mix phx.server - " + " \ No newline at end of file From 1f77407ef4a2442d2ec270e2f39ebe82d61245c9 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:11:54 +0530 Subject: [PATCH 12/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index e39758ce..2ed0bf8c 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -29,13 +29,13 @@ jobs: echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html/db-service/config - sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" .env - sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" .env - sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" .env - sed -i "s|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|" .env - sed -i "s|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|" .env - sed -i "s|PORT=.*|PORT=${{ secrets.PORT }}|" .env - sed -i "s|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|" .env + sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" /var/www/html/db-service/config/.env + sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" /var/www/html/db-service/config/.env + sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" /var/www/html/db-service/config/.env + sed -i "s|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|" /var/www/html/db-service/config/.env + sed -i "s|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|" /var/www/html/db-service/config/.env + sed -i "s|PORT=.*|PORT=${{ secrets.PORT }}|" /var/www/html/db-service/config/.env + sed -i "s|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|" /var/www/html/db-service/config/.env cd /var/www/html sudo ./kill_process_on_port_4000.sh cd /var/www/html/db-service && From 9f1c8a5964a5d8eb735b5449e38ed6428adc9150 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:19:39 +0530 Subject: [PATCH 13/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 2ed0bf8c..0279f73c 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -29,13 +29,13 @@ jobs: echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html/db-service/config - sed -i "s|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|" /var/www/html/db-service/config/.env - sed -i "s|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|" /var/www/html/db-service/config/.env - sed -i "s|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|" /var/www/html/db-service/config/.env - sed -i "s|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|" /var/www/html/db-service/config/.env - sed -i "s|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|" /var/www/html/db-service/config/.env - sed -i "s|PORT=.*|PORT=${{ secrets.PORT }}|" /var/www/html/db-service/config/.env - sed -i "s|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|" /var/www/html/db-service/config/.env + sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|'' /var/www/html/db-service/config/.env + sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|' /var/www/html/db-service/config/.env + sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|' /var/www/html/db-service/config/.env + sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|' /var/www/html/db-service/config/.env + sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|' /var/www/html/db-service/config/.env + sed -i 's|PORT=.*|PORT=${{ secrets.PORT }}|' /var/www/html/db-service/config/.env + sed -i 's|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' /var/www/html/db-service/config/.env cd /var/www/html sudo ./kill_process_on_port_4000.sh cd /var/www/html/db-service && From 25765699c2d71492e56e4f322364283356b76e3f Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:24:28 +0530 Subject: [PATCH 14/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 0279f73c..2f158571 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -28,14 +28,14 @@ jobs: branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " - cd /var/www/html/db-service/config - sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|'' /var/www/html/db-service/config/.env - sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|' /var/www/html/db-service/config/.env - sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|' /var/www/html/db-service/config/.env - sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|' /var/www/html/db-service/config/.env - sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|' /var/www/html/db-service/config/.env - sed -i 's|PORT=.*|PORT=${{ secrets.PORT }}|' /var/www/html/db-service/config/.env - sed -i 's|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' /var/www/html/db-service/config/.env + cd /var/www/html/db-service/config + sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|' .env + sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|' .env + sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|' .env + sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|' .env + sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|' .env + sed -i 's|PORT=.*|PORT=${{ secrets.PORT }}|' .env + sed -i 's|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' .env cd /var/www/html sudo ./kill_process_on_port_4000.sh cd /var/www/html/db-service && From e8cd99f56781ea5d168bb26a88b6606debc46722 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 21:39:48 +0530 Subject: [PATCH 15/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 2f158571..5b51c73b 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -35,7 +35,7 @@ jobs: sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|' .env sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|' .env sed -i 's|PORT=.*|PORT=${{ secrets.PORT }}|' .env - sed -i 's|STAGING_BEARER_TOKEN=.*|STAGING_BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' .env + sed -i 's|BEARER_TOKEN=.*|BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' .env cd /var/www/html sudo ./kill_process_on_port_4000.sh cd /var/www/html/db-service && From 6f9e04ef281eecaf3a6ea0e3e6ee439696f077ba Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 22:01:13 +0530 Subject: [PATCH 16/30] made CD to fetch env variables from GH secret --- .github/workflows/staging_deploy.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/staging_deploy.yml b/.github/workflows/staging_deploy.yml index 5b51c73b..cec27cc4 100644 --- a/.github/workflows/staging_deploy.yml +++ b/.github/workflows/staging_deploy.yml @@ -29,12 +29,12 @@ jobs: echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} " cd /var/www/html/db-service/config - sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.DATABASE_URL }}|' .env - sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}|' .env - sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.PHX_HOST }}|' .env - sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.WHITELISTED_DOMAINS }}|' .env - sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.POOL_SIZE }}|' .env - sed -i 's|PORT=.*|PORT=${{ secrets.PORT }}|' .env + sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.STAGING_DATABASE_URL }}|' .env + sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.STAGING_SECRET_KEY_BASE }}|' .env + sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.STAGING_PHX_HOST }}|' .env + sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.STAGING_WHITELISTED_DOMAINS }}|' .env + sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.STAGING_POOL_SIZE }}|' .env + sed -i 's|PORT=.*|PORT=${{ secrets.STAGING_PORT }}|' .env sed -i 's|BEARER_TOKEN=.*|BEARER_TOKEN=${{ secrets.STAGING_BEARER_TOKEN }}|' .env cd /var/www/html sudo ./kill_process_on_port_4000.sh From ef811ea5bc12e8fbb29cc78792d2635667b46238 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Thu, 7 Sep 2023 22:38:03 +0530 Subject: [PATCH 17/30] made CD to fetch env variables from GH secret for prod --- .github/workflows/production_deploy.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/production_deploy.yml b/.github/workflows/production_deploy.yml index 025d1d48..3cb416f9 100644 --- a/.github/workflows/production_deploy.yml +++ b/.github/workflows/production_deploy.yml @@ -26,6 +26,15 @@ jobs: run: | echo "$PRIVATE_KEY" > private_key && chmod 600 private_key ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} ' + #Setting environment variables . + cd /var/www/html/db-service/config + sed -i 's|DATABASE_URL=.*|DATABASE_URL=${{ secrets.PRODUCTION_DATABASE_URL }}|' .env + sed -i 's|SECRET_KEY_BASE=.*|SECRET_KEY_BASE=${{ secrets.PRODUCTION_SECRET_KEY_BASE }}|' .env + sed -i 's|PHX_HOST=.*|PHX_HOST=${{ secrets.PRODUCTION_PHX_HOST }}|' .env + sed -i 's|WHITELISTED_DOMAINS=.*|WHITELISTED_DOMAINS=${{ secrets.PRODUCTION_WHITELISTED_DOMAINS }}|' .env + sed -i 's|POOL_SIZE=.*|POOL_SIZE=${{ secrets.PRODUCTION_POOL_SIZE }}|' .env + sed -i 's|PORT=.*|PORT=${{ secrets.PRODUCTION_PORT }}|' .env + sed -i 's|BEARER_TOKEN=.*|BEARER_TOKEN=${{ secrets.PRODUCTION_BEARER_TOKEN }}|' .env #Now we have got the access of EC2 and we will start the deploy . cd /var/www/html From a8410354af8c2274ce46a634d0c32bd3b6caeda6 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 12 Sep 2023 21:33:02 +0530 Subject: [PATCH 18/30] added CORS policy --- lib/dbservice_web/endpoint.ex | 1 + mix.exs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dbservice_web/endpoint.ex b/lib/dbservice_web/endpoint.ex index 906312f3..f291f807 100644 --- a/lib/dbservice_web/endpoint.ex +++ b/lib/dbservice_web/endpoint.ex @@ -46,6 +46,7 @@ defmodule DbserviceWeb.Endpoint do plug Plug.Session, @session_options plug DbserviceWeb.DomainWhitelistPlug plug DbserviceWeb.AuthenticationMiddleware + plug CORSPlug plug DbserviceWeb.Router end diff --git a/mix.exs b/mix.exs index 0bba2019..760da75e 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,8 @@ defmodule Dbservice.MixProject do {:ex_check, "~> 0.14.0", only: [:dev], runtime: false}, {:dialyxir, ">= 0.0.0", only: [:dev], runtime: false}, {:credo, ">= 0.0.0", only: [:dev], runtime: false}, - {:dotenvy, "~> 0.8.0"} + {:dotenvy, "~> 0.8.0"}, + {:cors_plug, "~> 3.0"} ] end From 03995f344ae5067779719d90c33e21a7b98dfae7 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Wed, 13 Sep 2023 11:23:49 +0530 Subject: [PATCH 19/30] ordered CORS plug --- lib/dbservice_web/endpoint.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dbservice_web/endpoint.ex b/lib/dbservice_web/endpoint.ex index f291f807..37337792 100644 --- a/lib/dbservice_web/endpoint.ex +++ b/lib/dbservice_web/endpoint.ex @@ -44,9 +44,9 @@ defmodule DbserviceWeb.Endpoint do plug Plug.MethodOverride plug Plug.Head plug Plug.Session, @session_options + plug CORSPlug plug DbserviceWeb.DomainWhitelistPlug plug DbserviceWeb.AuthenticationMiddleware - plug CORSPlug plug DbserviceWeb.Router end From 7a8c3574e38dcdafbec22173a867e8b683f0ded4 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Fri, 22 Sep 2023 15:25:00 +0530 Subject: [PATCH 20/30] added changes --- .gitignore | 3 +++ .../migrations/20230630100806_alter_student_table_column.exs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9471df6a..b93daa16 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ erl_crash.dump # Ignore package tarball (built via "mix hex.build"). dbservice-*.tar +# Ignore .env +/config/.env + diff --git a/priv/repo/migrations/20230630100806_alter_student_table_column.exs b/priv/repo/migrations/20230630100806_alter_student_table_column.exs index c3751169..799a374e 100644 --- a/priv/repo/migrations/20230630100806_alter_student_table_column.exs +++ b/priv/repo/migrations/20230630100806_alter_student_table_column.exs @@ -2,7 +2,7 @@ defmodule Dbservice.Repo.Migrations.AlterStudentTable do use Ecto.Migration def change do - alter table(:session) do + alter table(:student) do modify(:has_internet_access, :string) end end From c26158d8ea74390293bd1b41cc200722e15ad230 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Sat, 23 Sep 2023 19:03:50 +0530 Subject: [PATCH 21/30] allowed request from swagger --- lib/dbservice_web/endpoint.ex | 1 - .../plugs/authentication_middleware_plug.ex | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/dbservice_web/endpoint.ex b/lib/dbservice_web/endpoint.ex index 37337792..255e45f9 100644 --- a/lib/dbservice_web/endpoint.ex +++ b/lib/dbservice_web/endpoint.ex @@ -45,7 +45,6 @@ defmodule DbserviceWeb.Endpoint do plug Plug.Head plug Plug.Session, @session_options plug CORSPlug - plug DbserviceWeb.DomainWhitelistPlug plug DbserviceWeb.AuthenticationMiddleware plug DbserviceWeb.Router diff --git a/lib/dbservice_web/plugs/authentication_middleware_plug.ex b/lib/dbservice_web/plugs/authentication_middleware_plug.ex index 01b2dace..146c93cf 100644 --- a/lib/dbservice_web/plugs/authentication_middleware_plug.ex +++ b/lib/dbservice_web/plugs/authentication_middleware_plug.ex @@ -15,10 +15,19 @@ defmodule DbserviceWeb.AuthenticationMiddleware do def call(conn, _opts) do source(["config/.env", "config/.env"]) + IO.inspect(conn) + + referer = + get_req_header(conn, "referer") + |> List.first() + |> to_string() + + request_path = conn.request_path api_key = get_req_header(conn, "authorization") - if api_key == ["Bearer " <> env!("BEARER_TOKEN", :string!)] do + if api_key == ["Bearer " <> env!("BEARER_TOKEN", :string!)] || + is_swagger_request?(referer, request_path) do conn else conn @@ -26,4 +35,8 @@ defmodule DbserviceWeb.AuthenticationMiddleware do |> halt() end end + + defp is_swagger_request?(referer, request_path) do + String.contains?(referer, "swagger") || String.contains?(request_path, "swagger") + end end From 4416d4e32b39676b11105bce67f14f09522586b7 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Sat, 23 Sep 2023 19:07:11 +0530 Subject: [PATCH 22/30] fixed ci checks --- lib/dbservice_web/plugs/authentication_middleware_plug.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/dbservice_web/plugs/authentication_middleware_plug.ex b/lib/dbservice_web/plugs/authentication_middleware_plug.ex index 146c93cf..a0645a46 100644 --- a/lib/dbservice_web/plugs/authentication_middleware_plug.ex +++ b/lib/dbservice_web/plugs/authentication_middleware_plug.ex @@ -15,7 +15,6 @@ defmodule DbserviceWeb.AuthenticationMiddleware do def call(conn, _opts) do source(["config/.env", "config/.env"]) - IO.inspect(conn) referer = get_req_header(conn, "referer") From a0d3c8563a72cb59ee2b1e0ce3a5c850212e0d1b Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Fri, 29 Sep 2023 14:02:26 +0530 Subject: [PATCH 23/30] logging access logs to separate file --- config/config.exs | 7 ++++++- logs/info.log | 0 mix.exs | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 logs/info.log diff --git a/config/config.exs b/config/config.exs index 473a3fc1..54124361 100644 --- a/config/config.exs +++ b/config/config.exs @@ -31,10 +31,15 @@ config :dbservice, Dbservice.Mailer, adapter: Swoosh.Adapters.Local config :swoosh, :api_client, false # Configures Elixir's Logger -config :logger, :console, +config :logger, + backends: [:console, {LoggerFileBackend, :error_log}], format: "$time $metadata[$level] $message\n", metadata: [:request_id] +config :logger, :error_log, + path: "logs/info.log", + level: :debug + # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason diff --git a/logs/info.log b/logs/info.log new file mode 100644 index 00000000..e69de29b diff --git a/mix.exs b/mix.exs index 0bba2019..254de880 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,8 @@ defmodule Dbservice.MixProject do {:ex_check, "~> 0.14.0", only: [:dev], runtime: false}, {:dialyxir, ">= 0.0.0", only: [:dev], runtime: false}, {:credo, ">= 0.0.0", only: [:dev], runtime: false}, - {:dotenvy, "~> 0.8.0"} + {:dotenvy, "~> 0.8.0"}, + {:logger_file_backend, "~> 0.0.13"} ] end From 9464cca6838c6f24e70965252e269f08aa6a0f1d Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 11:51:21 +0530 Subject: [PATCH 24/30] removed info.log --- logs/info.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 logs/info.log diff --git a/logs/info.log b/logs/info.log deleted file mode 100644 index e69de29b..00000000 From b24335c8e526ca4b33aca7b1d6a8cd8621f626a8 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 11:54:12 +0530 Subject: [PATCH 25/30] added info.log to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b93daa16..131b0392 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ dbservice-*.tar # Ignore .env /config/.env +# Ignore log file +/logs/info.log From c8d7e47a4c6b1ec7062e4d21e050d302079799e8 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 13:15:21 +0530 Subject: [PATCH 26/30] minor configuration changes --- config/config.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index 54124361..7f568878 100644 --- a/config/config.exs +++ b/config/config.exs @@ -32,13 +32,11 @@ config :swoosh, :api_client, false # Configures Elixir's Logger config :logger, - backends: [:console, {LoggerFileBackend, :error_log}], + backends: [:console, {LoggerFileBackend, :info}], format: "$time $metadata[$level] $message\n", metadata: [:request_id] -config :logger, :error_log, - path: "logs/info.log", - level: :debug +config :logger, :info, path: "logs/info.log" # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason From f55cad3ef30ea43303eb7853da5ae2a005107151 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 13:30:42 +0530 Subject: [PATCH 27/30] minor configuration changes --- config/config.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index 7f568878..a5d9db59 100644 --- a/config/config.exs +++ b/config/config.exs @@ -32,11 +32,11 @@ config :swoosh, :api_client, false # Configures Elixir's Logger config :logger, - backends: [:console, {LoggerFileBackend, :info}], + backends: [:console, {LoggerFileBackend, :file_log}], format: "$time $metadata[$level] $message\n", metadata: [:request_id] -config :logger, :info, path: "logs/info.log" +config :logger, :file_log, path: "logs/info.log" # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason From 50ecc4d2bbbc2b4420affc8d0cb81963c51ca375 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 13:32:22 +0530 Subject: [PATCH 28/30] changes in prod.exs --- config/prod.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/prod.exs b/config/prod.exs index 0baa7ec2..ed66d199 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -12,7 +12,7 @@ import Config # config :dbservice, DbserviceWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" # Do not print debug messages in production -config :logger, level: :info +config :logger, :console, format: "[$level] $message\n" # ## SSL Support # From 0cad385705601f718428fced5463fd2c5f6577f5 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 15:10:50 +0530 Subject: [PATCH 29/30] minor configuration changes --- config/config.exs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index a5d9db59..76c0ac3d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -32,11 +32,14 @@ config :swoosh, :api_client, false # Configures Elixir's Logger config :logger, - backends: [:console, {LoggerFileBackend, :file_log}], + backends: [:console, {LoggerFileBackend, :request_log}], format: "$time $metadata[$level] $message\n", metadata: [:request_id] -config :logger, :file_log, path: "logs/info.log" +config :logger, :request_log, + path: "logs/info.log", + format: "$time $metadata[$level] $message\n", + metadata: [:request_id] # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason From f478717e44b9b460dfce5839fd4c7910549169b2 Mon Sep 17 00:00:00 2001 From: Bahugunajii Date: Tue, 3 Oct 2023 15:28:43 +0530 Subject: [PATCH 30/30] making debug errors to true --- config/runtime.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index c2759089..f0b99607 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -23,5 +23,6 @@ if config_env() == :prod do ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port ], - secret_key_base: secret_key_base + secret_key_base: secret_key_base, + debug_errors: true end