|
| 1 | +package automationconfig |
| 2 | + |
| 3 | +import ( |
| 4 | + "path" |
| 5 | +) |
| 6 | + |
| 7 | +type ProcessType string |
| 8 | + |
| 9 | +const ( |
| 10 | + Mongod ProcessType = "mongod" |
| 11 | + DefaultMongoDBDataDir = "/data" |
| 12 | + DefaultAgentLogPath = "/var/log/mongodb-mms-automation" |
| 13 | +) |
| 14 | + |
| 15 | +type Auth struct { |
| 16 | + // Users is a list which contains the desired users at the project level. |
| 17 | + Users []MongoDBUser `json:"usersWanted,omitempty"` |
| 18 | + Disabled bool `json:"disabled"` |
| 19 | + // AuthoritativeSet indicates if the MongoDBUsers should be synced with the current list of Users |
| 20 | + AuthoritativeSet bool `json:"authoritativeSet"` |
| 21 | + // AutoAuthMechanisms is a list of auth mechanisms the Automation Agent is able to use |
| 22 | + AutoAuthMechanisms []string `json:"autoAuthMechanisms,omitempty"` |
| 23 | + |
| 24 | + // AutoAuthMechanism is the currently active agent authentication mechanism. This is a read only |
| 25 | + // field |
| 26 | + AutoAuthMechanism string `json:"autoAuthMechanism"` |
| 27 | + // DeploymentAuthMechanisms is a list of possible auth mechanisms that can be used within deployments |
| 28 | + DeploymentAuthMechanisms []string `json:"deploymentAuthMechanisms,omitempty"` |
| 29 | + // AutoUser is the MongoDB Automation Agent user, when x509 is enabled, it should be set to the subject of the AA's certificate |
| 30 | + AutoUser string `json:"autoUser,omitempty"` |
| 31 | + // Key is the contents of the KeyFile, the automation agent will ensure this a KeyFile with these contents exists at the `KeyFile` path |
| 32 | + Key string `json:"key,omitempty"` |
| 33 | + // KeyFile is the path to a keyfile with read & write permissions. It is a required field if `Disabled=false` |
| 34 | + KeyFile string `json:"keyfile,omitempty"` |
| 35 | + // KeyFileWindows is required if `Disabled=false` even if the value is not used |
| 36 | + KeyFileWindows string `json:"keyfileWindows,omitempty"` |
| 37 | + // AutoPwd is a required field when going from `Disabled=false` to `Disabled=true` |
| 38 | + AutoPwd string `json:"autoPwd,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +func DisabledAuth() Auth { |
| 42 | + return Auth{ |
| 43 | + Users: make([]MongoDBUser, 0), |
| 44 | + AutoAuthMechanisms: make([]string, 0), |
| 45 | + DeploymentAuthMechanisms: make([]string, 0), |
| 46 | + AutoAuthMechanism: "MONGODB-CR", |
| 47 | + Disabled: true, |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +type MongoDBUser struct { |
| 52 | +} |
| 53 | + |
| 54 | +type Process struct { |
| 55 | + Name string `json:"name"` |
| 56 | + HostName string `json:"hostname"` |
| 57 | + Args26 Args26 `json:"args2_6"` |
| 58 | + Replication Replication `json:"replication"` |
| 59 | + Storage Storage `json:"storage"` |
| 60 | + ProcessType ProcessType `json:"processType"` |
| 61 | + Version string `json:"version"` |
| 62 | + AuthSchemaVersion int `json:"authSchemaVersion"` |
| 63 | + SystemLog SystemLog `json:"systemLog"` |
| 64 | + WiredTiger WiredTiger `json:"wiredTiger"` |
| 65 | +} |
| 66 | + |
| 67 | +type SystemLog struct { |
| 68 | + Destination string `json:"destination"` |
| 69 | + Path string `json:"path"` |
| 70 | +} |
| 71 | + |
| 72 | +func newProcess(name, hostName, version, replSetName string) Process { |
| 73 | + return Process{ |
| 74 | + Name: name, |
| 75 | + HostName: hostName, |
| 76 | + Storage: Storage{ |
| 77 | + DBPath: DefaultMongoDBDataDir, |
| 78 | + }, |
| 79 | + Replication: Replication{ReplicaSetName: replSetName}, |
| 80 | + ProcessType: Mongod, |
| 81 | + Version: version, |
| 82 | + SystemLog: SystemLog{ |
| 83 | + Destination: "file", |
| 84 | + Path: path.Join(DefaultAgentLogPath, "/mongodb.log"), |
| 85 | + }, |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +type Replication struct { |
| 90 | + ReplicaSetName string `json:"replSetName"` |
| 91 | +} |
| 92 | + |
| 93 | +type Storage struct { |
| 94 | + DBPath string `json:"dbPath"` |
| 95 | + WiredTiger WiredTiger `json:"wiredTiger"` |
| 96 | +} |
| 97 | + |
| 98 | +type WiredTiger struct { |
| 99 | + EngineConfig EngineConfig `json:"engineConfig"` |
| 100 | +} |
| 101 | + |
| 102 | +type EngineConfig struct { |
| 103 | + CacheSizeGB float32 `json:"cacheSizeGB"` |
| 104 | +} |
| 105 | + |
| 106 | +type LogRotate struct { |
| 107 | + SizeThresholdMB int `json:"sizeThresholdMB"` |
| 108 | + TimeThresholdHrs int `json:"timeThresholdHrs"` |
| 109 | +} |
| 110 | + |
| 111 | +type Security struct { |
| 112 | +} |
| 113 | + |
| 114 | +type Args26 struct { |
| 115 | +} |
| 116 | + |
| 117 | +type ReplicaSet struct { |
| 118 | + Id string `json:"_id"` |
| 119 | + Members []ReplicaSetMember `json:"members"` |
| 120 | + ProtocolVersion string `json:"protocolVersion"` |
| 121 | +} |
| 122 | + |
| 123 | +type ReplicaSetMember struct { |
| 124 | + Id string `json:"_id"` |
| 125 | + Host string `json:"host"` |
| 126 | + Priority int `json:"priority"` |
| 127 | + ArbiterOnly bool `json:"arbiterOnly"` |
| 128 | + Votes int `json:"votes"` |
| 129 | +} |
| 130 | + |
| 131 | +func newReplicaSetMember(p Process, id string) ReplicaSetMember { |
| 132 | + return ReplicaSetMember{ |
| 133 | + Id: id, |
| 134 | + Host: p.Name, |
| 135 | + Priority: 1, |
| 136 | + ArbiterOnly: false, |
| 137 | + Votes: 1, |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | +type AutomationConfig struct { |
| 142 | + Version string `json:"version"` |
| 143 | + Processes []Process `json:"processes"` |
| 144 | + ReplicaSets []ReplicaSet `json:"replicaSets"` |
| 145 | + Auth Auth `json:"auth"` |
| 146 | +} |
0 commit comments