forked from mjeyarax/platform-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
175 lines (154 loc) · 4.49 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (C) 2019 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
package main
import (
"fmt"
p "intel/isecl/lib/platform-info/v3/platforminfo"
"intel/isecl/lib/common/v3/validation"
"os"
"encoding/json"
)
func main() {
// if no arguments were provided, just dump platform-info json to stdout
if len(os.Args[1:]) < 1 {
platformInfo, err := p.GetPlatformInfo()
if err != nil {
fmt.Printf("main: Error while fetching platform info: %s", err)
os.Exit(1)
}
// serialize to json
b, err := json.MarshalIndent(platformInfo, "", "\t")
if err != nil {
fmt.Printf("main: Error while serializing platform info: %s", err)
os.Exit(1)
}
fmt.Printf(string(b))
os.Exit(0)
}
inputValArr := os.Args[0:]
if valErr := validation.ValidateStrings(inputValArr); valErr != nil {
fmt.Println("Invalid string format")
os.Exit(1)
}
var methodName = os.Args[1]
switch methodName {
case "BiosName":
fmt.Println("Bios Name method called")
biosName, err := p.BiosName()
if err != nil {
fmt.Println("Error during retrieval of Bios Name: ", err)
os.Exit(1)
}
fmt.Println("Bios Name:\n", biosName)
case "BiosVersion":
fmt.Println("Bios Version method called")
biosVersion, err := p.BiosVersion()
if err != nil {
fmt.Println("Error during retrieval of Bios Version: ", err)
os.Exit(1)
}
fmt.Println("Bios Version:\n", biosVersion)
case "HardwareUUID":
fmt.Println("Hardware UUID method called")
hardwareUUID, err := p.HardwareUUID()
if err != nil {
fmt.Println("Error during retrieval of Hardware UUID: ", err)
os.Exit(1)
}
fmt.Println("Hardware UUID:\n", hardwareUUID)
case "OSName":
fmt.Println("OS Name method called")
osName, err := p.OSName()
if err != nil {
fmt.Println("Error during retrieval of OS Name: ", err)
os.Exit(1)
}
fmt.Println("OS Name:\n", osName)
case "OSVersion":
fmt.Println("OS Version method called")
osVersion, err := p.OSVersion()
if err != nil {
fmt.Println("Error during retrieval of OS Version: ", err)
os.Exit(1)
}
fmt.Println("OS Version:\n", osVersion)
case "ProcessorFlags":
fmt.Println("Processor Flags method called")
processorFlags, err := p.ProcessorFlags()
if err != nil {
fmt.Println("Error during retrieval of Processor Flags: ", err)
os.Exit(1)
}
fmt.Println("Processor Flags:\n", processorFlags)
case "ProcessorID":
fmt.Println("Processor ID method called")
processorID, err := p.ProcessorID()
if err != nil {
fmt.Println("Error during retrieval of Processor ID: ", err)
os.Exit(1)
}
fmt.Println("Processor Info:\n", processorID)
case "VMMName":
fmt.Println("VMM Name method called")
vmmName, err := p.VMMName()
if err != nil {
fmt.Println("Error during retrieval of VMM Name: ", err)
os.Exit(1)
}
fmt.Println("VMM Name:\n", vmmName)
case "VMMVersion":
fmt.Println("VMM Version method called")
vmmVersion, err := p.VMMVersion()
if err != nil {
fmt.Println("Error during retrieval of VMM Version: ", err)
os.Exit(1)
}
fmt.Println("VMM Version:\n", vmmVersion)
case "TPMVersion":
fmt.Println("TPM Version method called")
tpmVersion, err := p.TPMVersion()
if err != nil {
fmt.Println("Error during retrieval of TPM Version: ", err)
os.Exit(1)
}
fmt.Println("TPM Version:\n", tpmVersion)
case "HostName":
fmt.Println("Host Name method called")
hostName, err := p.HostName()
if err != nil {
fmt.Println("Error during retrieval of Host Name: ", err)
os.Exit(1)
}
fmt.Println("Host Name:\n", hostName)
case "NoOfSockets":
fmt.Println("Number of Sockets method called")
noOfSockets, err := p.NoOfSockets()
if err != nil {
fmt.Println("Error during retrieval of Number of Sockets: ", err)
os.Exit(1)
}
fmt.Println("Number of sockets:\n", noOfSockets)
case "TPMEnabled":
fmt.Println("TPM Enabled method called")
tpmEnabled, err := p.TPMEnabled()
if err != nil {
fmt.Println("Error during retrieval of status of TPM: ", err)
os.Exit(1)
}
fmt.Println("TPM Enabled:\n", tpmEnabled)
case "TXTEnabled":
fmt.Println("TXT Enabled method called")
txtEnabled, err := p.TXTEnabled()
if err != nil {
fmt.Println("Error during retrieval of status of TXT: ", err)
os.Exit(1)
}
fmt.Println("TXT Enabled:\n", txtEnabled)
default:
fmt.Println("Invalid method name mentioned.\nExpected values: BiosName, BiosVersion, HardwareUUID, " +
"OSName, OSVersion, ProcessorFlags, ProcessorInfo, VMMName, VMMVersion, TPMVersion, HostName, " +
"NoOfSockets, TPMEnabled, TXTEnabled")
}
}