Fix ignore

This commit is contained in:
Daniel Ponte 2022-09-25 22:16:21 -04:00
parent cb347fa0a2
commit 5ccd438fbf
3 changed files with 102 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
blas
!cmd/blas/
Session.vim
coverage.txt

30
cmd/blas/main.go Normal file
View file

@ -0,0 +1,30 @@
package main
import (
"log"
"dynatron.me/x/blasphem/internal/common"
"dynatron.me/x/blasphem/pkg/cmd/serve"
"dynatron.me/x/blasphem/pkg/config"
"github.com/spf13/cobra"
)
func main() {
rootCmd := cobra.Command{
Use: common.AppName,
}
config, err := config.ReadConfig()
if err != nil {
log.Fatal(err)
}
rootCmd.AddCommand(serve.Command(config))
// rootCmd.AddCommand(package.MyCommand([conf]), ...)
err = rootCmd.Execute()
if err != nil {
panic(err)
}
}

71
pkg/server/authorize.go Normal file
View file

@ -0,0 +1,71 @@
package server
import (
"encoding/json"
"io"
"net/http"
)
type AuthProvider interface {
ProviderName() string
ProviderID() *string
ProviderType() string
}
type AuthProviderBase struct {
Name string `json:"name"`
ID *string `json:"id"`
Type string `json:"type"`
}
func (bp *AuthProviderBase) ProviderName() string { return bp.Name }
func (bp *AuthProviderBase) ProviderID() *string { return bp.ID }
func (bp *AuthProviderBase) ProviderType() string { return bp.Type }
type LocalProvider struct {
AuthProviderBase
}
func hassProvider() *LocalProvider {
return &LocalProvider{
AuthProviderBase: AuthProviderBase{
Name: "Home Assistant Local",
Type: "homeassistant",
},
}
}
// TODO: make this configurable
func (s *Server) providersHandler(w http.ResponseWriter, r *http.Request) {
providers := []AuthProvider{
hassProvider(),
}
rjs, err := json.Marshal(providers)
if err != nil {
panic(err)
}
logRequest(http.StatusOK, r)
_, err = w.Write(rjs)
if err != nil {
panic(err)
}
}
func (s *Server) authorizeHandler(w http.ResponseWriter, r *http.Request) {
authPage, err := s.rootFS.Open("authorize.html")
if err != nil {
panic(err)
}
defer authPage.Close()
logRequest(http.StatusOK, r)
_, err = io.Copy(w, authPage)
if err != nil {
panic(err)
}
}