Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Events] Add project notification settings #18

Closed
wants to merge 3 commits into from

Conversation

MohamedBassem
Copy link
Contributor

@MohamedBassem MohamedBassem commented Jul 26, 2023

[Events] Add project notification settings

ghstack-source-id: 2452ad00e890fa87497a785348ac29808eec1a40
Pull Request resolved: #18

This PR adds a new model for project notifications. The semantics of the model is explained in notifications.proto.

  1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
  2. Expose setters/getters to notification settings in metadata svc.
  3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}

MohamedBassem added a commit that referenced this pull request Jul 26, 2023
ghstack-source-id: f1d3b7830b6178271fd27d399d03903282ef5ec8
Pull Request resolved: #18
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
ghstack-source-id: f1d3b7830b6178271fd27d399d03903282ef5ec8
Pull Request resolved: #18
@MohamedBassem
Copy link
Contributor Author

This is still not ready for review, I'm doing more changes.

MohamedBassem added a commit that referenced this pull request Jul 26, 2023
Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```

ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
Pull Request resolved: #18
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```

ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
Pull Request resolved: #18
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
Pull Request resolved: #18


This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
[Events] Add project notification settings

    ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
    Pull Request resolved: #18


    This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

    1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
    2. Expose setters/getters to notification settings in metadata svc.
    3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

    Later, we can also add this to the CLI.

    Test plan:

    ```
    ~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
    Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
    {
        "channels": {
            "email": {
                "address": "testgmail.com",
                "type": "email",
                "verified": false
            }
        },
        "subscriptions": [
            {
                "channel_names": [
                    "email"
                ],
                "event": {
                    "type": "on_run_failure"
                }
            }
        ]
    }
    ```





[ghstack-poisoned]
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
ghstack-source-id: 2452ad00e890fa87497a785348ac29808eec1a40
Pull Request resolved: #18


This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
[Events] Add project notification settings

    ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
    Pull Request resolved: #18


    This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

    1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
    2. Expose setters/getters to notification settings in metadata svc.
    3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

    Later, we can also add this to the CLI.

    Test plan:

    ```
    ~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
    Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
    {
        "channels": {
            "email": {
                "address": "testgmail.com",
                "type": "email",
                "verified": false
            }
        },
        "subscriptions": [
            {
                "channel_names": [
                    "email"
                ],
                "event": {
                    "type": "on_run_failure"
                }
            }
        ]
    }
    ```





[ghstack-poisoned]
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
[Events] Add project notification settings

    ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
    Pull Request resolved: #18


    This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

    1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
    2. Expose setters/getters to notification settings in metadata svc.
    3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

    Later, we can also add this to the CLI.

    Test plan:

    ```
    ~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
    Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
    {
        "channels": {
            "email": {
                "address": "testgmail.com",
                "type": "email",
                "verified": false
            }
        },
        "subscriptions": [
            {
                "channel_names": [
                    "email"
                ],
                "event": {
                    "type": "on_run_failure"
                }
            }
        ]
    }
    ```





[ghstack-poisoned]
MohamedBassem added a commit that referenced this pull request Jul 26, 2023
[Events] Add project notification settings

    ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
    Pull Request resolved: #18


    This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

    1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
    2. Expose setters/getters to notification settings in metadata svc.
    3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

    Later, we can also add this to the CLI.

    Test plan:

    ```
    ~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
    Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
    {
        "channels": {
            "email": {
                "address": "testgmail.com",
                "type": "email",
                "verified": false
            }
        },
        "subscriptions": [
            {
                "channel_names": [
                    "email"
                ],
                "event": {
                    "type": "on_run_failure"
                }
            }
        ]
    }
    ```





[ghstack-poisoned]
AhmedSoliman
AhmedSoliman previously approved these changes Jul 26, 2023
Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good. Just a few tiny nits but nothing blocking.

cronback-api-model/src/admin/notifications.rs Show resolved Hide resolved
cronback-api-model/src/admin/notifications.rs Outdated Show resolved Hide resolved
cronback-proto/metadata_svc.proto Outdated Show resolved Hide resolved
let resp = metadata
.get_project_notification_settings(
GetProjectNotificationSettingsRequest {
id: Some(project_id.into()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that because you are using ScopedGrpcClient. project_id is sent automatically via extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, all the metadata APIs take the project id as part of the request. So this is here for consistency.

To be honest, I don't have strong opinions on whether we should keep them in request bodies or not. In one hand, it's in the request context as you mentioned, on the other hand, I find the empty request body to be slightly weird for "project" management APIs. No strong opinions though.

Comment on lines +147 to +155
let req = request.into_inner();
let project_id: ProjectId = req.id.unwrap().into();
let project_id = project_id
.validated()
.map_err(|e| Status::invalid_argument(e.to_string()))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validated ProjectId is available in request.context()? (defined in TonicRequestExt which is available in lib::prelude::*).

Comment on lines +200 to +205
.await
.map_err(ProjectStoreHandlerError::Store)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should explore a better way for error handling, the number of .map_err is pretty high. I'll give it some thought.

ghstack-source-id: 2452ad00e890fa87497a785348ac29808eec1a40
Pull Request resolved: #18


This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings @examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "[email protected]",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```
@MohamedBassem MohamedBassem changed the base branch from gh/MohamedBassem/0/base to main August 4, 2023 23:51
@MohamedBassem MohamedBassem dismissed AhmedSoliman’s stale review August 4, 2023 23:51

The base branch was changed.

[Events] Add project notification settings

ghstack-source-id: 2452ad00e890fa87497a785348ac29808eec1a40
Pull Request resolved: #18


This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "testgmail.com",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```


[ghstack-poisoned]
[Events] Add project notification settings

ghstack-source-id: 2452ad00e890fa87497a785348ac29808eec1a40
Pull Request resolved: #18


This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
2. Expose setters/getters to notification settings in metadata svc.
3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

Later, we can also add this to the CLI.

Test plan:

```
~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
{
    "channels": {
        "email": {
            "address": "testgmail.com",
            "type": "email",
            "verified": false
        }
    },
    "subscriptions": [
        {
            "channel_names": [
                "email"
            ],
            "event": {
                "type": "on_run_failure"
            }
        }
    ]
}
```


[ghstack-poisoned]
@MohamedBassem MohamedBassem deleted the gh/MohamedBassem/0/head branch August 5, 2023 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants