Skip to content

totmicro/mops-plugin-sdk-old

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MOPS Plugin SDK

The official Software Development Kit (SDK) for creating MOPS plugins.

Overview

The MOPS Plugin SDK provides a stable, version-controlled interface for developing plugins that integrate with the MOPS (Micro Operations Platform System). This SDK ensures compatibility across MOPS versions and provides a consistent development experience.

Features

  • 🔌 Plugin Interface: Standardized plugin interface for MOPS integration
  • 🎯 CLI Commands: Support for command-line interface commands
  • 🖥️ Interactive Functions: UI-based interactive plugin operations
  • 📊 Dynamic Providers: Context-aware menu and action providers
  • 🔄 Version Compatibility: Automatic compatibility checking
  • 📝 Type Safety: Comprehensive type definitions and interfaces

Installation

go mod init your-plugin-name
go get github.com/totmicro/mops-plugin-sdk@latest

Quick Start

Basic Plugin Structure

package main

import (
    "context"
    "github.com/totmicro/mops-plugin-sdk/interfaces"
    "github.com/totmicro/mops-plugin-sdk/types"
)

type MyPlugin struct {
    config *types.PluginConfig
}

// Plugin Interface Implementation
func (p *MyPlugin) GetName() string {
    return "my-plugin"
}

func (p *MyPlugin) GetVersion() string {
    return "1.0.0"
}

func (p *MyPlugin) GetDescription() string {
    return "My awesome MOPS plugin"
}

func (p *MyPlugin) GetAPIVersion() types.APIVersion {
    return interfaces.CurrentSDKVersion
}

func (p *MyPlugin) Initialize(config *types.PluginConfig) error {
    p.config = config
    return nil
}

func (p *MyPlugin) GetProviders() []interfaces.Provider {
    return []interfaces.Provider{}
}

func (p *MyPlugin) GetExecutors() []interfaces.ActionExecutor {
    return []interfaces.ActionExecutor{}
}

func (p *MyPlugin) Cleanup() error {
    return nil
}

// CLI Commands (optional)
func (p *MyPlugin) GetCLICommands() []interfaces.CLICommand {
    return []interfaces.CLICommand{
        {
            Name:        "my-plugin-hello",
            Description: "Say hello from my plugin",
            Usage:       "mops my-plugin-hello [name]",
            Handler:     p.helloCLI,
        },
    }
}

func (p *MyPlugin) helloCLI(args []string) error {
    name := "World"
    if len(args) > 0 {
        name = args[0]
    }
    fmt.Printf("Hello %s from my plugin!\n", name)
    return nil
}

// Interactive Functions (optional)
func (p *MyPlugin) GetInteractiveFunctions() []interfaces.InteractiveFunction {
    return []interfaces.InteractiveFunction{
        {
            Name:        "my-plugin-interactive-hello",
            Description: "Interactive hello",
            Handler:     p.helloInteractive,
        },
    }
}

func (p *MyPlugin) helloInteractive(ctx context.Context, outputChan chan<- string, inputChan <-chan string, params map[string]interface{}) error {
    outputChan <- "Hello from interactive mode!"
    return nil
}

// Required export for MOPS
func GetPlugin() interfaces.Plugin {
    return &MyPlugin{}
}

Building Your Plugin

go build -buildmode=plugin -o my-plugin.so main.go

SDK Interfaces

Core Interfaces

  • Plugin: Main plugin interface with lifecycle methods
  • CLIProvider: For plugins that provide CLI commands
  • InteractiveProvider: For plugins with UI interactions
  • DynamicProvider: For context-aware menu generation
  • FullCapabilityPlugin: Combines all interface capabilities

Provider Types

  • Provider: Menu entry generation
  • ActionExecutor: Action execution handling
  • DynamicProvider: Runtime menu generation

API Compatibility

The SDK uses semantic versioning for API compatibility:

  • Major version: Breaking changes to the plugin interface
  • Minor version: New features, backward compatible
  • Patch version: Bug fixes, backward compatible

Current API Version: 1.0.0

Examples

Check out example plugins in the main MOPS repository:

  • sdk-plugins/example-sdk-plugin/ - Basic plugin example
  • sdk-plugins/saml2aws-sdk/ - Advanced plugin with CLI and UI
  • sdk-plugins/samples-sdk/ - Interactive demonstrations

Development Guidelines

Plugin Architecture

For maintainable plugins, follow the recommended structure:

your-plugin/
├── main.go          # Plugin interface implementation
├── core.go          # Shared business logic
├── go.mod           # Go module definition
└── README.md        # Plugin documentation

Shared Business Logic

Separate your business logic from plugin interfaces:

// core.go - Shared business logic
type MyService struct{}

func (s *MyService) DoSomething() error {
    // Business logic here
    return nil
}

// main.go - Plugin interfaces
func (p *MyPlugin) cliCommand(args []string) error {
    service := &MyService{}
    return service.DoSomething()
}

func (p *MyPlugin) interactiveFunction(ctx context.Context, outputChan chan<- string, inputChan <-chan string, params map[string]interface{}) error {
    service := &MyService{}
    return service.DoSomething()
}

Contributing

This SDK is part of the MOPS project. For contributions and issues, please refer to the main MOPS repository.

License

This project is licensed under the same terms as the main MOPS project.


MOPS Plugin SDK - Build powerful, compatible plugins for the MOPS platform.

About

Official SDK for MOPS plugin development

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages