-
Notifications
You must be signed in to change notification settings - Fork 6
/
auth_plugin_request.go
67 lines (57 loc) · 1.74 KB
/
auth_plugin_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package message
import (
"encoding/xml"
"github.com/cyverse/go-irodsclient/irods/common"
"golang.org/x/xerrors"
)
// IRODSMessageAuthPluginRequest stores auth plugin request
type IRODSMessageAuthPluginRequest struct {
XMLName xml.Name `xml:"authPlugReqInp_PI"`
AuthScheme string `xml:"auth_scheme_"`
Context string `xml:"context_"`
}
// NewIRODSMessageAuthPluginRequest creates a IRODSMessageAuthPluginRequest
func NewIRODSMessageAuthPluginRequest(authScheme string, context string) *IRODSMessageAuthPluginRequest {
return &IRODSMessageAuthPluginRequest{
AuthScheme: authScheme,
Context: context,
}
}
// GetBytes returns byte array
func (msg *IRODSMessageAuthPluginRequest) GetBytes() ([]byte, error) {
xmlBytes, err := xml.Marshal(msg)
if err != nil {
return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err)
}
return xmlBytes, nil
}
// FromBytes returns struct from bytes
func (msg *IRODSMessageAuthPluginRequest) FromBytes(bytes []byte) error {
err := xml.Unmarshal(bytes, msg)
if err != nil {
return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err)
}
return nil
}
// GetMessage builds a message
func (msg *IRODSMessageAuthPluginRequest) GetMessage() (*IRODSMessage, error) {
bytes, err := msg.GetBytes()
if err != nil {
return nil, xerrors.Errorf("failed to get bytes from irods message: %w", err)
}
msgBody := IRODSMessageBody{
Type: RODS_MESSAGE_API_REQ_TYPE,
Message: bytes,
Error: nil,
Bs: nil,
IntInfo: int32(common.AUTH_PLUG_REQ_AN),
}
msgHeader, err := msgBody.BuildHeader()
if err != nil {
return nil, xerrors.Errorf("failed to build header from irods message: %w", err)
}
return &IRODSMessage{
Header: msgHeader,
Body: &msgBody,
}, nil
}