Skip to content

Commit

Permalink
Merge branch 'main' into Fix-CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurav-Shrivastav committed Jul 15, 2021
2 parents 0ca1141 + cb88304 commit 65cf5da
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 30 deletions.
13 changes: 13 additions & 0 deletions jabme/users/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.http import HttpResponse

allowed_ips = os.environ.get("ALLOWED_IPS", "localhost 127.0.0.1").split()
super_secret_header = os.environ.get("SECRET_HEADER")


def login_by_ip(view_func):
Expand All @@ -14,3 +15,15 @@ def authorize(request, *args, **kwargs):
return HttpResponse("Forbidden. F Off.")

return authorize


def validate_header(view_func):
def authorize(request, *args, **kwargs):
if (
"only-fan-secret-key" in request.headers
and super_secret_header == request.headers["only-fan-secret-key"]
):
return view_func(request, *args, **kwargs)
return HttpResponse("Forbidden. F Off.")

return authorize
6 changes: 3 additions & 3 deletions jabme/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from fake_useragent import UserAgent
from rest_framework.response import Response
from rest_framework.views import APIView
from users.decorators import login_by_ip
from users.decorators import validate_header
from users.models import District

PINCODE_REGEX = "^[1-9][0-9]{5}$"
Expand Down Expand Up @@ -74,7 +74,7 @@ def post(self, request):
return Response("Registered Successfully")


@method_decorator(login_by_ip, name="get")
@method_decorator(validate_header, name="get")
class FindSlotView(APIView):
def get(self, request):
time_threshold = datetime.now(timezone.utc) - timedelta(
Expand Down Expand Up @@ -206,7 +206,7 @@ def get(self, request):
return Response(result)


@method_decorator(login_by_ip, name="post")
@method_decorator(validate_header, name="post")
class UpdateEmailSentTime(APIView):
def post(self, request):
now = Now()
Expand Down
15 changes: 15 additions & 0 deletions mailer/src/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from "axios";
import { Agent } from "https";
import keys from "./config";

const agent = new Agent({ rejectUnauthorized: false });

const headers: { [k: string]: string } = {};
headers[keys.SECRET_HEADER_KEY] = keys.SECRET_HEADER_VALUE;

const axiosConfig = axios.create({
httpsAgent: agent,
headers,
});

export default axiosConfig;
2 changes: 1 addition & 1 deletion mailer/src/publisher/publisher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as amqp from "amqplib";
import keys from "../config";
import fetch from "./fetch";
import fetch from "./utils/fetch";

const main = async () => {
console.log("Trying to connect...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as axios from "axios";
import axios from "../../axios";

import ResponseData from "./fetch.types";
import { Agent } from "https";

const requestPromise = () => {
console.log("Trying to fetch...");

const agent = new Agent({ rejectUnauthorized: false });

return axios.default
.get("https://covaccinate.tech/api/users/slots/", { httpsAgent: agent })
return axios
.get("https://covaccinate.tech/api/users/slots/")
.then((res) => res.data as ResponseData[])
.catch((err: Error) => {
console.error(err.message);
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions mailer/src/subscriber/setLastSent.ts

This file was deleted.

6 changes: 3 additions & 3 deletions mailer/src/subscriber/subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as amqp from "amqplib";
import keys from "../config";
import sendEmails from "./mailgun";
import setLastSent from "./setLastSent";
import sendEmails from "./utils/mailgun";
import setLastSent from "./utils/setLastSent";

import ResponseData from "../publisher/fetch.types";
import ResponseData from "../publisher/utils/fetch.types";

const main = async () => {
console.log("Trying to connect...");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mailgun from "mailgun-js";
import keys from "../config";
import keys from "../../config";
import makeEmail from "./makeEmail";

import { ConsumeMessage } from "amqplib";
import ResponseData from "../publisher/fetch.types";
import ResponseData from "../../publisher/utils/fetch.types";
import { SendEmailItem } from "./mailgun.types";

const who = process.env.WHO?.trim().toUpperCase() || "ARYAMAN";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ResponseData from "../publisher/fetch.types";
import ResponseData from "../../publisher/utils/fetch.types";
import ejsTemplate from "./emailTemplate";
import ejs from "ejs";

Expand Down
9 changes: 9 additions & 0 deletions mailer/src/subscriber/utils/setLastSent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import axios from "../../axios";

const setLastSent = (district_id: string) => {
return axios.post("https://covaccinate.tech/api/users/update-lastsent/", {
district_ids: [district_id],
});
};

export default setLastSent;

0 comments on commit 65cf5da

Please sign in to comment.