@@ -665,10 +665,11 @@ func New(options *Options) *API {
665665 api .Auditor .Store (& options .Auditor )
666666 api .TailnetCoordinator .Store (& options .TailnetCoordinator )
667667 dialer := & InmemTailnetDialer {
668- CoordPtr : & api .TailnetCoordinator ,
669- DERPFn : api .DERPMap ,
670- Logger : options .Logger ,
671- ClientID : uuid .New (),
668+ CoordPtr : & api .TailnetCoordinator ,
669+ DERPFn : api .DERPMap ,
670+ Logger : options .Logger ,
671+ ClientID : uuid .New (),
672+ DatabaseHealthCheck : api .Database ,
672673 }
673674 stn , err := NewServerTailnet (api .ctx ,
674675 options .Logger ,
@@ -1147,64 +1148,74 @@ func New(options *Options) *API {
11471148 r .Get ("/" , api .AssignableSiteRoles )
11481149 })
11491150 r .Route ("/{user}" , func (r chi.Router ) {
1150- r .Use (httpmw .ExtractUserParam (options .Database ))
1151- r .Post ("/convert-login" , api .postConvertLoginType )
1152- r .Delete ("/" , api .deleteUser )
1153- r .Get ("/" , api .userByName )
1154- r .Get ("/autofill-parameters" , api .userAutofillParameters )
1155- r .Get ("/login-type" , api .userLoginType )
1156- r .Put ("/profile" , api .putUserProfile )
1157- r .Route ("/status" , func (r chi.Router ) {
1158- r .Put ("/suspend" , api .putSuspendUserAccount ())
1159- r .Put ("/activate" , api .putActivateUserAccount ())
1151+ r .Group (func (r chi.Router ) {
1152+ r .Use (httpmw .ExtractUserParamOptional (options .Database ))
1153+ // Creating workspaces does not require permissions on the user, only the
1154+ // organization member. This endpoint should match the authz story of
1155+ // postWorkspacesByOrganization
1156+ r .Post ("/workspaces" , api .postUserWorkspaces )
11601157 })
1161- r .Get ("/appearance" , api .userAppearanceSettings )
1162- r .Put ("/appearance" , api .putUserAppearanceSettings )
1163- r .Route ("/password" , func (r chi.Router ) {
1164- r .Use (httpmw .RateLimit (options .LoginRateLimit , time .Minute ))
1165- r .Put ("/" , api .putUserPassword )
1166- })
1167- // These roles apply to the site wide permissions.
1168- r .Put ("/roles" , api .putUserRoles )
1169- r .Get ("/roles" , api .userRoles )
1170-
1171- r .Route ("/keys" , func (r chi.Router ) {
1172- r .Post ("/" , api .postAPIKey )
1173- r .Route ("/tokens" , func (r chi.Router ) {
1174- r .Post ("/" , api .postToken )
1175- r .Get ("/" , api .tokens )
1176- r .Get ("/tokenconfig" , api .tokenConfig )
1177- r .Route ("/{keyname}" , func (r chi.Router ) {
1178- r .Get ("/" , api .apiKeyByName )
1179- })
1158+
1159+ r .Group (func (r chi.Router ) {
1160+ r .Use (httpmw .ExtractUserParam (options .Database ))
1161+
1162+ r .Post ("/convert-login" , api .postConvertLoginType )
1163+ r .Delete ("/" , api .deleteUser )
1164+ r .Get ("/" , api .userByName )
1165+ r .Get ("/autofill-parameters" , api .userAutofillParameters )
1166+ r .Get ("/login-type" , api .userLoginType )
1167+ r .Put ("/profile" , api .putUserProfile )
1168+ r .Route ("/status" , func (r chi.Router ) {
1169+ r .Put ("/suspend" , api .putSuspendUserAccount ())
1170+ r .Put ("/activate" , api .putActivateUserAccount ())
11801171 })
1181- r .Route ("/{keyid}" , func (r chi.Router ) {
1182- r .Get ("/" , api .apiKeyByID )
1183- r .Delete ("/" , api .deleteAPIKey )
1172+ r .Get ("/appearance" , api .userAppearanceSettings )
1173+ r .Put ("/appearance" , api .putUserAppearanceSettings )
1174+ r .Route ("/password" , func (r chi.Router ) {
1175+ r .Use (httpmw .RateLimit (options .LoginRateLimit , time .Minute ))
1176+ r .Put ("/" , api .putUserPassword )
1177+ })
1178+ // These roles apply to the site wide permissions.
1179+ r .Put ("/roles" , api .putUserRoles )
1180+ r .Get ("/roles" , api .userRoles )
1181+
1182+ r .Route ("/keys" , func (r chi.Router ) {
1183+ r .Post ("/" , api .postAPIKey )
1184+ r .Route ("/tokens" , func (r chi.Router ) {
1185+ r .Post ("/" , api .postToken )
1186+ r .Get ("/" , api .tokens )
1187+ r .Get ("/tokenconfig" , api .tokenConfig )
1188+ r .Route ("/{keyname}" , func (r chi.Router ) {
1189+ r .Get ("/" , api .apiKeyByName )
1190+ })
1191+ })
1192+ r .Route ("/{keyid}" , func (r chi.Router ) {
1193+ r .Get ("/" , api .apiKeyByID )
1194+ r .Delete ("/" , api .deleteAPIKey )
1195+ })
11841196 })
1185- })
11861197
1187- r .Route ("/organizations" , func (r chi.Router ) {
1188- r .Get ("/" , api .organizationsByUser )
1189- r .Get ("/{organizationname}" , api .organizationByUserAndName )
1190- })
1191- r .Post ("/workspaces" , api .postUserWorkspaces )
1192- r .Route ("/workspace/{workspacename}" , func (r chi.Router ) {
1193- r .Get ("/" , api .workspaceByOwnerAndName )
1194- r .Get ("/builds/{buildnumber}" , api .workspaceBuildByBuildNumber )
1195- })
1196- r .Get ("/gitsshkey" , api .gitSSHKey )
1197- r .Put ("/gitsshkey" , api .regenerateGitSSHKey )
1198- r .Route ("/notifications" , func (r chi.Router ) {
1199- r .Route ("/preferences" , func (r chi.Router ) {
1200- r .Get ("/" , api .userNotificationPreferences )
1201- r .Put ("/" , api .putUserNotificationPreferences )
1198+ r .Route ("/organizations" , func (r chi.Router ) {
1199+ r .Get ("/" , api .organizationsByUser )
1200+ r .Get ("/{organizationname}" , api .organizationByUserAndName )
1201+ })
1202+ r .Route ("/workspace/{workspacename}" , func (r chi.Router ) {
1203+ r .Get ("/" , api .workspaceByOwnerAndName )
1204+ r .Get ("/builds/{buildnumber}" , api .workspaceBuildByBuildNumber )
1205+ })
1206+ r .Get ("/gitsshkey" , api .gitSSHKey )
1207+ r .Put ("/gitsshkey" , api .regenerateGitSSHKey )
1208+ r .Route ("/notifications" , func (r chi.Router ) {
1209+ r .Route ("/preferences" , func (r chi.Router ) {
1210+ r .Get ("/" , api .userNotificationPreferences )
1211+ r .Put ("/" , api .putUserNotificationPreferences )
1212+ })
1213+ })
1214+ r .Route ("/webpush" , func (r chi.Router ) {
1215+ r .Post ("/subscription" , api .postUserWebpushSubscription )
1216+ r .Delete ("/subscription" , api .deleteUserWebpushSubscription )
1217+ r .Post ("/test" , api .postUserPushNotificationTest )
12021218 })
1203- })
1204- r .Route ("/webpush" , func (r chi.Router ) {
1205- r .Post ("/subscription" , api .postUserWebpushSubscription )
1206- r .Delete ("/subscription" , api .deleteUserWebpushSubscription )
1207- r .Post ("/test" , api .postUserPushNotificationTest )
12081219 })
12091220 })
12101221 })
0 commit comments