Skip to content

Commit a03e079

Browse files
committed
feat(*): add endpoint to fetch application remote
1 parent 4d268bf commit a03e079

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

services/master/controllers/application.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"errors"
57
"fmt"
68
"strconv"
@@ -303,3 +305,24 @@ func FetchMetrics(c *gin.Context) {
303305
"data": metricsRecord,
304306
})
305307
}
308+
309+
func FetchAppRemote (c *gin.Context) {
310+
appName := c.Param("app")
311+
config, err := mongo.FetchSingleApp(appName)
312+
if err != nil {
313+
c.AbortWithStatusJSON(400, gin.H{
314+
"success": false,
315+
"error": err.Error(),
316+
})
317+
}
318+
319+
response := &types.ApplicationRemote{
320+
GitURL: config.Git.RepoURL,
321+
}
322+
323+
fmt.Println(response)
324+
325+
responseBody := new(bytes.Buffer)
326+
json.NewEncoder(responseBody).Encode(response)
327+
c.Data(200, "application/json", responseBody.Bytes())
328+
}

services/master/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func NewService() http.Handler {
7272
app.PATCH("/:app/transfer/:user", m.IsAppOwner, c.TransferApplicationOwnership)
7373
app.GET("/:app/term", m.IsAppOwner, c.DeployWebTerminal)
7474
app.GET("/:app/metrics", m.IsAppOwner, c.FetchMetrics)
75+
app.GET("/:app/remote", m.IsAppOwner, c.FetchAppRemote)
7576
}
7677

7778
db := router.Group("/dbs")

types/application.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ type ApplicationConfig struct {
9393
Success bool `json:"success,omitempty" bson:"-"`
9494
}
9595

96+
type ApplicationRemote struct {
97+
GitURL string `json:"giturl" bson:"giturl"`
98+
}
99+
96100
// GetName returns the application's name
97101
func (app *ApplicationConfig) GetName() string {
98102
return app.Name

0 commit comments

Comments
 (0)