Skip to content

Commit

Permalink
fix(grpc): client SSL config
Browse files Browse the repository at this point in the history
add README
add LICENSE
  • Loading branch information
ary82 committed Jun 23, 2024
1 parent a82cdf3 commit e5efddb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Aryan Goyal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# Balance

A website that can compliment and insult you, at the same time.

## Installation

1. Populate the environment variables defined at `.env.example` and rename it to `.env`

2. Regenerate the proto codes
_(Optional step, generated codes are checked into git)_

```bash
cd proto
./generate.sh
```

3. Run the http server and the grpc server

```bash
# App
make run
# Classification grpc
make py-server
```
2 changes: 1 addition & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
log.Fatal("dburl envvar empty")
}

err := infra.Run(dburl, classifyServerAddr, port)
err := infra.Run(dburl, mode, classifyServerAddr, port)
if err != nil {
log.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/classification_grpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ COPY ./proto/classification_pb2_grpc.py .

RUN pip install -r requirements.txt --no-cache-dir

EXPOSE 8000
CMD [ "python","./main.py" ]
8 changes: 5 additions & 3 deletions cmd/classification_grpc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# Load envs in dev mode
mode = os.getenv("MODE")
if mode != "prod":
load_dotenv("../.env")
load_dotenv("./.env")

port = os.getenv("PORT")
addr = "[::]:" + port
port = os.getenv("PORT") or ""
if port == "" or port is None:
port = "8000"
addr = "[::]:" + str(port)

# Configure Gemini
GOOGLE_API_KEY = os.getenv("GEMINI_KEY")
Expand Down
12 changes: 10 additions & 2 deletions internal/infra/cron.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package infra

import (
"crypto/tls"
"database/sql"

"github.com/ary82/balance/proto"
"github.com/ary82/balance/internal/cron"
"github.com/ary82/balance/internal/post"
"github.com/ary82/balance/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

func NewCron(
db *sql.DB,
mode string,
classifyServerAddr string,
posSseCh chan post.Post,
negSseCh chan post.Post,
) (cron.CronService, error) {
repo := cron.NewCronRepository(db)

creds := credentials.NewTLS(&tls.Config{})
if mode != "prod" {
creds = insecure.NewCredentials()
}

opts := []grpc.DialOption{
grpc.WithTransportCredentials(
insecure.NewCredentials(),
creds,
),
}

Expand Down
7 changes: 6 additions & 1 deletion internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

func Run(
dburl string,
mode string,
classifyServerAddr string,
port string,
) error {
Expand All @@ -19,7 +20,11 @@ func Run(
posSseCh := make(chan post.Post)
negSseCh := make(chan post.Post)

cron, err := NewCron(db, classifyServerAddr, posSseCh, negSseCh)
cron, err := NewCron(
db, mode,
classifyServerAddr,
posSseCh, negSseCh,
)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion static/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2 class="text-xl font-semibold">balance</h2>
<nav>
<h6 class="footer-title">Social</h6>
<div class="grid grid-flow-col gap-4">
<a href="https://github.com/ary82/urlstash" target="_blank" rel="noopener noreferrer">
<a href="https://github.com/ary82" target="_blank" rel="noopener noreferrer">
{{template "icons/github"}}
</a>
<a href="https://linkedin.com/in/aryan-goyal1" target="_blank" rel="noopener noreferrer">
Expand Down

0 comments on commit e5efddb

Please sign in to comment.