Browse Source

update diagram

ubuntu-nvidia-bug
forest 8 months ago
parent
commit
ad14d2a7df
3 changed files with 64 additions and 27 deletions
  1. +42
    -6
      greenhouse-daemon/main.go
  2. BIN
      readme/architechture.png
  3. +22
    -21
      src/main/python/main.py

+ 42
- 6
greenhouse-daemon/main.go View File

@ -19,7 +19,26 @@ import (
errors "git.sequentialread.com/forest/pkg-errors"
)
type daemonAPI struct{}
type daemonAPI struct {
HTTPClient *http.Client
}
type ThresholdConfig struct {
DebugLog bool
ClientId string
GreenhouseDomain string
GreenhouseAPIKey string
GreenhouseThresholdPort int
CaCertificate string
// TODO rename Tls to TLS
ClientTlsKey string
ClientTlsCertificate string
AdminAPIPort int
AdminAPICACertificate string
AdminAPITlsKey string
AdminAPITlsCertificate string
// TODO Metrics MetricsConfig
}
const mainCAName = "greenhouse_daemon_localhost_ca"
@ -57,22 +76,39 @@ func main() {
}
}
//err := http.ListenAndServe("127.0.0.1:9572", daemonAPI{})
certPath := path.Join(daemonPath, "daemon.crt")
keyPath := path.Join(daemonPath, "daemon.key")
daemonAPIInstance := daemonAPI{
HTTPClient: &http.Client{
Timeout: time.Second * 10,
},
}
err = http.ListenAndServeTLS("127.0.0.1:9572", certPath, keyPath, daemonAPIInstance)
log.Fatalf("http.ListenAndServe returned %+v", err)
}
func (handler daemonAPI) ServeHTTP(response http.ResponseWriter, request *http.Request) {
switch path.Clean(request.URL.Path) {
case "/configdropbox":
case "/register":
if request.Method == "POST" {
// TODO validate this with the cloud service somehow?
query := request.URL.Query()
nodeId := query.Get("nodeId")
apiKey := query.Get("apiKey")
request, err := http.NewRequest("POST", fmt.Sprintf("https://forest-n-johnson.greenhouseusers.com/api/register/%s", nodeId), nil)
if err != nil {
http.Error(response, "greenhouse-daemon: 500 internal server error", http.StatusBadGateway)
return
}
request.Header().Add("Authorization", fmt.Sprintf("Bearer %s", apiKey))
client.Do(request)
} else {
response.Header().Set("Allow", "POST")
http.Error(response, "greenhouse-daemon: 405 method not allowed, try POST", http.StatusMethodNotAllowed)
}
default:
http.Error(response, "greenhouse-daemon: 404 not found, try POST /configdropbox", http.StatusNotFound)
http.Error(response, "greenhouse-daemon: 404 not found, try POST /register", http.StatusNotFound)
}
}


BIN
readme/architechture.png View File

Before After
Width: 853  |  Height: 436  |  Size: 64 KiB Width: 853  |  Height: 436  |  Size: 70 KiB

+ 22
- 21
src/main/python/main.py View File

@ -58,8 +58,8 @@ class LoginWindow(QWidget):
api_token_row.addLayout(api_token_layout)
api_token_row.addStretch()
login_button = QPushButton('Register')
login_button.clicked.connect(lambda: self.login_clicked(hostname_input.text(), api_token_input.text()))
register_button = QPushButton('Register')
register_button.clicked.connect(lambda: self.register_clicked(hostname_input.text(), api_token_input.text()))
vbox = QVBoxLayout()
vbox.addStretch()
vbox.addWidget(logo_label)
@ -71,37 +71,38 @@ class LoginWindow(QWidget):
vbox.setAlignment(hostname_row, Qt.AlignHCenter)
vbox.addLayout(api_token_row)
vbox.setAlignment(api_token_row, Qt.AlignHCenter)
vbox.addWidget(login_button)
vbox.setAlignment(login_button, Qt.AlignHCenter)
vbox.addWidget(register_button)
vbox.setAlignment(register_button, Qt.AlignHCenter)
vbox.addStretch()
self.setLayout(vbox)
def login_clicked(self, hostname: str, api_token: str):
config_fetcher = Worker(self.login_task, hostname, api_token)
config_fetcher.signals.result.connect(self.login_callback)
def register_clicked(self, hostname: str, api_token: str):
config_fetcher = Worker(self.register_task, hostname, api_token)
config_fetcher.signals.result.connect(self.register_callback)
QThreadPool.globalInstance().start(config_fetcher)
def login_task(self, hostname: str, api_token: str):
def register_task(self, hostname: str, api_token: str) ->:
try:
result = requests.post(
'http://forest-n-johnson.greenhouseusers.com/api/client_config/'+hostname,
'http://forest-n-johnson.greenhouseusers.com/api/try_register/'+hostname,
headers={'Authorization': 'Bearer '+api_token}
)
if not result.ok:
return (None, None, "request failed, server returned HTTP " + result.status_code + ": " + result.text)
result = requests.post(
'https://127.0.0.1/api/try_register/'+hostname
)
return (hostname, api_token, None)
except:
return (None, "request failed: " + my_exec_info_message(sys.exc_info()))
if not result.ok:
return (None, "request failed, server returned HTTP " + result.status_code + ": " + result.text)
try:
return (result.json(), None)
except:
return (None, "request failed, server returned an error: " + result.text)
return (None, None, "request failed: " + my_exec_info_message(sys.exc_info()))
def login_callback(self, result: Tuple[dict, str]):
config = result[0]
error = result[1]
def register_callback(self, result: Tuple[str, str, str]):
server_name = result[0]
api_token = result[1]
error = result[2]
if error is not None and error is not "":
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)


Loading…
Cancel
Save