@@ -40,6 +40,43 @@ type MongoDBSpec struct {
4040 // Security configures security features, such as TLS, and authentication settings for a deployment
4141 // +optional
4242 Security Security `json:"security"`
43+
44+ // Users specifies the MongoDB users that should be configured in your deployment
45+ // +required
46+ Users []MongoDBUser `json:"users"`
47+ }
48+
49+ type MongoDBUser struct {
50+ // Name is the username of the user
51+ Name string `json:"name"`
52+
53+ // DB is the database the user is stored in. Defaults to "admin"
54+ // +optional
55+ DB string `json:"db"`
56+
57+ // PasswordSecretRef is a reference to the secret containing this user's password
58+ PasswordSecretRef SecretKeyReference `json:"passwordSecretRef"`
59+
60+ // Roles is an array of roles assigned to this user
61+ Roles []Role `json:"roles"`
62+ }
63+
64+ // SecretKeyReference is a reference to the secret containing the user's password
65+ type SecretKeyReference struct {
66+ // Name is the name of the secret storing this user's password
67+ Name string `json:"name"`
68+
69+ // Key is the key in the secret storing this password. Defaults to "password"
70+ // +optional
71+ Key string `json:"key"`
72+ }
73+
74+ // Role is the database role this user should have
75+ type Role struct {
76+ // DB is the database the role can act on
77+ DB string `json:"db"`
78+ // Name is the name of the role
79+ Name string `json:"name"`
4380}
4481
4582type Security struct {
@@ -125,6 +162,17 @@ func (m MongoDB) MongoURI() string {
125162 return fmt .Sprintf ("mongodb://%s" , strings .Join (members , "," ))
126163}
127164
165+ // TODO: this is a temporary function which will be used in the e2e tests
166+ // which will be removed in the following PR to clean up our mongo client testing
167+ func (m MongoDB ) SCRAMMongoURI (username , password string ) string {
168+ members := make ([]string , m .Spec .Members )
169+ clusterDomain := "svc.cluster.local" // TODO: make this configurable
170+ for i := 0 ; i < m .Spec .Members ; i ++ {
171+ members [i ] = fmt .Sprintf ("%s-%d.%s.%s.%s:%d" , m .Name , i , m .ServiceName (), m .Namespace , clusterDomain , 27017 )
172+ }
173+ return fmt .Sprintf ("mongodb://%s:%s@%s/?authMechanism=SCRAM-SHA-256" , username , password , strings .Join (members , "," ))
174+ }
175+
128176// ServiceName returns the name of the Service that should be created for
129177// this resource
130178func (m MongoDB ) ServiceName () string {
0 commit comments