Documentation ¶
Overview ¶
Package requesthandling offers means to create signed requests for interfacing with CloudKit.
A Configuration is required to know the CloudKit container's properties, the KeyManager is required for signing requests.
Index ¶
- Constants
- type CloudkitRequestManager
- func (cm CloudkitRequestManager) GetRequest(operationPath string, body string) (*http.Request, error)
- func (cm *CloudkitRequestManager) HashedBody(body string) string
- func (cm CloudkitRequestManager) PostRequest(operationPath string, body string) (*http.Request, error)
- func (cm *CloudkitRequestManager) SignatureForMessage(message []byte) (signature []byte)
- type HTTPMethod
- type Payload
- type RequestConfig
- type RequestManager
Examples ¶
Constants ¶
const ( // GET represents HTTP GET GET HTTPMethod = "GET" // POST represents HTTP POST POST = "POST" // PUT represents HTTP PUT PUT = "PUT" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloudkitRequestManager ¶
type CloudkitRequestManager struct { Config RequestConfig // contains filtered or unexported fields }
CloudkitRequestManager is the concrete implementation of RequestManager
func New ¶
func New(config RequestConfig, keyManager keymanager.KeyManager) CloudkitRequestManager
New creates a new RequestManager
func (CloudkitRequestManager) GetRequest ¶
func (cm CloudkitRequestManager) GetRequest(operationPath string, body string) (*http.Request, error)
GetRequest is a convenience method for creating POST requests
func (*CloudkitRequestManager) HashedBody ¶
func (cm *CloudkitRequestManager) HashedBody(body string) string
HashedBody takes the given body, hashes it, using sha256 and returns the base64 encoded result
func (CloudkitRequestManager) PostRequest ¶
func (cm CloudkitRequestManager) PostRequest(operationPath string, body string) (*http.Request, error)
PostRequest is a convenience method for creating POST requests
func (*CloudkitRequestManager) SignatureForMessage ¶
func (cm *CloudkitRequestManager) SignatureForMessage(message []byte) (signature []byte)
SignatureForMessage returns the signature for the given message
type Payload ¶
type Payload struct {
Fields map[string]interface{}
}
Payload represents the payload to send with a request
type RequestConfig ¶
RequestConfig is used to initialise RequestManagers. It specifies the Cloudkit API version and container ID to use for requests
func NewRequestConfig ¶
func NewRequestConfig(version string, containerID string, database string) RequestConfig
NewRequestConfig creates a fresh config with the given version and container ID
type RequestManager ¶
type RequestManager interface { PostRequest(string, string) (*http.Request, error) GetRequest(string, string) (*http.Request, error) }
The RequestManager interface exposes methods for creating requests
Example ¶
This Example shows how to create a request manager.
A request manager requires a keymanager for handling authentication as well as a valid configuration.
keyManager := mocks.MockKeyManager{} config := RequestConfig{Version: "1", ContainerID: "iCloud.com.mycontainer", Database: "public"} requestManager := New(config, &keyManager) fmt.Printf("Container:%s, Version:%s, Database:%s", requestManager.Config.ContainerID, requestManager.Config.Version, requestManager.Config.Database)
Output: Container:iCloud.com.mycontainer, Version:1, Database:public