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

Updated deployment pipeline + updated config #5

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
10 changes: 8 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
push_to_registery:
name: Push Docker image
runs-on: ubuntu-latest
#environment: Azure
environment: Azure
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand All @@ -25,6 +25,12 @@ jobs:
with:
images: michalmoudry/user-service

- name: Edit app's config
uses: jacobtomlinson/gha-find-replace@v3
find: "[dev]"
replace: "[prod]"
include: "**config.toml"

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
Expand All @@ -37,7 +43,7 @@ jobs:
name: Deploy
runs-on: ubuntu-latest
needs: [push_to_registery]
#environment: Azure
environment: Azure
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand Down
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,43 @@


# User service
A repository with a service for managing users. This repository is part of Microservices Reference Framework.
A repository with a service for managing users. This repository is part of [Microservices Reference Framework](https://github.com/MichalMoudry/microservices-reference-framework "Link to Microservices Reference Framework").

[![Build and test project](https://github.com/MichalMoudry/mrf-user-service/actions/workflows/go.yml/badge.svg)](https://github.com/MichalMoudry/mrf-user-service/actions/workflows/go.yml)
[![Deploy to Azure](https://github.com/MichalMoudry/mrf-user-service/actions/workflows/deploy.yml/badge.svg)](https://github.com/MichalMoudry/mrf-user-service/actions/workflows/deploy.yml)

## Project structure
- /src
- /cmd
- **/src** - Folder with all the source/test code related to this service.
- /cmd - Folder with service's entrypoints.
- /internal
- /transport
- /service
- /config
- /.dapr
- /.azure
- /assets
- **/.dapr** - Folder with Dapr components for local deployment.
- **/.azure** - Folder containing definitions for Azure resources.
- **/assets** - Folder with repository's assets that are not part of the source code.

### Service architecture
This section describes architecture of this particular service and not the entire system.

**Note**: Arrows in the diagram below display direction of dependencies between layers. This project utilises Inversion of Control pattern for many component, layers including.

```mermaid
---
title: "Layers of the workflow service"
---
classDiagram
class transport["Transport layer"]
click transport href "https://github.com/MichalMoudry/mrf-workflow-service/tree/main/transport" "Go to transport layer package"
class service["Service layer"]
transport <-- service

note for transport "validates requests\nparses request content\ncontains HTTP middleware\nrequest & response contracts"
note for service "contains business logic\nhandles commiting transactions\nhandles rolling back of transactions\n..."
```

**Note**: This is a stateless service, so there is no persistance layer/database.

## Getting started

## Used technologies
3 changes: 2 additions & 1 deletion src/internal/config/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"encoding/json"
"os"
"strings"

firebase "firebase.google.com/go/v4"
)
Expand Down Expand Up @@ -35,7 +36,7 @@ func CreateFirebaseCredentials() ([]byte, error) {
Type: os.Getenv("FB_TYPE"),
ProjectId: "ocr-microservice-project",
PrivateKeyId: os.Getenv("FB_PRIV_KEY_ID"),
PrivateKey: os.Getenv("FB_PRIV_KEY"),
PrivateKey: strings.ReplaceAll(os.Getenv("FB_PRIV_KEY"), "\\n", "\n"),
ClientEmail: os.Getenv("FB_CLIENT_EMAIL"),
ClientId: os.Getenv("FB_CLIENT_ID"),
AuthUri: "https://accounts.google.com/o/oauth2/auth",
Expand Down
45 changes: 45 additions & 0 deletions src/internal/config/firebase_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package config

import (
"encoding/json"
"os"
"testing"
)

func Test_PrivateKeyFormatting(t *testing.T) {
type args struct {
privKey string
wantErr bool
}
tests := []struct {
name string
args args
}{
{
name: "Test basic string replacement in private key",
args: args{
privKey: "-----BEGIN PRIVATE KEY-----\\nwfjwjfowfkwepkf\\n",
wantErr: false,
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
os.Setenv("FB_PRIV_KEY", test.args.privKey)
data, err := CreateFirebaseCredentials()
if err != nil {
t.Error(err)
return
}

credentials := GoogleCredentials{}
err = json.Unmarshal(data, &credentials)
if err != nil {
t.Error(err)
return
}
t.Log(credentials)
})
}
}
Loading