Reverse Proxy with SSL support, Generated client Configs, JWT client to server auth, closes #13

This commit is contained in:
2018-02-07 21:41:00 -05:00
parent 0abe1620c6
commit d6288f4aaa
17 changed files with 1816 additions and 1222 deletions

View File

@@ -15,6 +15,24 @@ var Logger *logrus.Logger
//Conn is the global websocket connection used to push server notification messages
var Conn *websocket.Conn
//IssuedTokensList contains a slice of all the tokens issues to applications
type IssuedTokensList struct {
ID int `storm:"id,unique"` //storm requires unique ID (will be 3) to save although there will only be one of these
SigningKey []byte
TokenNames []SingleToken
}
//SingleToken stores a single token and all of the associated information
type SingleToken struct {
ClientName string
}
//TorrentHistoryList holds the entire history of downloaded torrents by hash TODO implement a way to read this and maybe grab the name for every torrent as well
type TorrentHistoryList struct {
ID int `storm:"id,unique"` //storm requires unique ID (will be 2) to save although there will only be one of these
HashList []string
}
//RSSFeedStore stores all of our RSS feeds in a slice of gofeed.Feed
type RSSFeedStore struct {
ID int `storm:"id,unique"` //storm requires unique ID (will be 1) to save although there will only be one of these
@@ -64,12 +82,6 @@ type TorrentLocal struct {
TorrentFilePriority []TorrentFilePriority
}
//TorrentHistoryList holds the entire history of downloaded torrents by hash TODO implement a way to read this and maybe grab the name for every torrent as well
type TorrentHistoryList struct {
ID int `storm:"id,unique"` //storm requires unique ID (will be 2) to save although there will only be one of these
HashList []string
}
//FetchAllStoredTorrents is called to read in ALL local stored torrents in the boltdb database (called on server restart)
func FetchAllStoredTorrents(torrentStorage *storm.DB) (torrentLocalArray []*TorrentLocal) {
torrentLocalArray = []*TorrentLocal{} //creating the array of the torrentlocal struct
@@ -188,6 +200,25 @@ func StoreHashHistory(db *storm.DB, torrentHash string) {
}
}
//FetchJWTTokens fetches the stored client authentication tokens
func FetchJWTTokens(db *storm.DB) IssuedTokensList {
tokens := IssuedTokensList{}
err := db.One("ID", 3, &tokens)
if err != nil {
Logger.WithFields(logrus.Fields{"Tokens": tokens, "error": err}).Error("Unable to fetch Token database... should always be one token in database")
}
return tokens
}
//UpdateJWTTokens updates the database with new tokens as they are added
func UpdateJWTTokens(db *storm.DB, tokens IssuedTokensList) {
err := db.Update(&tokens)
if err != nil {
Logger.WithFields(logrus.Fields{"Tokens": tokens, "error": err}).Error("Unable to update Token database")
}
}
//FetchRSSFeeds fetches the RSS feed from db, which was setup when initializing database on first startup
func FetchRSSFeeds(db *storm.DB) RSSFeedStore {
RSSFeed := RSSFeedStore{}