github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/models/models.go (about) 1 package models 2 3 import ( 4 "github.com/jault3/mow.cli" 5 ) 6 7 // AssociatedEnvV1 holds information about an associated environment 8 type AssociatedEnvV1 struct { 9 EnvironmentID string `json:"environmentId"` 10 ServiceID string `json:"serviceId"` 11 Directory string `json:"dir"` 12 Name string `json:"name"` 13 Pod string `json:"pod"` 14 OrgID string `json:"organizationId"` 15 } 16 17 // AssociatedEnvV2 holds information about an associated environment 18 type AssociatedEnvV2 struct { 19 EnvironmentID string `json:"environmentId"` 20 Name string `json:"name"` 21 Pod string `json:"pod"` 22 OrgID string `json:"organizationId"` 23 } 24 25 type Cert struct { 26 Name string `json:"name"` 27 PubKey string `json:"sslCertFile"` 28 PrivKey string `json:"sslPKFile"` 29 30 Service string `json:"service,omitempty"` 31 PubKeyID int `json:"sslCertFileId,omitempty"` 32 PrivKeyID int `json:"sslPKFileId,omitempty"` 33 Restricted bool `json:"restricted,omitempty"` 34 LetsEncrypt LetsEncryptStatus `json:"letsEncrypt,omitempty"` 35 } 36 37 type Command struct { 38 Name string 39 ShortHelp string 40 LongHelp string 41 CmdFunc func(settings *Settings) func(cmd *cli.Cmd) 42 } 43 44 // ContentDigest contains hash data for an image 45 type ContentDigest struct { 46 HashType string 47 Hash string 48 Size int64 49 } 50 51 // ConsoleCredentials hold the keys necessary for connecting to a console service 52 type ConsoleCredentials struct { 53 URL string `json:"url"` 54 Token string `json:"token"` 55 } 56 57 type CPUUsage struct { 58 JobID string `json:"job"` 59 CorePercent float64 `json:"core_percent"` 60 TS int `json:"ts"` 61 } 62 63 // DeployKey is an ssh key belonging to an environment's code service 64 type DeployKey struct { 65 Name string `json:"name"` 66 Key string `json:"value"` 67 Type string `json:"type"` 68 } 69 70 // EncryptionStore holds the values for encryption on backup/import jobs 71 type EncryptionStore struct { 72 Key string `json:"key"` 73 KeyLogs string `json:"keyLogs"` 74 KeyInternalLogs string `json:"keyInternalLogs"` 75 IV string `json:"iv"` 76 } 77 78 // Environment environment 79 type Environment struct { 80 ID string `json:"id,omitempty"` 81 Name string `json:"name"` 82 Pod string `json:"pod,omitempty"` 83 Namespace string `json:"namespace,omitempty"` 84 OrgID string `json:"organizationId"` 85 } 86 87 // Error is a wrapper around an array of errors from the API 88 type Error struct { 89 Title string `json:"title"` 90 Description string `json:"description"` 91 Code int `json:"code"` 92 } 93 94 // ACL support 95 type GroupWrapper struct { 96 Groups *[]Group `json:"groups"` 97 } 98 99 type Group struct { 100 Name string `json:"name"` 101 Acls []string `json:"acls"` 102 Protected bool `json:"protected"` 103 Members *[]GroupMember `json:"members"` 104 } 105 106 type GroupMember struct { 107 ID string `json:"id"` 108 Email string `json:"email"` 109 } 110 111 // Hits contain arrays of log data 112 type Hits struct { 113 Total int64 `json:"total"` 114 MaxScore float64 `json:"max_score"` 115 Hits *[]LogHits `json:"hits"` 116 } 117 118 type HTTPManager interface { 119 GetHeaders(sessionToken, version, pod, userID string) map[string][]string 120 ConvertResp(b []byte, statusCode int, s interface{}) error 121 ConvertError(b []byte, statuseCode int) (*Error, error) 122 Get(body []byte, url string, headers map[string][]string) ([]byte, int, error) 123 Post(body []byte, url string, headers map[string][]string) ([]byte, int, error) 124 PostFile(filepath string, url string, headers map[string][]string) ([]byte, int, error) 125 PutFile(filepath string, url string, headers map[string][]string) ([]byte, int, error) 126 Put(body []byte, url string, headers map[string][]string) ([]byte, int, error) 127 Delete(body []byte, url string, headers map[string][]string) ([]byte, int, error) 128 } 129 130 // Image contains data about an image 131 type Image struct { 132 Name string 133 Tag string 134 Digest *ContentDigest 135 } 136 137 // Invite represents an invitation to an organization 138 type Invite struct { 139 ID string `json:"id"` 140 OrgID string `json:"orgID"` 141 SenderID string `json:"senderID"` 142 RoleID int `json:"roleID"` 143 Email string `json:"email"` 144 Consumed bool `json:"consumed"` 145 Revoked bool `json:"revoked"` 146 } 147 148 // LetsEncryptStatus code 149 type LetsEncryptStatus int 150 151 const ( 152 // NormalCert is a non-let's encrypt cert 153 NormalCert LetsEncryptStatus = iota 154 // Waiting verification and issuance 155 Waiting 156 // Valid certificate that has already been issued 157 Valid 158 ) 159 160 func (l LetsEncryptStatus) String() string { 161 switch l { 162 case NormalCert: 163 return "This is not a Let's Encrypt certificate" 164 case Waiting: 165 return "Awaiting the certificate to be issued by Let's Encrypt" 166 case Valid: 167 return "Certificate successfully issued" 168 } 169 return "" 170 } 171 172 // LogHits contain ordering data for logs 173 type LogHits struct { 174 Index string `json:"_index"` 175 Type string `json:"_type"` 176 ID string `json:"_id"` 177 Score float64 `json:"_score"` 178 Fields map[string][]string `json:"fields"` 179 Source map[string]string `json:"_source"` 180 } 181 182 // Login is used for making an authentication request 183 type Login struct { 184 Identifier string `json:"identifier"` 185 Password string `json:"password"` 186 } 187 188 // Logs hold the log values from a successful LogQuery 189 type Logs struct { 190 Hits *Hits `json:"hits"` 191 } 192 193 type Maintenance struct { 194 UpstreamID string `json:"upstream"` 195 CreatedAt string `json:"createdAt"` 196 } 197 198 type MemoryUsage struct { 199 JobID string `json:"job"` 200 Total float64 `json:"total"` 201 AVG float64 `json:"ave"` 202 Max float64 `json:"max"` 203 Min float64 `json:"min"` 204 TS int `json:"ts"` 205 } 206 207 // Metrics holds all metrics data for an entire environment or a single service 208 type Metrics struct { 209 ServiceName string `json:"serviceName"` 210 ServiceType string `json:"serviceType"` 211 ServiceID string `json:"serviceId"` 212 ServiceLabel string `json:"serviceLabel"` 213 Size ServiceSize `json:"size"` 214 Data *MetricsData `json:"metrics"` 215 } 216 217 // MetricsData is a container for each type of metrics: network, memory, etc. 218 type MetricsData struct { 219 CPUUsage *[]CPUUsage `json:"cpu.usage"` 220 MemoryUsage *[]MemoryUsage `json:"memory.usage"` 221 NetworkUsage *[]NetworkUsage `json:"network.usage"` 222 } 223 224 type NetworkUsage struct { 225 JobID string `json:"job"` 226 RXDropped float64 `json:"rx_dropped"` 227 RXErrors float64 `json:"rx_errors"` 228 RXKB float64 `json:"rx_kb"` 229 RXPackets float64 `json:"rx_packets"` 230 TXDropped float64 `json:"tx_dropped"` 231 TXErrors float64 `json:"tx_errors"` 232 TXKB float64 `json:"tx_kb"` 233 TXPackets float64 `json:"tx_packets"` 234 TS int `json:"ts"` 235 } 236 237 type NotaryRepo struct { 238 RootTrustDir string 239 ImageName string 240 NotaryServer string 241 User *User 242 } 243 244 type Org struct { 245 ID string `json:"id"` 246 Name string `json:"name"` 247 Description string `json:"description"` 248 } 249 250 // OrgUser users who have access to an org 251 type OrgUser struct { 252 ID string `json:"id"` 253 Name string `json:"name"` 254 Email string `json:"email"` 255 RoleID int `json:"roleID"` 256 } 257 258 // Payload is the payload of a job 259 type Payload struct { 260 Environment map[string]string `json:"environment"` 261 } 262 263 // Pod is a pod returned from the pod router 264 type Pod struct { 265 Name string `json:"name"` 266 } 267 268 // Job job 269 type Job struct { 270 ID string `json:"id"` 271 Type string `json:"type"` 272 Status string `json:"status,omitempty"` 273 Backup *EncryptionStore `json:"backup,omitempty"` 274 Restore *EncryptionStore `json:"restore,omitempty"` 275 CreatedAt string `json:"created_at"` 276 MetricsData *[]MetricsData `json:"metrics"` 277 Spec *Spec `json:"spec"` 278 Target string `json:"target,omitempty"` 279 IsSnapshotBackup *bool `json:"isSnapshotBackup,omitempty"` 280 } 281 282 // PodWrapper pod wrapper 283 type PodWrapper struct { 284 Pods *[]Pod `json:"pods"` 285 } 286 287 type PostInvite struct { 288 Email string `json:"email"` 289 Role int `json:"role"` 290 LinkTemplate string `json:"linkTemplate"` 291 } 292 293 type Release struct { 294 Name string `json:"release,omitempty"` 295 CreatedAt string `json:"created_at,omitempty"` 296 Notes string `json:"metadata,omitempty"` 297 } 298 299 // ReportedError is the standard error model sent back from the API 300 type ReportedError struct { 301 Code int `json:"id"` 302 Message string `json:"message"` 303 } 304 305 type Role struct { 306 ID int `json:"id"` 307 Name string `json:"name"` 308 } 309 310 // Service service 311 type Service struct { 312 ID string `json:"id,omitempty"` 313 Identifier string `json:"identifier,omitempty"` 314 DNS string `json:"internal_domain,omitempty"` 315 Type string `json:"type,omitempty"` 316 Label string `json:"label"` 317 Size ServiceSize `json:"size"` 318 Name string `json:"name"` 319 Environment string `json:"environment,omitempty"` 320 EnvVars map[string]string `json:"environmentVariables,omitempty"` 321 Source string `json:"source,omitempty"` 322 LBIP string `json:"load_balancer_ip,omitempty"` 323 Scale int `json:"scale,omitempty"` 324 WorkerScale int `json:"worker_scale,omitempty"` 325 ReleaseVersion string `json:"release_version,omitempty"` 326 Redeployable bool `json:"redeployable,omitempty"` 327 } 328 329 // ServiceFile is a file associated with a service 330 type ServiceFile struct { 331 ID int `json:"id"` 332 Contents string `json:"contents"` 333 GID int `json:"gid"` 334 Mode string `json:"mode"` 335 Name string `json:"name"` 336 UID int `json:"uid"` 337 EnableDownload bool `json:"enable_download"` 338 CreatedAt string `json:"created_at"` 339 UpdatedAt string `json:"updated_at"` 340 } 341 342 // ServiceSize holds size information for a service 343 type ServiceSize struct { 344 RAM int `json:"ram"` 345 Storage int `json:"storage"` 346 Behavior string `json:"behavior,omitempty"` 347 Type string `json:"type,omitempty"` 348 CPU int `json:"cpu"` 349 } 350 351 type Settings SettingsV2 352 353 // SettingsV1 holds various settings for the current context. All items with 354 // `json:"-"` are never persisted to disk but used in memory for the current 355 // command. 356 type SettingsV1 struct { 357 AccountsHost string `json:"-"` 358 AuthHost string `json:"-"` 359 PaasHost string `json:"-"` 360 AuthHostVersion string `json:"-"` 361 PaasHostVersion string `json:"-"` 362 Version string `json:"-"` 363 HTTPManager HTTPManager `json:"-"` 364 365 Email string `json:"-"` 366 Password string `json:"-"` 367 EnvironmentID string `json:"-"` // the id of the environment used for the current command 368 ServiceID string `json:"-"` // the id of the service used for the current command 369 Pod string `json:"-"` // the pod used for the current command 370 EnvironmentName string `json:"-"` // the name of the environment used for the current command 371 OrgID string `json:"-"` // the org ID the chosen environment for this commands belongs to 372 PrivateKeyPath string `json:"private_key_path"` 373 SessionToken string `json:"token"` 374 UsersID string `json:"user_id"` 375 Environments map[string]AssociatedEnvV1 `json:"environments"` 376 Default string `json:"default"` 377 Pods *[]Pod `json:"pods"` 378 PodCheck int64 `json:"pod_check"` 379 } 380 381 // SettingsV2 holds various settings for the current context. All items with 382 // `json:"-"` are never persisted to disk but used in memory for the current 383 // command. 384 type SettingsV2 struct { 385 AccountsHost string `json:"-"` 386 AuthHost string `json:"-"` 387 PaasHost string `json:"-"` 388 AuthHostVersion string `json:"-"` 389 PaasHostVersion string `json:"-"` 390 Version string `json:"-"` 391 HTTPManager HTTPManager `json:"-"` 392 GivenEnvName string `json:"-"` 393 394 Email string `json:"-"` 395 Password string `json:"-"` 396 EnvironmentID string `json:"-"` // the id of the environment used for the current command 397 Pod string `json:"-"` // the pod used for the current command 398 EnvironmentName string `json:"-"` // the name of the environment used for the current command 399 OrgID string `json:"-"` // the org ID the chosen environment for this commands belongs to 400 PrivateKeyPath string `json:"private_key_path"` 401 SessionToken string `json:"token"` 402 UsersID string `json:"user_id"` 403 Environments map[string]AssociatedEnvV2 `json:"environments"` 404 Pods *[]Pod `json:"pods"` 405 PodCheck int64 `json:"pod_check"` 406 Format string `json:"format"` 407 } 408 409 type Site struct { 410 ID int `json:"id,omitempty"` 411 Name string `json:"name"` 412 Cert string `json:"cert"` 413 SiteFileID int `json:"siteFileId,omitempty"` 414 UpstreamService string `json:"upstreamService"` 415 Restricted bool `json:"restricted,omitempty"` 416 SiteValues map[string]interface{} `json:"site_values"` 417 } 418 419 // Spec is a job specification 420 type Spec struct { 421 Payload *Payload `json:"payload"` 422 } 423 424 // TempURL holds a URL for uploading or downloading files from a temporary URL 425 type TempURL struct { 426 URL string `json:"url"` 427 } 428 429 // User is an authenticated User 430 type User struct { 431 Email string `json:"email"` 432 SessionToken string `json:"sessionToken"` 433 UsersID string `json:"id"` 434 } 435 436 // UserKey is a public key belonging to a user 437 type UserKey struct { 438 Name string `json:"name"` 439 Key string `json:"key"` 440 } 441 442 type Volume struct { 443 ID int `json:"id"` 444 Type string `json:"type"` 445 Size int `json:"size"` 446 } 447 448 type Workers struct { 449 Limit int `json:"worker_limit,omitempty"` 450 Workers map[string]int `json:"workers"` 451 }