This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started refactoring. Changed framework structure. Added credential se…
…rvice.
- Loading branch information
Showing
26 changed files
with
403 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<credentials> | ||
<entry> | ||
<type> | ||
codeoverflow.youtube.login | ||
</type> | ||
<identifier> | ||
sebinside | ||
</identifier> | ||
<values> | ||
<entry> | ||
<key> | ||
a key | ||
</key> | ||
<value> | ||
a value | ||
</value> | ||
</entry> | ||
</values> | ||
</entry> | ||
<entry> | ||
<type> | ||
codeoverflow.twitch.api | ||
</type> | ||
<identifier> | ||
skate702 | ||
</identifier> | ||
<values> | ||
<entry> | ||
<key> | ||
apiKey | ||
</key> | ||
<value> | ||
oauth:xxx | ||
</value> | ||
</entry> | ||
<entry> | ||
<key> | ||
anotherKey | ||
</key> | ||
<value> | ||
xyz | ||
</value> | ||
</entry> | ||
</values> | ||
</entry> | ||
</credentials> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/scala/org/codeoverflow/chatoverflow/config/ConfigEntry.scala
This file was deleted.
Oops, something went wrong.
63 changes: 28 additions & 35 deletions
63
src/main/scala/org/codeoverflow/chatoverflow/config/Configuration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
package org.codeoverflow.chatoverflow.config | ||
|
||
import java.io.File | ||
|
||
class Configuration(val configDirectoryPath: String) { | ||
val configFile = s"$configDirectoryPath/config.xml" | ||
|
||
var pluginInstances: Seq[PluginInstanceConfigEntry] = Seq[PluginInstanceConfigEntry]() | ||
|
||
def load(): Unit = { | ||
|
||
// Create file if non existent | ||
if (!new File(configFile).exists()) { | ||
save() | ||
} | ||
|
||
val xmlContent = xml.Utility.trim(xml.XML.loadFile(configFile)) | ||
|
||
pluginInstances = for (pluginInstance <- xmlContent \ "pluginInstances" \ "_") yield | ||
new PluginInstanceConfigEntry(pluginInstance) | ||
|
||
} | ||
|
||
def save(): Unit = { | ||
|
||
val xmlContent = | ||
<config> | ||
<pluginInstances> | ||
{for (pluginInstance <- pluginInstances) yield pluginInstance.toXml} | ||
</pluginInstances> | ||
</config> | ||
|
||
xml.XML.save(configFile, xmlContent) | ||
|
||
} | ||
|
||
} | ||
import scala.xml.{Elem, Node} | ||
|
||
trait Configuration { | ||
def toXml: xml.Elem | ||
} | ||
|
||
case class PluginInstance(pluginName: String, pluginAuthor: String, instanceName: String) extends Configuration { | ||
override def toXml: Elem = | ||
<pluginInstance> | ||
<pluginName> | ||
{pluginName} | ||
</pluginName> | ||
<pluginAuthor> | ||
{pluginAuthor} | ||
</pluginAuthor> | ||
<instanceName> | ||
{instanceName} | ||
</instanceName> | ||
</pluginInstance> | ||
|
||
def this(xmlNode: Node) = this( | ||
(xmlNode \ "pluginName").text, | ||
(xmlNode \ "pluginAuthor").text, | ||
(xmlNode \ "instanceName").text) | ||
|
||
} | ||
|
||
// Insert new config options here |
41 changes: 41 additions & 0 deletions
41
src/main/scala/org/codeoverflow/chatoverflow/config/ConfigurationService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.codeoverflow.chatoverflow.config | ||
|
||
import java.io.File | ||
|
||
class ConfigurationService(val configDirectoryPath: String) { | ||
val configFile = s"$configDirectoryPath/config.xml" | ||
|
||
var pluginInstances: Seq[PluginInstance] = Seq[PluginInstance]() | ||
|
||
def load(): Unit = { | ||
|
||
// Create file if non existent | ||
if (!new File(configFile).exists()) { | ||
save() | ||
} | ||
|
||
val xmlContent = xml.Utility.trim(xml.XML.loadFile(configFile)) | ||
|
||
pluginInstances = for (node <- xmlContent \ "pluginInstances" \ "_") yield | ||
new PluginInstance(node) | ||
|
||
// Insert new config options here | ||
|
||
} | ||
|
||
def save(): Unit = { | ||
|
||
val xmlContent = | ||
<config> | ||
<pluginInstances> | ||
{for (pluginInstance <- pluginInstances) yield pluginInstance.toXml} | ||
</pluginInstances> | ||
</config> | ||
|
||
// Insert new config options here | ||
|
||
xml.XML.save(configFile, xmlContent) | ||
|
||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/scala/org/codeoverflow/chatoverflow/config/CredentialsService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.codeoverflow.chatoverflow.config | ||
|
||
import java.io.File | ||
|
||
import org.codeoverflow.chatoverflow.service.Credentials | ||
|
||
import scala.collection.mutable | ||
|
||
class CredentialsService(val credentialsFilePath: String, password: Array[Char]) { | ||
private val credentials = mutable.Map[(String, String), Credentials]() | ||
|
||
def load(): Unit = { | ||
|
||
// Create file if non existent | ||
if (!new File(credentialsFilePath).exists()) { | ||
save() | ||
} | ||
|
||
// TODO: Decrypt | ||
val xmlContent = xml.Utility.trim(xml.XML.loadFile(credentialsFilePath)) | ||
|
||
credentials.clear() | ||
|
||
for (node <- xmlContent \ "entry") { | ||
val credentialsType = (node \ "type").text | ||
val credentialsIdentifier = (node \ "identifier").text | ||
|
||
val entry = new Credentials(credentialsIdentifier) | ||
entry.fromXML(node \ "values") | ||
|
||
credentials += (credentialsType, credentialsIdentifier) -> entry | ||
} | ||
} | ||
|
||
def save(): Unit = { | ||
|
||
val xmlContent = | ||
<credentials> | ||
{for (entry <- credentials.toList) yield { | ||
<entry> | ||
<type> | ||
{entry._1._1} | ||
</type> | ||
<identifier> | ||
{entry._1._2} | ||
</identifier>{entry._2.toXML} | ||
</entry> | ||
}} | ||
</credentials> | ||
|
||
// TODO: Encrypt | ||
xml.XML.save(credentialsFilePath, xmlContent) | ||
|
||
} | ||
|
||
def getCredentials(credentialsType: String, credentialsIdentifier: String): Option[Credentials] = | ||
credentials.get((credentialsType, credentialsIdentifier)) | ||
|
||
def addCredentials(credentialsType: String, credentials: Credentials): Unit = | ||
this.credentials += (credentialsType, credentials.credentialsIdentifier) -> credentials | ||
|
||
def removeCredentials(credentialsType: String, credentialsIdentifier: String): Unit = | ||
credentials -= ((credentialsType, credentialsIdentifier)) | ||
|
||
} |
Oops, something went wrong.