@@ -44,7 +44,11 @@ const (
44
44
errGetPC = "cannot get ProviderConfig"
45
45
errGetCreds = "cannot get credentials"
46
46
47
- errNewClient = "cannot create new Service"
47
+ errNewClient = "cannot create new Service"
48
+ errCreateUser = "cannot create User"
49
+ errDeleteUser = "cannot delete User"
50
+ errListUsers = "cannot list Users"
51
+ errGetUser = "cannot get User"
48
52
)
49
53
50
54
// A NoOpService does nothing.
@@ -145,8 +149,10 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
145
149
return managed.ExternalObservation {}, errors .New (errNotUser )
146
150
}
147
151
148
- // These fmt statements should be removed in the real implementation.
149
- fmt .Printf ("Observing: %+v" , cr )
152
+ users , err := c .cloudianService .ListUsers (ctx , cr .Spec .ForProvider .GroupID , nil )
153
+ if err != nil {
154
+ return managed.ExternalObservation {}, errors .Wrap (err , errListUsers )
155
+ }
150
156
151
157
return managed.ExternalObservation {
152
158
// Return false when the external resource does not exist. This lets
@@ -157,21 +163,36 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
157
163
// Return false when the external resource exists, but it not up to date
158
164
// with the desired managed resource state. This lets the managed
159
165
// resource reconciler know that it needs to call Update.
160
- ResourceUpToDate : true ,
166
+ ResourceUpToDate : isUpToDate ( cr . Spec . ForProvider , users ) ,
161
167
162
168
// Return any details that may be required to connect to the external
163
169
// resource. These will be stored as the connection secret.
164
170
ConnectionDetails : managed.ConnectionDetails {},
165
171
}, nil
166
172
}
167
173
174
+ func isUpToDate (spec v1alpha1.UserParameters , users []cloudian.User ) bool {
175
+ for _ , user := range users {
176
+ if user .UserID == spec .UserID {
177
+ return true
178
+ }
179
+ }
180
+ return false
181
+ }
182
+
168
183
func (c * external ) Create (ctx context.Context , mg resource.Managed ) (managed.ExternalCreation , error ) {
169
184
cr , ok := mg .(* v1alpha1.User )
170
185
if ! ok {
171
186
return managed.ExternalCreation {}, errors .New (errNotUser )
172
187
}
173
188
174
- fmt .Printf ("Creating: %+v" , cr )
189
+ user := cloudian.User {
190
+ GroupID : cr .Spec .ForProvider .GroupID ,
191
+ UserID : cr .Spec .ForProvider .UserID ,
192
+ }
193
+ if err := c .cloudianService .CreateUser (ctx , user ); err != nil {
194
+ return managed.ExternalCreation {}, errors .Wrap (err , errCreateUser )
195
+ }
175
196
176
197
return managed.ExternalCreation {
177
198
// Optionally return any details that may be required to connect to the
@@ -186,7 +207,7 @@ func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
186
207
return managed.ExternalUpdate {}, errors .New (errNotUser )
187
208
}
188
209
189
- fmt .Printf ("Updating : %+v" , cr )
210
+ fmt .Printf ("Pretending to Update (no managed fields to update) : %+v" , cr )
190
211
191
212
return managed.ExternalUpdate {
192
213
// Optionally return any details that may be required to connect to the
@@ -201,7 +222,13 @@ func (c *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext
201
222
return managed.ExternalDelete {}, errors .New (errNotUser )
202
223
}
203
224
204
- fmt .Printf ("Deleting: %+v" , cr )
225
+ user := cloudian.User {
226
+ GroupID : cr .Spec .ForProvider .GroupID ,
227
+ UserID : cr .Spec .ForProvider .UserID ,
228
+ }
229
+ if err := c .cloudianService .DeleteUser (ctx , user ); err != nil {
230
+ return managed.ExternalDelete {}, errors .Wrap (err , errDeleteUser )
231
+ }
205
232
206
233
return managed.ExternalDelete {}, nil
207
234
}
0 commit comments