diff --git a/config/credential/Credential.go b/config/credential/Credential.go new file mode 100644 index 0000000..b09c7c4 --- /dev/null +++ b/config/credential/Credential.go @@ -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 +} diff --git a/config/credential/SNMPCredential.go b/config/credential/SNMPCredential.go new file mode 100644 index 0000000..ce42ae5 --- /dev/null +++ b/config/credential/SNMPCredential.go @@ -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"` +} diff --git a/config/credential/UnixCredential.go b/config/credential/UnixCredential.go new file mode 100644 index 0000000..85e6a77 --- /dev/null +++ b/config/credential/UnixCredential.go @@ -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"` +} diff --git a/config/credential/WindowsCredential.go b/config/credential/WindowsCredential.go new file mode 100644 index 0000000..81bac02 --- /dev/null +++ b/config/credential/WindowsCredential.go @@ -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"` +} diff --git a/discovery/DiscoveryConfig.go b/discovery/DiscoveryConfig.go new file mode 100644 index 0000000..e24517b --- /dev/null +++ b/discovery/DiscoveryConfig.go @@ -0,0 +1,9 @@ +package discovery + +import ( + "git.loafle.net/overflow/model/config/credential" +) + +type DiscoveryConfig struct { + Credentials credential.CredentialMap `json:"credentials,omitempty"` +} diff --git a/meta/MetaCredentialType.go b/meta/MetaCredentialType.go new file mode 100644 index 0000000..8bd9b7e --- /dev/null +++ b/meta/MetaCredentialType.go @@ -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], + } +}