github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/build/info.go (about) 1 // Copyright (c) 2019-2022, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package build 6 7 import ( 8 "sort" 9 "strings" 10 "sync" 11 ) 12 13 type Info struct{} 14 15 var mu = &sync.Mutex{} 16 17 func (i *Info) Version() string { 18 mu.Lock() 19 defer mu.Unlock() 20 21 return Version 22 } 23 24 func (i *Info) SHA() string { 25 mu.Lock() 26 defer mu.Unlock() 27 28 return SHA 29 } 30 31 func (i *Info) BuildDate() string { 32 mu.Lock() 33 defer mu.Unlock() 34 35 return BuildDate 36 } 37 38 func (i *Info) License() string { 39 mu.Lock() 40 defer mu.Unlock() 41 42 return License 43 } 44 45 func (i *Info) ClientIdentitySuffix() string { 46 mu.Lock() 47 defer mu.Unlock() 48 49 return ClientIdentitySuffix 50 } 51 52 func (i *Info) DefaultCollectives() []string { 53 mu.Lock() 54 defer mu.Unlock() 55 56 collectives := strings.Split(DefaultCollectives, ",") 57 for i, c := range collectives { 58 collectives[i] = strings.TrimSpace(c) 59 } 60 61 return collectives 62 } 63 64 func (i *Info) HasTLS() bool { 65 mu.Lock() 66 defer mu.Unlock() 67 68 return HasTLS() 69 } 70 71 func (i *Info) MaxBrokerClients() int { 72 mu.Lock() 73 defer mu.Unlock() 74 75 return MaxBrokerClients() 76 } 77 78 func (i *Info) ProvisionSecurity() bool { 79 mu.Lock() 80 defer mu.Unlock() 81 82 return ProvisionSecurity() 83 } 84 85 // SupportsProvisioning determines if the build supports provisioning, typically that comes down to if a Provisioning Token is set either at build time or through the JWT 86 func (i *Info) SupportsProvisioning() bool { 87 return i.ProvisionToken() != "" 88 } 89 90 func (i *Info) ProvisionDefault() bool { 91 mu.Lock() 92 defer mu.Unlock() 93 94 return ProvisionDefault() 95 } 96 97 func (i *Info) ProvisionBrokerURLs() string { 98 mu.Lock() 99 defer mu.Unlock() 100 101 return ProvisionBrokerURLs 102 } 103 104 func (i *Info) ProvisionBrokerSRVDomain() string { 105 mu.Lock() 106 defer mu.Unlock() 107 108 return ProvisionBrokerSRVDomain 109 } 110 111 func (i *Info) ProvisionAgent() bool { 112 mu.Lock() 113 defer mu.Unlock() 114 115 return ProvisionAgent == "true" 116 } 117 118 func (i *Info) ProvisionRegistrationData() string { 119 mu.Lock() 120 defer mu.Unlock() 121 122 return ProvisionRegistrationData 123 } 124 125 func (i *Info) ProvisionFacts() string { 126 mu.Lock() 127 defer mu.Unlock() 128 129 return ProvisionFacts 130 } 131 132 func (i *Info) ProvisionToken() string { 133 mu.Lock() 134 defer mu.Unlock() 135 136 return ProvisionToken 137 } 138 139 func (i *Info) ProvisionJWTFile() string { 140 mu.Lock() 141 defer mu.Unlock() 142 143 return ProvisionJWTFile 144 } 145 146 func (i *Info) ProvisionStatusFile() string { 147 mu.Lock() 148 defer mu.Unlock() 149 150 return ProvisionStatusFile 151 } 152 153 func (i *Info) ProvisionUsingVersion2() bool { 154 mu.Lock() 155 defer mu.Unlock() 156 157 return ProvisioningUsesProtocolV2 == "true" 158 } 159 160 func (i *Info) ProvisionAllowServerUpdate() bool { 161 mu.Lock() 162 defer mu.Unlock() 163 164 return ProvisionAllowServerUpdate == "true" 165 } 166 167 func (i *Info) AgentProviders() []string { 168 mu.Lock() 169 defer mu.Unlock() 170 171 return AgentProviders 172 } 173 174 func (i *Info) RegisterAgentProvider(p string) { 175 mu.Lock() 176 defer mu.Unlock() 177 178 AgentProviders = append(AgentProviders, p) 179 sort.Strings(AgentProviders) 180 } 181 182 func (i *Info) Machines() []string { 183 mu.Lock() 184 defer mu.Unlock() 185 186 return Machines 187 } 188 189 func (i *Info) MachineWatchers() []string { 190 mu.Lock() 191 defer mu.Unlock() 192 193 return MachineWatchers 194 } 195 196 func (i *Info) RegisterMachineWatcher(p string) { 197 mu.Lock() 198 defer mu.Unlock() 199 200 MachineWatchers = append(MachineWatchers, p) 201 sort.Strings(MachineWatchers) 202 } 203 204 func (i *Info) RegisterMachine(p string) { 205 mu.Lock() 206 defer mu.Unlock() 207 208 Machines = append(Machines, p) 209 sort.Strings(Machines) 210 } 211 212 func (i *Info) RegisterDataProvider(p string) { 213 mu.Lock() 214 defer mu.Unlock() 215 216 DataProviders = append(DataProviders, p) 217 sort.Strings(DataProviders) 218 } 219 220 func (i *Info) DataProviders() []string { 221 mu.Lock() 222 defer mu.Unlock() 223 224 return DataProviders 225 } 226 227 func (i *Info) SetProvisionBrokerURLs(u string) { 228 mu.Lock() 229 defer mu.Unlock() 230 231 ProvisionBrokerURLs = u 232 } 233 234 func (i *Info) SetProvisioningBrokerUsername(u string) { 235 mu.Lock() 236 defer mu.Unlock() 237 238 ProvisioningBrokerUsername = u 239 } 240 241 func (i *Info) SetProvisioningBrokerPassword(p string) { 242 mu.Lock() 243 defer mu.Unlock() 244 245 ProvisioningBrokerPassword = p 246 } 247 248 func (i *Info) ProvisioningBrokerUsername() string { 249 mu.Lock() 250 defer mu.Unlock() 251 252 return ProvisioningBrokerUsername 253 } 254 255 func (i *Info) ProvisioningBrokerPassword() string { 256 mu.Lock() 257 defer mu.Unlock() 258 259 return ProvisioningBrokerPassword 260 } 261 262 func (i *Info) SetProvisionJWTFile(t string) { 263 mu.Lock() 264 defer mu.Unlock() 265 266 ProvisionJWTFile = t 267 } 268 269 func (i *Info) SetProvisionToken(t string) { 270 mu.Lock() 271 defer mu.Unlock() 272 273 ProvisionToken = t 274 } 275 276 func (i *Info) SetProvisionUsingVersion2(v2 bool) { 277 mu.Lock() 278 defer mu.Unlock() 279 280 if v2 { 281 ProvisioningUsesProtocolV2 = "true" 282 } else { 283 ProvisioningUsesProtocolV2 = "false" 284 } 285 } 286 287 func (i *Info) SetProvisionAllowServerUpdate(allow bool) { 288 mu.Lock() 289 defer mu.Unlock() 290 291 if allow { 292 ProvisionAllowServerUpdate = "true" 293 } else { 294 ProvisionAllowServerUpdate = "false" 295 } 296 } 297 298 func (i *Info) SetProvisionBrokerSRVDomain(d string) { 299 mu.Lock() 300 defer mu.Unlock() 301 302 ProvisionBrokerSRVDomain = d 303 } 304 305 func (i *Info) EnableProvisionModeAsDefault() { 306 mu.Lock() 307 defer mu.Unlock() 308 309 ProvisionModeDefault = "true" 310 } 311 312 func (i *Info) DisableProvisionModeAsDefault() { 313 mu.Lock() 314 defer mu.Unlock() 315 316 ProvisionModeDefault = "false" 317 } 318 319 func (i *Info) EnableProvisionModeSecurity() { 320 mu.Lock() 321 defer mu.Unlock() 322 323 ProvisionSecure = "true" 324 } 325 326 func (i *Info) DisableProvisionModeSecurity() { 327 mu.Lock() 328 defer mu.Unlock() 329 330 ProvisionSecure = "false" 331 } 332 333 func (i *Info) SetProvisionFacts(f string) { 334 mu.Lock() 335 defer mu.Unlock() 336 337 ProvisionFacts = f 338 } 339 340 func (i *Info) SetProvisionRegistrationData(f string) { 341 mu.Lock() 342 defer mu.Unlock() 343 344 ProvisionRegistrationData = f 345 }