soapclient

package module
v0.0.0-...-e987cdb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 14 Imported by: 0

README

SoapClient

SoapClient implements a simple SOAP client written in Go. It is not fully tested against the whole spec so it could not work for your use case. If that's the case please open an issue to keep track of it.

Usage

package main

import (
	"crypto/tls"
	"log"

	"github.com/dcu/soapclient"
)

func main() {
	cert, err := tls.LoadX509KeyPair("public.pem", "private.pem")
	if err != nil {
		panic(err)
	}

	client := soapclient.New("URL-HERE", soapclient.ClientOpts{
		Certificate: cert,
		Username:    "FIXME",
		Password:    "FIXME",
	})

	res, err := client.RawQuery(soapclient.Operation{
		Name: "operationName",
		Data: map[string]interface{}{
			"foo": map[string]interface{}{
				"bar":              "baz",
			},
		},
	})
	if err != nil {
		panic(err)
	}

	log.Println("Response:", string(res))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InOrder

func InOrder(keys ...string) func([]string)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(url string, opts ClientOpts) *Client

New creates a new Client. This client is supposed to be shared between threads

func (*Client) ListOperations

func (c *Client) ListOperations() ([]string, error)

ListOperations lists all supported operations by the service

func (*Client) Query

func (c *Client) Query(op Operation) (*etree.Document, error)

Query performs the query and returns a *etree.Document

func (*Client) RawQuery

func (c *Client) RawQuery(op Operation) ([]byte, error)

RawQuery does a query and returns the response

type ClientIface

type ClientIface interface {
	ListOperations() ([]string, error)
	RawQuery(op Operation) ([]byte, error)
	Query(op Operation) (*etree.Document, error)
}

ClientIface defines the interface for a SOAP Client. It makes mocking the client easier in your tests

type ClientOpts

type ClientOpts struct {
	// Certificate is the tls certificate. It is mandatory
	Certificate tls.Certificate

	// Username for the UsernameToken as defined in https://www.oasis-open.org/committees/download.php/13392/wss-v1.1-spec-pr-UsernameTokenProfile-01.htm#_Toc104276211
	Username string

	// Password for the UsernameToken as defined in https://www.oasis-open.org/committees/download.php/13392/wss-v1.1-spec-pr-UsernameTokenProfile-01.htm#_Toc104276211
	Password string

	// Debug enables the verbose mode which prints output of steps. Use it only for development
	Debug bool

	// V1 set the v1 namespace value for the operation
	V1 string
}

ClientOpts defines the possible options to pass to a client

type Operation

type Operation struct {
	// Name is the name of the operation. It is mandatory.
	Name string
	// Data receives the data/body of the request for the operation. Mandatory.
	Data map[string]any
	// Validate runs a validation of the signature before sending the request. Use it only for development
	Validate bool

	V1 string

	SortKeysFn func([]string)
}

Operation defines an operation for the SOAP service

func (Operation) MarshalXML

func (op Operation) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the Operation in XML. The keys of the operation Data are always sorted alphabetically.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL