@@ -12,15 +12,16 @@ type AuthService service
1212
1313// Don't add it to the models, as they are used with LAPI, but the enroll endpoint is specific to CAPI
1414type enrollRequest struct {
15- EnrollKey string `json:"attachment_key"`
15+ EnrollKey string `json:"attachment_key,omitempty "`
1616 Name string `json:"name"`
1717 Tags []string `json:"tags"`
18- Overwrite bool `json:"overwrite"`
18+ Overwrite bool `json:"overwrite,omitempty "`
1919 AutoEnroll bool `json:"autoenroll"`
2020}
2121
2222type autoEnrollResponse struct {
23- Url string `json:"url"`
23+ Url string `json:"url"`
24+ ExpiresAt int64 `json:"expire_at"`
2425}
2526
2627func (s * AuthService ) UnregisterWatcher (ctx context.Context ) (* Response , error ) {
@@ -76,7 +77,16 @@ func (s *AuthService) AuthenticateWatcher(ctx context.Context, auth models.Watch
7677func (s * AuthService ) EnrollWatcher (ctx context.Context , enrollKey string , name string , tags []string , overwrite bool , autoEnroll bool ) (autoEnrollResponse , * Response , error ) {
7778 u := fmt .Sprintf ("%s/watchers/enroll" , s .client .URLPrefix )
7879
79- req , err := s .client .PrepareRequest (ctx , http .MethodPost , u , & enrollRequest {EnrollKey : enrollKey , Name : name , Tags : tags , Overwrite : overwrite , AutoEnroll : autoEnroll })
80+ b := & enrollRequest {EnrollKey : enrollKey , Name : name , Tags : tags , AutoEnroll : autoEnroll }
81+ // Console refuses enroll requests if overwrite or key is set even to falsy values with autoenroll, so we only set them if they are needed
82+ if overwrite {
83+ b .Overwrite = true
84+ }
85+ if enrollKey != "" {
86+ b .EnrollKey = enrollKey
87+ }
88+
89+ req , err := s .client .PrepareRequest (ctx , http .MethodPost , u , b )
8090 if err != nil {
8191 return autoEnrollResponse {}, nil , err
8292 }
0 commit comments