Skip to content

Commit

Permalink
feat: adding external plugin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
panoramix360 committed Mar 14, 2024
1 parent fb1149a commit 90336a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import fetch from 'node-fetch'
global.fetch = fetch

export {default as MattermostContainer} from './mmcontainer'
export {default as RunContainer} from './plugincontainer'
export * from './plugincontainer'
export * from './utils'
13 changes: 12 additions & 1 deletion src/mmcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export default class MattermostContainer {
await this.container.exec(["mmctl", "--local", "plugin", "enable", pluginID])
}

installPluginFromUrl = async (pluginPath: string) => {
const client = await this.getAdminClient()
console.log(pluginPath)
const manifest = await client.installPluginFromUrl(pluginPath)
await this.container.exec(["mmctl", "--local", "plugin", "enable", manifest.id])
}

withEnv = (env: string, value: string): MattermostContainer => {
this.envs[env] = value
return this
Expand Down Expand Up @@ -181,7 +188,11 @@ export default class MattermostContainer {
await this.addUserToTeam(this.username, this.teamName)

for (const plugin of this.plugins) {
await this.installPlugin(plugin.path, plugin.id, plugin.config)
if (plugin.path.startsWith('http') || plugin.path.startsWith('https')) {
await this.installPluginFromUrl(plugin.path)
} else {
await this.installPlugin(plugin.path, plugin.id, plugin.config)
}
}

return this
Expand Down
29 changes: 24 additions & 5 deletions src/plugincontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ type PluginConfig = {
webhooksecret: string
}

type RunContainerConfig = {
type RunContainerWithExternalPluginParams = {
packageName: string
pluginPath: string
pluginConfig: PluginConfig
}

type RunContainerParams = {
packageName: string
distPath: string
pluginConfig: PluginConfig
}

const RunContainer = async ({ packageName, distPath, pluginConfig }: RunContainerConfig): Promise<MattermostContainer> => {
type RunContainerConfig = {
packageName: string
filename: string
pluginConfig: PluginConfig
}

export const RunContainerWithExternalPlugin = async ({ packageName, pluginPath, pluginConfig }: RunContainerWithExternalPluginParams): Promise<MattermostContainer> => {
return RunContainerInternal({ packageName, filename: pluginPath, pluginConfig })
}

export const RunContainer = async ({ packageName, distPath, pluginConfig }: RunContainerParams): Promise<MattermostContainer> => {
let filename = "";
fs.readdirSync(distPath).forEach(file => {
if (file.endsWith(".tar.gz")) {
Expand All @@ -30,6 +46,11 @@ const RunContainer = async ({ packageName, distPath, pluginConfig }: RunContaine
if (filename === "") {
throw("No tar.gz file found in dist folder")
}

return RunContainerInternal({ packageName, filename, pluginConfig })
}

const RunContainerInternal = async ({ packageName, filename, pluginConfig }: RunContainerConfig): Promise<MattermostContainer> => {
const mattermost = await new MattermostContainer()
.withPlugin(filename, packageName, pluginConfig)
.withEnv("MM_MSTEAMSSYNC_MOCK_CLIENT", "true")
Expand Down Expand Up @@ -71,6 +92,4 @@ const RunContainer = async ({ packageName, distPath, pluginConfig }: RunContaine
});

return mattermost;
}

export default RunContainer
}

0 comments on commit 90336a0

Please sign in to comment.