Skip to content

Commit

Permalink
feat: added private routing
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Mar 4, 2024
1 parent fe20fa6 commit 5e1a59c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion backend/src/cache_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl CacheClient {
///
/// If the REST server connection fails, or if the output is an error (like 404), then this will return an Err.
pub async fn get_recipe_by_id(&self, id1: Uuid, id2: Uuid) -> Result<Recipe, RestError> {
let res = reqwest::get(self.url.join(format!("kubeRecipeByIds/{}/{}", id1, id2).as_str()).unwrap()).await?.text().await?;
let res = reqwest::get(self.url.join(format!("private/kubeRecipeByIds/{}/{}", id1, id2).as_str()).unwrap()).await?.text().await?;
Ok(serde_json::from_str(&res)?)
}
}
Expand Down
6 changes: 3 additions & 3 deletions kube_cache/server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func New(metrics *metrics.Metrics, database *model.Database, ai *aiStuff.KubeAi)
func (s *Server) Use(engine *gin.Engine) {
engine.GET("/cache_metrics", s.CacheMetrics)
engine.GET("/kubes", s.GetAllKubes)
engine.GET("/kubeRecipes", s.GetAllKubeRecipes)
engine.GET("/kubeById/:id", s.GetKube)
engine.GET("/kubeRecipes", s.GetAllKubeRecipes)
engine.GET("/kubeImageById/:id", s.GetKubeImage)
engine.GET("/kubeImageByIdNew/:id", s.RegenerateImage)
engine.GET("/kubeRecipeByIds/:id1/:id2", s.GetKubeRecipe)
engine.GET("/private/kubeImageByIdNew/:id", s.RegenerateImage)
engine.GET("/private/kubeRecipeByIds/:id1/:id2", s.GetKubeRecipe)

// index
engine.GET("/", s.Index)
Expand Down
40 changes: 24 additions & 16 deletions kube_cache/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Server) IndexPost(c *gin.Context) {
<h1>New Kube: %s</h1>
<p><a href='./'>Back</a></p>
<img src="./kubeImageById/%s" style="max-width: 100px; max-height: 100px;" loading="lazy" alt="%s"/>
<p><a href="./kubeImageByIdNew/%s">Regenerate Image</a></p>
<p><a href="./private/kubeImageByIdNew/%s">Regenerate Image</a></p>
</body>`,
kube.Name,
kube.Id,
Expand All @@ -65,9 +65,9 @@ func (s *Server) Index(c *gin.Context) {
kubesHtml := ""
for _, kube := range kubes {
kubesHtml += fmt.Sprintf(`<div style="max-width: 100px;">
<h3 class="word-wrap: break-word;">%s</h3>
<a href="./kubeImageByIdNew/%s">Regenerate Image</a>
<img src="./kubeImageById/%s" style="max-width: 100px; max-height: 100px;" loading="lazy" alt="%s"/>
<h3 style="word-wrap: break-word">%s</h3>
<a href="./private/kubeImageByIdNew/%s">Regenerate Image</a>
<img src="./kubeImageById/%s" style="max-width: 100px; max-height: 100px" loading="lazy" alt="%s"/>
</div>`, kube.Name, kube.Id, kube.Id, kube.Name)
}

Expand Down Expand Up @@ -95,23 +95,31 @@ func (s *Server) Index(c *gin.Context) {
<head>
<title>Kube Cache</title>
</head>
<body class="display: flex; margin: 0px; flex-direction: column; max-width: 100vw;">
<body style="display: flex; margin: 0px; flex-direction: column; max-width: 100vw">
<h1>Kube Cache</h1>
<h2>Endpoints</h2>
<ul>
<li><a href="./">/.</a></li>
<li><a href="./kubes">/kubes</a></li>
<li><a href="./kubeById/:id">/kubeById/:id</a></li>
<li><a href="./kubeImageById/:id">/kubeImageById/:id</a></li>
<li><a href="./kubeRecipes">/kubeRecipes</a></li>
<li><a href="./kubeRecipeByIds/:id1/:id2">/kubeRecipeByIds/:id1/:id2</a></li>
<li><a href="./cache_metrics">/cache_metrics</a></li>
<li><a href="./metrics">/metrics</a></li>
</ul>
<div style="display: flex; flex-direction: row; gap: 10px; flex-wrap: wrap; justify-content: between">
<ul style="min-width: 200px">
<li><a href="./">/.</a></li>
<li><a href="./kubes">/kubes</a></li>
<li><a href="./kubeById/:id">/kubeById/:id</a></li>
<li><a href="./kubeRecipes">/kubeRecipes</a></li>
<li><a href="./kubeImageById/:id">/kubeImageById/:id</a></li>
<li><a href="./private/kubeRecipeByIds/:id1/:id2">/private/kubeRecipeByIds/:id1/:id2</a></li>
<li><a href="./private/kubeImageByIdNew/:id">/private/kubeImageByIdNew/:id</a></li>
<li><a href="./cache_metrics">/cache_metrics</a></li>
<li><a href="./metrics">/metrics</a></li>
</ul>
<div style="min-width: 200px">
<p>
Metrics are collected on Grafana, private endpoints requires the same proxy authentication.
</p>
</div>
</div>
<h2>Create New Kube</h2>
%s
<h2>Kubes</h2>
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 10px; align-items: center; align-content: center;">
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 10px; align-items: center; align-content: center">
%s
</div>
<p>End of cache</p>
Expand Down

0 comments on commit 5e1a59c

Please sign in to comment.