credential added
This commit is contained in:
parent
cfa3f94692
commit
7b804b2da2
44
config/credential/Credential.go
Normal file
44
config/credential/Credential.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package credential
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"git.loafle.net/overflow/model/meta"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Credential struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type CredentialMap map[string]*Credential
|
||||||
|
|
||||||
|
func (m *CredentialMap) UnmarshalJSON(data []byte) error {
|
||||||
|
credentials := make(map[string]json.RawMessage)
|
||||||
|
err := json.Unmarshal(data, &credentials)
|
||||||
|
if nil != err {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(CredentialMap)
|
||||||
|
for k, v := range credentials {
|
||||||
|
var i interface{}
|
||||||
|
|
||||||
|
switch meta.ToMetaCredentialTypeEnum(&meta.MetaCredentialType{Key: k}) {
|
||||||
|
case meta.MetaCredentialTypeEnumSNMP:
|
||||||
|
i = &SNMPCredential{}
|
||||||
|
case meta.MetaCredentialTypeEnumWindows:
|
||||||
|
i = &WindowsCredential{}
|
||||||
|
default:
|
||||||
|
return errors.New("Unrecognized Credential")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := json.Unmarshal(v, i)
|
||||||
|
if nil != err {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
result[k] = i.(*Credential)
|
||||||
|
}
|
||||||
|
*m = result
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
17
config/credential/SNMPCredential.go
Normal file
17
config/credential/SNMPCredential.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package credential
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type SNMPCredential struct {
|
||||||
|
Credential
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
Community string `json:"community,omitempty"`
|
||||||
|
AuthenticationType string `json:"authenticationType,omitempty"`
|
||||||
|
User string `json:"user,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
EncryptionType string `json:"encryptionType,omitempty"`
|
||||||
|
DataEncryptionKey string `json:"dataEncryptionKey,omitempty"`
|
||||||
|
ContextName string `json:"contextName,omitempty"`
|
||||||
|
Port json.Number `json:"port,Number,omitempty"`
|
||||||
|
Timeout json.Number `json:"timeout,Number,omitempty"`
|
||||||
|
}
|
15
config/credential/UnixCredential.go
Normal file
15
config/credential/UnixCredential.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package credential
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnixCredential struct {
|
||||||
|
Credential
|
||||||
|
User string `json:"user,omitempty"`
|
||||||
|
LoginType string `json:"loginType,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
PrivateKey string `json:"privateKey,omitempty"`
|
||||||
|
SSHPort json.Number `json:"sshPort,Number,omitempty"`
|
||||||
|
SSHRightsElevationType string `json:"sshRightsElevationType,omitempty"`
|
||||||
|
TargetUser string `json:"targetUser,omitempty"`
|
||||||
|
TargetUserPassword string `json:"targetUserPassword,omitempty"`
|
||||||
|
}
|
8
config/credential/WindowsCredential.go
Normal file
8
config/credential/WindowsCredential.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package credential
|
||||||
|
|
||||||
|
type WindowsCredential struct {
|
||||||
|
Credential
|
||||||
|
DomainName string `json:"domainName,omitempty"`
|
||||||
|
User string `json:"user,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
|
}
|
9
discovery/DiscoveryConfig.go
Normal file
9
discovery/DiscoveryConfig.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package discovery
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.loafle.net/overflow/model/config/credential"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DiscoveryConfig struct {
|
||||||
|
Credentials credential.CredentialMap `json:"credentials,omitempty"`
|
||||||
|
}
|
71
meta/MetaCredentialType.go
Normal file
71
meta/MetaCredentialType.go
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
package meta
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.loafle.net/overflow/model/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MetaCredentialType struct {
|
||||||
|
ID json.Number `json:"id,Number,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Key string `json:"key,omitempty"`
|
||||||
|
CreateDate *util.Timestamp `json:"createDate,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MetaCredentialTypeEnum int
|
||||||
|
|
||||||
|
const (
|
||||||
|
MetaCredentialTypeEnumNONE MetaCredentialTypeEnum = iota + 1
|
||||||
|
MetaCredentialTypeEnumWindows
|
||||||
|
MetaCredentialTypeEnumLinux
|
||||||
|
MetaCredentialTypeEnumSolaris
|
||||||
|
MetaCredentialTypeEnumMacOS
|
||||||
|
MetaCredentialTypeEnumVMWare
|
||||||
|
MetaCredentialTypeEnumXenServer
|
||||||
|
MetaCredentialTypeEnumSNMP
|
||||||
|
MetaCredentialTypeEnumDatabase
|
||||||
|
MetaCredentialTypeEnumAmazoneCloudWatch
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
metaCredentialTypeEnumID = map[MetaCredentialTypeEnum]string{
|
||||||
|
MetaCredentialTypeEnumNONE: "NONE",
|
||||||
|
MetaCredentialTypeEnumWindows: "WINDOWS",
|
||||||
|
MetaCredentialTypeEnumLinux: "LINUX",
|
||||||
|
MetaCredentialTypeEnumSolaris: "SOLARIS",
|
||||||
|
MetaCredentialTypeEnumMacOS: "MACOS",
|
||||||
|
MetaCredentialTypeEnumVMWare: "VMWARE",
|
||||||
|
MetaCredentialTypeEnumXenServer: "XENSERVER",
|
||||||
|
MetaCredentialTypeEnumSNMP: "SNMP",
|
||||||
|
MetaCredentialTypeEnumDatabase: "DATABASE",
|
||||||
|
MetaCredentialTypeEnumAmazoneCloudWatch: "AMAZON_CLOUDWATCH",
|
||||||
|
}
|
||||||
|
|
||||||
|
metaCredentialTypeEnumKey = map[string]MetaCredentialTypeEnum{
|
||||||
|
"NONE": MetaCredentialTypeEnumNONE,
|
||||||
|
"WINDOWS": MetaCredentialTypeEnumWindows,
|
||||||
|
"LINUX": MetaCredentialTypeEnumLinux,
|
||||||
|
"SOLARIS": MetaCredentialTypeEnumSolaris,
|
||||||
|
"MACOS": MetaCredentialTypeEnumMacOS,
|
||||||
|
"VMWARE": MetaCredentialTypeEnumVMWare,
|
||||||
|
"XENSERVER": MetaCredentialTypeEnumXenServer,
|
||||||
|
"SNMP": MetaCredentialTypeEnumSNMP,
|
||||||
|
"DATABASE": MetaCredentialTypeEnumDatabase,
|
||||||
|
"AMAZON_CLOUDWATCH": MetaCredentialTypeEnumAmazoneCloudWatch,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e MetaCredentialTypeEnum) String() string {
|
||||||
|
return metaCredentialTypeEnumID[e]
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToMetaCredentialTypeEnum(v *MetaCredentialType) MetaCredentialTypeEnum {
|
||||||
|
return metaCredentialTypeEnumKey[v.Key]
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToMetaCredentialType(v MetaCredentialTypeEnum) *MetaCredentialType {
|
||||||
|
return &MetaCredentialType{
|
||||||
|
Key: metaCredentialTypeEnumID[v],
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user