Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Umbrella PR for v1.0.0 #7

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.ts linguist-detectable=false
*.scss linguist-detectable=false
*.css linguist-detectable=false
*.go linguist-generated=false
*.go linguist-detectable=true
*.css linguist-detectable=false
*.html linguist-detectable=false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
bin/main
.secrets/**
!.secrets/*.secret
config.yml
config.yaml
kratos
auth/authz.development.yml
auth/rogue.yml
2 changes: 2 additions & 0 deletions .gitsecret/paths/mapping.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.secrets/credentials.json:8e5c408e3c2e6131d943e3d4751f5fba0e8a12d69d2fee24a3365232d4487ab8
.secrets/token.json:111664e94a89be8d1333c0e648831461d598d3fd5208cae43bc42c63768d70ad
config.yaml:516f4cda9e452351747a879ce7c00871a7687c6d45af129aefe70baa5ede767f
auth/rogue.yml:cfa5d85da9280ad77275ec56d3341d6b067be2a09eca20f69d8c20ef8cc0fe00
38 changes: 0 additions & 38 deletions .keto/access-policy.json

This file was deleted.

39 changes: 0 additions & 39 deletions .keto/keto.yaml

This file was deleted.

Empty file removed .keto/roles/user.example.json
Empty file.
5 changes: 4 additions & 1 deletion .kratos/.kratos.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
session:
lifespan: 24h

dsn: memory

serve:
public:
base_url: http://127.0.0.1:3001/.ory/kratos/public
Expand Down Expand Up @@ -48,7 +51,7 @@ hashers:
salt_length: 16
key_length: 16
identity:
default_schema_url: file:///etc/config/kratos/identity.traits.schema.json
default_schema_url: file:///home/mshivam/AnC/go/.kratos/identity.traits.schema.json
courier:
smtp:
connection_uri: smtps://anc.courses@gmail.com:AnC@2020@smtp.gmail.com:465/?skip_ssl_verify=true
Binary file modified .secrets/credentials.json.secret
Binary file not shown.
Binary file modified .secrets/token.json.secret
Binary file not shown.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

## 09/02/2021 `v0.1.0`

- Initial Commit for web app

## 10/02/2021 `v0.1.1`

- GraphQL support added!

## 03/02/2021 `v0.1.2`

- Ory KETO has been phased out in support of Custom MongoDB Solution.
- Nodemailer has been phased out in support of go `net/smtp` package.
10 changes: 0 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,11 @@ RUN bash <(curl https://raw.githubusercontent.com/ory/kratos/v0.5.0-alpha.1/inst

RUN bash <(curl https://raw.githubusercontent.com/ory/oathkeeper/master/install.sh) -b . v0.38.6-beta.1

RUN bash <(curl https://raw.githubusercontent.com/ory/keto/master/install.sh) -b . v0.5.7-alpha.1

FROM node:latest
WORKDIR /
COPY ./mail/ /
RUN yarn install
RUN yarn build

FROM ubuntu:latest
RUN mkdir -p /var/www/bin/
COPY --from=0 /server/bin/main /var/www/bin/fiber
COPY --from=1 /home/download/kratos /var/www/bin/kratos
COPY --from=1 /home/download/keto /var/www/bin/keto
COPY --from=1 /home/download/oathkeeper /var/www/bin/oathkeeper
COPY --from=2 /mailman /var/www/bin/mailman

# Install Supervisor
RUN apt update && apt install -y supervisor nginx unrar
Expand Down
64 changes: 64 additions & 0 deletions api/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package api

import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/Mshivam2409/AnC-Courses/models"
"github.com/Mshivam2409/AnC-Courses/services"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
)

// CreateFile sdfs
func CreateFile(c *fiber.Ctx) error {
d := services.GetService()
n, err := strconv.Atoi(c.FormValue("length"))
cno := c.FormValue("course")
if err != nil {
return &fiber.Error{Code: 422, Message: "Length of files must be a number"}
}
files := []string{}
for i := 0; i < n; i++ {
f, err := c.FormFile("file" + fmt.Sprint(n))
if err != nil {
return &fiber.Error{Code: 422, Message: "Unable to process file!"}
}
r, err := d.CreateFile("", f)
if err != nil {
return &fiber.Error{Code: 422, Message: "Unable to upload file!"}
}
out, err := json.Marshal(r)
if err != nil {
return &fiber.Error{Code: 422, Message: "Unable to get file ID!"}
}
files = append(files, string(out))
}
update := bson.D{
{Key: "$push", Value: bson.D{
{Key: "driveFiles", Value: bson.A{"$each", files}},
}},
}
err = services.MongoClient.Courses.Collection("courses").FindOneAndUpdate(context.TODO(), bson.D{{Key: "number", Value: cno}}, update).Decode(&models.MGMCourse{})
return c.Status(200).JSON(fiber.Map{"message": "success"})
}

func DownloadFile(ctx *fiber.Ctx) error {
d := services.GetService()
s, err := d.GetFile(ctx.Params("fid"))
if err != nil {
return &fiber.Error{Code: 500, Message: "Unable to download file!"}
}
return ctx.Status(200).SendStream(s)
}

func Register(ctx *fiber.Ctx) error {
u := ctx.FormValue("username")
err := services.OryClient.CreateUser(u)
if err != nil {
return fiber.NewError(401, fmt.Sprint(err))
}
return ctx.Status(200).JSON(fiber.Map{})
}
38 changes: 38 additions & 0 deletions api/fiber.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package api

import (
"github.com/ansrivas/fiberprometheus/v2"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/recover"
)

func FiberListenAndServe() error {
app := fiber.New(fiber.Config{
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
message := "Internal Server Error"
if e, ok := err.(*fiber.Error); ok {
code = e.Code
message = e.Message
}
err = ctx.Status(code).JSON(fiber.Map{"message": message})
if err != nil {
return ctx.Status(500).SendString("Internal Server Error")
}
return nil
},
})
app.Use(cors.New(cors.Config{AllowOrigins: "*"}))
app.Use(recover.New())
prometheus := fiberprometheus.New("fiber")
prometheus.RegisterAt(app, "/metrics")
app.Use(prometheus.Middleware)
SetupRoutes(app)
app.Static("/", "html")
err := app.Listen(":5000")
if err != nil {
return err
}
return nil
}
8 changes: 5 additions & 3 deletions router/router.go → api/router.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router
package api

import (
"log"
Expand All @@ -16,7 +16,7 @@ import (
// SetupRoutes ....
func SetupRoutes(app *fiber.App) {
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
cache, err := services.NewCache(viper.GetString("redis"), viper.GetString("fsd"), 24*time.Hour)
cache, err := services.NewCache(viper.GetString("redis.host"), viper.GetString("redis.pwd"), 24*time.Hour)
if err != nil {
log.Printf("cannot create APQ redis cache: %v", err)
}
Expand All @@ -29,5 +29,7 @@ func SetupRoutes(app *fiber.App) {
return nil
})
restAPI := app.Group("/secure")
restAPI.Post("/file/create", services.CreateFile)
restAPI.Post("/file/create", CreateFile)
app.Get("/file/:fid", DownloadFile)
app.Post("/register", Register)
}
12 changes: 12 additions & 0 deletions auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
*.log

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
30 changes: 30 additions & 0 deletions auth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "rogue"
version = "0.1.0"
authors = ["Mshivam2409 <shivammalhotra08@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde_json = "1.0"
serde_yaml = "0.8"
serde_derive = "1.0"
serde = "1.0"
rocket = "0.4.7"
graphql-parser = "0.2.3"
yaml-rust = "0.4.5"
lazy_static = "1.4.0"
strum_macros = "0.20.1"
clap = "3.0.0-beta.2"
log = "0.4"
fern = "0.5"
chrono = "0.4"
[dependencies.mongodb]
version = "1.2.0"
default-features = false
features = ["sync"]
[dependencies.rocket_contrib]
version = "0.4.7"
default-features = false
features = ["json"]
21 changes: 21 additions & 0 deletions auth/Rocket.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[development]
address = "localhost"
port = 8080
workers = 2
keep_alive = 5
read_timeout = 5
write_timeout = 5
log = "normal"
limits = { forms = 32768 }

[production]
address = "localhost"
port = 8080
workers = 2
keep_alive = 5
read_timeout = 5
write_timeout = 5
log = "normal"
limits = { forms = 32768 }


Binary file added auth/rogue.yml.secret
Binary file not shown.
11 changes: 11 additions & 0 deletions auth/src/config/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use clap::Clap;

/// This doc string acts as a help message when the user runs '--help'
/// as do all doc strings on fields
#[derive(Clap)]
#[clap(version = "1.0", author = "Mshivam2409 <shivammalhotra08@gmail.com>")]
pub struct Opts {
/// Sets a custom config file. Could have been an Option<T> with no default too
#[clap(short, long, default_value = "rogue.yml")]
pub config: String,
}
4 changes: 4 additions & 0 deletions auth/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// src/config/mod.rs
mod cli;
mod yaml;
pub use yaml::Config;
Loading