瀏覽代碼

[cliconf] draft for clientconfig api

The clienconfig api will return values for the client to use upon
remote initialisation (like rsa keys etc)
cgars 7 年之前
父節點
當前提交
5c1283c866
共有 4 個文件被更改,包括 35 次插入0 次删除
  1. 4 0
      conf/app.ini
  2. 6 0
      pkg/setting/setting.go
  3. 1 0
      routes/api/v1/api.go
  4. 24 0
      routes/api/v1/misc/client.go

+ 4 - 0
conf/app.ini

@@ -542,6 +542,10 @@ ON = false
 ; is login required for webdav
 LOGGED = true
 
+[cliconfig]
+RSA_HOST_KEY = notset
+
+
 ; Extension mapping to highlight class
 ; e.g. .toml=ini
 [highlight.mapping]

+ 6 - 0
pkg/setting/setting.go

@@ -342,6 +342,10 @@ var (
 		DoiBase string
 	}
 
+	CliConfig struct {
+		RsaHostKey string
+	}
+
 	WebDav struct {
 		On     bool
 		Logged bool
@@ -709,6 +713,8 @@ func NewContext() {
 		log.Fatal(2, "Fail to map Search settings: %v", err)
 	} else if err = Cfg.Section("doi").MapTo(&Doi); err != nil {
 		log.Fatal(2, "Fail to map Doi settings: %v", err)
+	} else if err = Cfg.Section("cliconfig").MapTo(&CliConfig); err != nil {
+		log.Fatal(2, "Fail to map Client config settings: %v", err)
 	} else if err = Cfg.Section("dav").MapTo(&WebDav); err != nil {
 		log.Fatal(2, "Fail to map WebDav settings: %v", err)
 	}

+ 1 - 0
routes/api/v1/api.go

@@ -162,6 +162,7 @@ func RegisterRoutes(m *macaron.Macaron) {
 		// Handle preflight OPTIONS request
 		m.Options("/*", func() {})
 
+		m.Get("/cliconfig", misc.ClientC)
 		// Miscellaneous
 		m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
 		m.Post("/markdown/raw", misc.MarkdownRaw)

+ 24 - 0
routes/api/v1/misc/client.go

@@ -0,0 +1,24 @@
+package misc
+
+import (
+	"github.com/G-Node/gogs/pkg/context"
+	"github.com/G-Node/gogs/pkg/setting"
+	"encoding/json"
+	"net/http"
+	log "gopkg.in/clog.v1"
+)
+
+type CliCongig struct {
+	RsaHostKey string
+}
+
+func ClientC(c *context.APIContext) {
+	data, err := json.Marshal(setting.CliConfig)
+	if err != nil {
+		log.Info("Copuld not determine client congig: %+v", err)
+		c.WriteHeader(http.StatusInternalServerError)
+		return
+	}
+	c.WriteHeader(http.StatusOK)
+	c.Write(data)
+}