Skip to content

Commit

Permalink
B2 (#59)
Browse files Browse the repository at this point in the history
* userfile added

* test pushing

* ass2

* adding put method

* pushing new files

* removing kerys

* changed the file

* changed the file

* changed the file

* sdsad

* sdsad

* sasdsaad

* sasdsaad

* sasdsaad

* sasdsaad

* sasdsaad

* sasdsaad

* assad

* assad

* assad

* assad

* workflow

* asda

* asdsa

* asdsa

* asdsa

* asdsad

* asdsad

* asdsad

* asdsad

* asdsad

* asdsad

* adsad

* adsad

* adsad

* adsad

* adsad

* pushing env

* dotenv

* asdsa

* add env

* Commit message for config/.env file

* commiting

* setup.sh

* deleted file

* added setup file

* asds

* adding postgresshitagain

* asdsad

* commented nologin

* initchange

* asdsa

* adding setup.sh

* adding setup.sh

* adding setup.sh

* adding setup.sh

* saad

* asddsd

* removing nodemoudles

* dotenv

* adding new stuff

* adding setup file

* adding setup file

* asdasdsa

* asasdsadsa

* asdsad

* asdsad
  • Loading branch information
pranavmakarand authored Jul 18, 2024
1 parent c9e4a44 commit 29ac0d4
Show file tree
Hide file tree
Showing 8,178 changed files with 648 additions and 880,370 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file modified .DS_Store
Binary file not shown.
11 changes: 9 additions & 2 deletions .github/workflows/build-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ jobs:
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
credentials_json: ${{ secrets.GCP_SA_KEY }}

# - name: Check Service Account Key File
# run: |
# if [ ! -f "${{ github.workspace }}/secrets/project4-414017-5c44874f2950.json" ]; then
# echo "Error: Service account key file not found."
# exit 1
# fi

- name: Check Service Account Key File
run: |
Expand All @@ -39,4 +46,4 @@ jobs:
run: packer init ./packer/centos-stream.pkr.hcl

- name: Build AMI
run: packer build ./packer/centos-stream.pkr.hcl
run: packer build ./packer/centos-stream.pkr.hcl
3 changes: 1 addition & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ jobs:
rm -rf node_modules
npm install
- run: npm test
- run: npm test
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
16 changes: 16 additions & 0 deletions bootup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Webapp
ConditionPathExists=/opt/csye6225/webapp/index.js
After=network.target

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/csye6225/webapp
ExecStart=/usr/bin/node /opt/csye6225/webapp/index.js
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
5 changes: 5 additions & 0 deletions config/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST = 'localhost'
DB_USER = 'postgres'
DB_PASS = 'root'
DB_NAME = 'cloudassignmentdatabase'
DB_PORT = 5432
33 changes: 28 additions & 5 deletions config/sequelizeconfig.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
const { Sequelize } = require('sequelize');
const dotenv = require('dotenv')
const path = require('path');

// Load environment variables from the .env file located in the config directory
const result = dotenv.config({ path: path.resolve(__dirname, '.env') });

if (result.error) {
console.error('Error loading .env file:', result.error);
} else {
console.log('.env file loaded successfully from config folder');
}

const dbHost = process.env.DB_HOST;
const dbUser = process.env.DB_USER;
const dbPass = process.env.DB_PASS;
const dbName = process.env.DB_NAME;
const dbPort = process.env.DB_PORT;

console.log('dbHost' + dbHost);
console.log('dbUser' + dbUser);
console.log('dbPass' + dbPass);
console.log('dbName' + dbName);
console.log('dbPort' + dbPort);

const sequelize = new Sequelize({
dialect: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'root',
database: 'cloudassignmentdatabase',
host: dbHost,
port: dbPort,
username: dbUser,
password: dbPass,
database: dbName,
define: {
timestamps: false,
},
Expand Down
68 changes: 68 additions & 0 deletions controllers/cloudfunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//email the user link
//verification link should expire in 2 minutes
//expired link shouldnt be used
const { PubSub } = require('@google-cloud/pubsub');
const nodemailer = require('nodemailer');
const crypto = require('crypto');

const pubsub = new PubSub();
const topicName = 'verify_email';
const verificationLinks = new Map(); // Store verification links in-memory (use a database for production)

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your-email-password'
}
});

exports.verifyEmail = async (event, context) => {
const pubsubMessage = event.data;
const user = JSON.parse(Buffer.from(pubsubMessage, 'base64').toString());

const token = crypto.randomBytes(20).toString('hex');
const verificationLink = `https://your-domain.com/verify-email?token=${token}`;

verificationLinks.set(token, {
email: user.email,
expires: Date.now() + 2 * 60 * 1000 // 2 minutes
});

const mailOptions = {
from: '[email protected]',
to: user.email,
subject: 'Verify Your Email Address',
text: `Click the link to verify your email address: ${verificationLink}`
};

try {
await transporter.sendMail(mailOptions);
console.log(`Verification email sent to ${user.email}`);
} catch (error) {
console.error(`Error sending verification email: ${error}`);
}
};

// Function to handle verification link expiration and user verification
exports.handleVerification = (req, res) => {
const { token } = req.query;

if (!verificationLinks.has(token)) {
return res.status(400).send('Invalid or expired verification link.');
}

const linkData = verificationLinks.get(token);

if (Date.now() > linkData.expires) {
verificationLinks.delete(token);
return res.status(400).send('Verification link expired.');
}

// Mark user as verified in the database (implementation depends on your setup)
// For example:
// User.update({ email_verified: true }, { where: { email: linkData.email } });

verificationLinks.delete(token);
res.send('Email verified successfully.');
};
22 changes: 22 additions & 0 deletions controllers/dummycontroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { publishMessage } = require("./trial");
const topicName = "verify_email";

const welcome = (req, res) => {
return res.status(200).json({
success: true,
message: "Welcome to User Profile Service:)",
});
};

const createUser = async (req, res) => {
let userObj = req.body;
// create user profile logic goes here...
let messageId = await publishMessage(topicName, userObj);

return res.status(200).json({
success: true,
message: `Message ${messageId} published :)`,
});
};

module.exports = {welcome, createUser};
74 changes: 74 additions & 0 deletions controllers/trial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// const { PubSub } = require('@google-cloud/pubsub');
// const pubsub = new PubSub({ projectId: 'project4-414017' }); // Use the correct project ID



// async function a() {
// const messageBuffer = Buffer.from(JSON.stringify({"empty": "boy"}));
// await pubsub.topic(topicName).publish(messageBuffer);
// }

// a();

const { PubSub } = require("@google-cloud/pubsub");
const path = require("path");
const topicName = 'verify_email'; // replace with your Pub/Sub topic name

const keyFilePath = path.join(__dirname, "../../../gcpkey/newkey2/project4-414017-f35db3a91268.json");
const projectId = "project4-414017";

// Create an instance of PubSub with the provided service account key
const pubSubClient = new PubSub({
projectId: projectId,
keyFilename: keyFilePath,
});

const publishMessage = async (topicName, payload) => {
const dataBuffer = Buffer.from(JSON.stringify(payload));
try {
const messageId = await pubSubClient
.topic(topicName)
.publishMessage({ data: dataBuffer });
console.log(`Message ${messageId} published.`);
return messageId;
} catch (error) {
console.error(`Received error while publishing: ${error.message}`);
}
};

const listenForPullMessages = async (subscriptionName, timeout) => {
const subscription = pubSubClient.subscription(subscriptionName);
let messageCount = 0;
let data = [];
const messageHandler = message => {
const jsonData = JSON.parse(message.data);

data.push({
id: message.id,
attributes: message.attributes,
...jsonData,
});
messageCount += 1;
message.ack();
};
subscription.on("message", messageHandler);

setTimeout(() => {
console.log("Message Pulled: \n", data);
console.log(`${messageCount} message(s) received.`);
subscription.removeListener("message", messageHandler);
}, timeout * 100);
}

const listenForPushMessages = payload => {
const message = Buffer.from(payload, "base64").toString("utf-8");
let parsedMessage = JSON.parse(message);
console.log("Message Pushed: \n", parsedMessage);
return parsedMessage;
}

module.exports = {
publishMessage,
listenForPullMessages,
listenForPushMessages,
};
49 changes: 49 additions & 0 deletions controllers/trial.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "google_compute_instance" "instance-20240221-230457" {
boot_disk {
auto_delete = true
device_name = "instance-20240221-230457"

initialize_params {
image = "projects/project4-414017/global/images/image-1"
size = 100
type = "pd-balanced"
}

mode = "READ_WRITE"
}

can_ip_forward = false
deletion_protection = false
enable_display = false

labels = {
goog-ec-src = "vm_add-tf"
}

machine_type = "e2-medium"
name = "instance-20240221-230457"

network_interface {
access_config {
network_tier = "STANDARD"
}

queue_count = 0
stack_type = "IPV4_ONLY"
subnetwork = "projects/project4-414017/regions/us-east1/subnetworks/webappsubnet"
}

scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
preemptible = false
provisioning_model = "STANDARD"
}

service_account {
email = "[email protected]"
scopes = ["https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring.write", "https://www.googleapis.com/auth/service.management.readonly", "https://www.googleapis.com/auth/servicecontrol", "https://www.googleapis.com/auth/trace.append"]
}

zone = "us-east1-b"
}
Loading

0 comments on commit 29ac0d4

Please sign in to comment.