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

Main to dev #29

Merged
merged 20 commits into from
Jun 16, 2024
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
55 changes: 55 additions & 0 deletions .github/workflows/cd-azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: cd-azure
on:
workflow_run:
workflows: ['CI pipeline']
types: [completed]
branches:
- main
workflow_dispatch: {}
env:
CLUSTER_NAME: skipass-cluster
CLUSTER_RESOURCE_GROUP: skipass-demo
DEPLOYMENT_MANIFEST_PATH: |
./docker_kubernetes/app/azure-deployment
jobs:
deploy:
permissions:
actions: read
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
name: Azure login
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}

- uses: azure/use-kubelogin@v1
name: Set up kubelogin for non-interactive login
with:
kubelogin-version: v0.0.25

- uses: azure/aks-set-context@v3
name: Get K8s context
with:
admin: "false"
cluster-name: ${{ env.CLUSTER_NAME }}
resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }}
use-kubelogin: "true"

- name: Deploy setup
run: |
kubectl apply -f https://github.com/envoyproxy/gateway/releases/download/v1.0.1/install.yaml
kubectl delete secret azure-secret --ignore-not-found
kubectl create secret generic azure-secret --from-literal=post-db-user=${{ secrets.AZURE_DB_USER }} --from-literal=post-db-pass=${{ secrets.AZURE_DB_PASS }} --from-literal=rabbitmq-user=${{ secrets.RABBITMQ_USER }} --from-literal=rabbitmq-pass=${{ secrets.RABBITMQ_PASS }}

- uses: Azure/k8s-deploy@v4
name: Deploys application
with:
action: deploy
manifests: ${{ env.DEPLOYMENT_MANIFEST_PATH }}
namespace: default
10 changes: 6 additions & 4 deletions PostManagement/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ spring.rabbitmq.port=${RABBITMQ_PORT}
spring.rabbitmq.username=${RABBITMQ_USER}
spring.rabbitmq.password=${RABBITMQ_PASS}
#DB setup
spring.datasource.url=jdbc:postgresql://${POST_DB_HOST}:${POST_DB_PORT}/posts
spring.datasource.username=${POST_DB_USER}
spring.datasource.password=${POST_DB_PASS}
#spring.datasource.url=jdbc:postgresql://${POST_DB_HOST}:${POST_DB_PORT}/posts
spring.datasource.url=jdbc:postgresql://post-database.postgres.database.azure.com:5432/postgres?user=${POST_DB_USER}&password=${POST_DB_PASS}&sslmode=require
#spring.datasource.username=${POST_DB_USER}
#spring.datasource.password=${POST_DB_PASS}
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.open-in-view=false
#spring.datasource.hikari.maximumPoolSize=100

Expand Down
12 changes: 6 additions & 6 deletions client/src/api/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type UserData = {

// export const createUser = (user: UserData) => {

// return axios.post('http://skipass.api:80/create-user', user).then((res) => {
// return axios.post('http://4.182.131.77/:80/create-user', user).then((res) => {
// return res;
// });
// };
Expand All @@ -22,25 +22,25 @@ export const createPost = (post: Post, token: string) => {
Authorization: 'Bearer ' + token,
};

return axios.post('http://skipass.api:80/create-post',post, {headers}).then((res) => {
return axios.post('http://4.182.131.77/:80/create-post',post, {headers}).then((res) => {
return res;
});
};

// export const viewUsers = () => {
// return axios.get('http://skipass.api:80/get-users').then((res)=>{
// return axios.get('http://4.182.131.77/:80/get-users').then((res)=>{
// return res;
// });
// };

export const viewPostsForUser = (userEmail: string) => {
return axios.get(`http://skipass.api:80/view/${userEmail}`).then((res) => {
return axios.get(`http://4.182.131.77/:80/view/${userEmail}`).then((res) => {
return res;
});
};

// export const deleteUserProfile = (userId:number)=>{
// return axios.delete(`http://skipass.api:80/delete-profile/${userId}`).then((res) => {
// return axios.delete(`http://4.182.131.77/:80/delete-profile/${userId}`).then((res) => {
// return res;
// });
// };
Expand All @@ -51,7 +51,7 @@ export const deletePost = (postId:number, token: string)=>{
Authorization: 'Bearer ' + token,
};

return axios.delete(`http://skipass.api:80/delete-post/${postId}`, {headers}).then((res) => {
return axios.delete(`http://4.182.131.77/:80/delete-post/${postId}`, {headers}).then((res) => {
return res;
});
};
Expand Down
33 changes: 33 additions & 0 deletions client/src/components/atoms/AuthComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// import { useAuth0 } from '@auth0/auth0-react';



// export const UseAuthComponents = () => {
// const { user, isAuthenticated, getAccessTokenSilently, loginWithRedirect } = useAuth0();

// const getMetadata = async()=>{
// if (!isAuthenticated) {
// return;
// }
// const userDetailsByIdUrl: string = `https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/users/${user?.sub}`;
// const token = await getAccessTokenSilently({
// authorizationParams: {
// audience: 'https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/',
// scope: 'read:current_user',
// }});

// const metadata = await fetch(userDetailsByIdUrl, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });

// return await metadata.json();
// };

// return (
// getMetadata()
// );

// };

6 changes: 2 additions & 4 deletions client/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ export default function App(props: AppProps) {
clientId="pZ5kS27dqX4zxH3xzTF1Q18qz7dTLrrJ"
// useRefreshTokens={true}
authorizationParams={{
<<<<<<< Updated upstream
// redirect_uri: 'https://skipass.pages.dev/',
redirect_uri:'http://localhost:3000',
// redirect_uri: 'https://auth0.skipass.pages.dev/'
=======
// redirect_uri: 'https://skipass.pages.dev/',
>>>>>>> Stashed changes
redirect_uri:'http://localhost:3000',
audience: 'https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/',
scope: 'read:current_user, update:current_user_metadata'
}}
Expand Down
139 changes: 139 additions & 0 deletions client/src/pages/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { createPost, deletePost, viewPostsForUser } from '@/api/requests';
import { Post } from '@/api/types';
import Navigation from '@/components/molecultes/Navigation';
import { useAuth0 } from '@auth0/auth0-react';
import { Box, Button, List, ListItem, ListItemText, TextField, Typography } from '@mui/material';
import { useEffect, useState } from 'react';

const Profile = () => {

const { user, isAuthenticated, getAccessTokenSilently, loginWithRedirect } = useAuth0();
const [postsForUser, setPostsForUser] = useState<Post[]>([]);
const [postText, setPostText] = useState<string>('');
const [trigger, setTrigger] = useState<boolean>(false);

useEffect(() => {
viewPostsForLoggedInUser();
}, [trigger]);

const getMetadata = async()=>{
if (!isAuthenticated) {
return;
}
const userDetailsByIdUrl: string = `https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/users/${user?.sub}`;
const token = await getAccessTokenSilently({
authorizationParams: {
audience: 'https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/',
scope: 'read:current_user',
}});

const metadata = await fetch(userDetailsByIdUrl, {
headers: {
Authorization: `Bearer ${token}`,
},
});

return await metadata.json();
};

const createPostForUser = async() => {
if(!isAuthenticated) return;
const metadata = await getMetadata();
const post:Post = {
// @ts-ignore
userEmail: metadata.email,
text: postText,
};
const token = await getAccessTokenSilently({
authorizationParams: {
audience: 'https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/',
scope: 'read:current_user',
}}).catch(()=>{
loginWithRedirect();
});

if(!token) return;

await createPost(post, token).catch((e)=>{
if(e.response.status === 401){
loginWithRedirect();
}
}).then(()=>{
setTrigger(!trigger);
});
};


const deletePostById = async(id:number)=>{
const token = await getAccessTokenSilently({
authorizationParams: {
audience: 'https://dev-hxsl4k6mw7xspicu.eu.auth0.com/api/v2/',
scope: 'read:current_user',
}}).catch(()=>{
loginWithRedirect();
});

if(!token) return;


await deletePost(id, token).catch((e)=>{
console.log(e);
if(e.response.status === 401){
loginWithRedirect();
}
}).then(()=>{
setTrigger(!trigger);
});
};

const viewPostsForLoggedInUser = async()=>{
if(!isAuthenticated) return;
const metadata = await getMetadata();
// @ts-ignore
const res = await viewPostsForUser(metadata.email);
setPostsForUser(res.data);
};

return (
<>
<Navigation/>

{isAuthenticated && (
<>
<Box sx={{mt: 10, border: 1, borderColor: 'black'}} >
<TextField id="outlined-basic" label="Post" variant="outlined" required
onChange={(e)=>setPostText(e.target.value)} />
<Button variant="contained" onClick={()=>createPostForUser()}>Create post</Button>
</Box>

<List sx={{ width: '100%', maxWidth: 360, bgcolor: 'background.paper' }}>
My posts
{postsForUser.map((post)=>{
return (
<ListItem alignItems="flex-start">
<ListItemText
primary={post.userEmail}
secondary={
<Typography
sx={{ display: 'inline' }}
component="span"
variant="body2"
color="text.primary"
>
{post.text}
</Typography>
}
/>
<Button sx={{backgroundColor:'pink'}} size="small" variant="contained" onClick={()=>deletePostById(post.id!)}>Delete</Button>
</ListItem>
);
})}
</List>
</>
)}
</>
);
};

export default Profile;
14 changes: 5 additions & 9 deletions docker_kubernetes/app/azure-deployment/gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ metadata:
spec:
gatewayClassName: eg
listeners:
- name: https
protocol: HTTPS
port: 443
tls:
certificateRefs:
- group: ""
kind: Secret
name: skipass-cert
mode: Terminate
- name: http
protocol: HTTP
port: 80

---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
Expand Down Expand Up @@ -102,6 +97,7 @@ spec:
name: open-routes
cors:
allowOrigins:
- '*'
- "https://skipass.pages.dev"
allowMethods:
- GET
Expand Down
10 changes: 10 additions & 0 deletions docker_kubernetes/app/azure-deployment/global-config-azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: azure-config
data:
post-db-host: "post-database.postgres.database.azure.com"
post-db-port: "5432"
post-db-database: "postgres"
rabbitmq-host: "rabbitmq-service"
rabbitmq-port: "5672"
Loading
Loading