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

Fix #11, Implement setting X-Audit-Log-Reason header #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/Wumpus.Net.Rest/Net/IDiscordRestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ internal interface IDiscordRestApi : IDisposable
/// If modifying a category, individual Channel Update events will fire for each child channel that also changes.
/// </summary>
[Patch("channels/{channelId}")]
Task<Channel> ModifyChannelAsync([Path] Snowflake channelId, [Body] ModifyChannelParams args);
Task<Channel> ModifyChannelAsync([Path] Snowflake channelId, [Body] ModifyChannelParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
Copy link

Choose a reason for hiding this comment

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

I think moving the header declaration to be a property akin to the authorization header would be more appropriate than passing it in as a method parameter. This would make it accessible immediately to any new endpoints that arise that can utilize it for audit logging.

The client would need to null out this property after every request though if changed to this, as not to reuse the same header value between requests, and...I'm not quite sure where that logic should go now that I look at what's possible with RestEase.

Copy link
Author

Choose a reason for hiding this comment

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

Given that this property may change very frequently, I think this approach would also require considering thread saftey

Copy link

Choose a reason for hiding this comment

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

Forgot to consider that. Do you know if the endpoints you've added the header param for are the only ones that actually do anything if you specify the audit log header?

Copy link
Author

Choose a reason for hiding this comment

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

[Delete("channels/{channelId}")]
Task<Channel> DeleteChannelAsync([Path] Snowflake channelId);
Task<Channel> DeleteChannelAsync([Path] Snowflake channelId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

/// <summary>
/// Returns the <see cref="Entities.Message"/> for a <see cref="Entities.Channel"/>. If operating on a <see cref="Entities.Guild"/> <see cref="Entities.Channel"/>, this endpoint requires the <see cref="Entities.ChannelPermissions.ViewChannel"/> to be present on the current <see cref="Entities.User"/>.
Expand All @@ -68,7 +68,7 @@ internal interface IDiscordRestApi : IDisposable
[Patch("channels/{channelId}/messages/{messageId}")]
Task<Message> ModifyMessageAsync([Path] Snowflake channelId, [Path] Snowflake messageId, [Body] ModifyMessageParams args);
[Delete("channels/{channelId}/messages/{messageId}")]
Task DeleteMessageAsync([Path] Snowflake channelId, [Path] Snowflake messageId);
Task DeleteMessageAsync([Path] Snowflake channelId, [Path] Snowflake messageId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Post("channels/{channelId}/messages/bulk-delete")]
Task DeleteMessagesAsync([Path] Snowflake channelId, [Body] DeleteMessagesParams args);

Expand All @@ -84,9 +84,9 @@ internal interface IDiscordRestApi : IDisposable
Task DeleteAllReactionsAsync([Path] Snowflake channelId, [Path] Snowflake messageId);

[Put("channels/{channelId}/permissions/{overwriteId}")]
Task EditChannelPermissionsAsync([Path] Snowflake channelId, [Path] Snowflake overwriteId, [Body] ModifyChannelPermissionsParams args);
Task EditChannelPermissionsAsync([Path] Snowflake channelId, [Path] Snowflake overwriteId, [Body] ModifyChannelPermissionsParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("channels/{channelId}/permissions/{overwriteId}")]
Task DeleteChannelPermissionsAsync([Path] Snowflake channelId, [Path] Snowflake overwriteId);
Task DeleteChannelPermissionsAsync([Path] Snowflake channelId, [Path] Snowflake overwriteId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Get("channels/{channelId}/invites")]
Task<Invite[]> GetChannelInvitesAsync([Path] Snowflake channelId);
Expand Down Expand Up @@ -115,11 +115,11 @@ internal interface IDiscordRestApi : IDisposable
[Get("guilds/{guildId}/emoji/{emojiId}")]
Task<Emoji> GetGuildEmojiAsync([Path] Snowflake guildId, [Path] Snowflake emojiId);
[Post("guilds/{guildId}/emojis")]
Task<Emoji> CreateGuildEmojiAsync([Path] Snowflake guildId, [Body] CreateGuildEmojiParams args);
Task<Emoji> CreateGuildEmojiAsync([Path] Snowflake guildId, [Body] CreateGuildEmojiParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("guilds/{guildId}/emoji/{emojiId}")]
Task<Emoji> ModifyGuildEmojiAsync([Path] Snowflake guildId, [Path] Snowflake emojiId, [Body] ModifyGuildEmojiParams args);
Task<Emoji> ModifyGuildEmojiAsync([Path] Snowflake guildId, [Path] Snowflake emojiId, [Body] ModifyGuildEmojiParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("guilds/{guildId}/emoji/{emojiId}")]
Task DeleteGuildEmojiAsync([Path] Snowflake guildId, [Path] Snowflake emojiId);
Task DeleteGuildEmojiAsync([Path] Snowflake guildId, [Path] Snowflake emojiId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

// Gateway

Expand All @@ -135,14 +135,14 @@ internal interface IDiscordRestApi : IDisposable
[Post("guilds")]
Task<Guild> CreateGuildAsync([Body] CreateGuildParams args);
[Patch("guilds/{guildId}")]
Task<Guild> ModifyGuildAsync([Path] Snowflake guildId, [Body] ModifyGuildParams args);
Task<Guild> ModifyGuildAsync([Path] Snowflake guildId, [Body] ModifyGuildParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("guilds/{guildId}")]
Task DeleteGuildAsync([Path] Snowflake guildId);

[Get("guilds/{guildId}/channels")]
Task<Channel[]> GetGuildChannelsAsync([Path] Snowflake guildId);
[Post("guilds/{guildId}/channels")]
Task<Channel> CreateGuildChannelAsync([Path] Snowflake guildId, [Body] CreateGuildChannelParams args);
Task<Channel> CreateGuildChannelAsync([Path] Snowflake guildId, [Body] CreateGuildChannelParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("guilds/{guildId}/channels")]
Task<Channel[]> ModifyGuildChannelPositionsAsync([Path] Snowflake guildId, [Body] ModifyGuildChannelPositionParams[] args);

Expand All @@ -153,7 +153,7 @@ internal interface IDiscordRestApi : IDisposable
[Put("guilds/{guildId}/members/{userId}")]
Task<GuildMember> AddGuildMemberAsync([Path] Snowflake guildId, [Path] Snowflake userId, [Body] AddGuildMemberParams args);
[Delete("guilds/{guildId}/members/{userId}")]
Task RemoveGuildMemberAsync([Path] Snowflake guildId, [Path] Snowflake userId);
Task RemoveGuildMemberAsync([Path] Snowflake guildId, [Path] Snowflake userId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("guilds/{guildId}/members/{userId}")]
Task ModifyGuildMemberAsync([Path] Snowflake guildId, [Path] Snowflake userId, [Body] ModifyGuildMemberParams args);
[Patch("guilds/{guildId}/members/@me/nick")]
Expand All @@ -167,25 +167,25 @@ internal interface IDiscordRestApi : IDisposable
[Get("guilds/{guildId}/bans")]
Task<Ban[]> GetGuildBansAsync([Path] Snowflake guildId);
[Put("guilds/{guildId}/bans/{userId}")]
Task CreateGuildBanAsync([Path] Snowflake guildId, [Path] Snowflake userId, [QueryMap] CreateGuildBanParams args);
Task CreateGuildBanAsync([Path] Snowflake guildId, [Path] Snowflake userId, [QueryMap] CreateGuildBanParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("guilds/{guildId}/bans/{userId}")]
Task DeleteGuildBanAsync([Path] Snowflake guildId, [Path] Snowflake userId);
Task DeleteGuildBanAsync([Path] Snowflake guildId, [Path] Snowflake userId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Get("guilds/{guildId}/roles")]
Task<Role[]> GetGuildRolesAsync([Path] Snowflake guildId);
[Post("guilds/{guildId}/roles")]
Task<Role> CreateGuildRoleAsync([Path] Snowflake guildId, [Body] CreateGuildRoleParams args);
Task<Role> CreateGuildRoleAsync([Path] Snowflake guildId, [Body] CreateGuildRoleParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("guilds/{guildId}/roles/{roleId}")]
Task<Role> DeleteGuildRoleAsync([Path] Snowflake guildId, [Path] Snowflake roleId);
Task<Role> DeleteGuildRoleAsync([Path] Snowflake guildId, [Path] Snowflake roleId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("guilds/{guildId}/roles/{roleId}")]
Task<Role> ModifyGuildRoleAsync([Path] Snowflake guildId, [Path] Snowflake roleId, [Body] ModifyGuildRoleParams args);
Task<Role> ModifyGuildRoleAsync([Path] Snowflake guildId, [Path] Snowflake roleId, [Body] ModifyGuildRoleParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("guilds/{guildId}/roles")]
Task ModifyGuildRolePositionsAsync([Path] Snowflake guildId, [Body] ModifyGuildRolePositionParams[] args);

[Get("guilds/{guildId}/prune")]
Task<GuildPruneCountResponse> GetGuildPruneCountAsync([Path] Snowflake guildId, [QueryMap] GuildPruneParams args);
[Post("guilds/{guildId}/prune")]
Task<GuildPruneCountResponse> PruneGuildMembersAsync([Path] Snowflake guildId, [QueryMap] GuildPruneParams args);
Task<GuildPruneCountResponse> PruneGuildMembersAsync([Path] Snowflake guildId, [QueryMap] GuildPruneParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Get("guilds/{guildId}/regions")]
Task<VoiceRegion[]> GetGuildVoiceRegionsAsync([Path] Snowflake guildId);
Expand Down Expand Up @@ -217,7 +217,7 @@ internal interface IDiscordRestApi : IDisposable
[Get("invites/{code}")]
Task<Invite> GetInviteAsync([Path] Utf8String code, [QueryMap] GetInviteParams args);
[Delete("invites/{code}")]
Task<Invite> DeleteInviteAsync([Path] Utf8String code);
Task<Invite> DeleteInviteAsync([Path] Utf8String code, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

// OAuth

Expand Down Expand Up @@ -265,19 +265,19 @@ internal interface IDiscordRestApi : IDisposable
Task<Webhook> GetWebhookAsync([Path] Snowflake webhookId, [Path] Utf8String webhookToken);

[Post("channels/{channelId}/webhooks")]
Task<Webhook> CreateWebhookAsync([Path] Snowflake channelId, [Body] CreateWebhookParams args);
Task<Webhook> CreateWebhookAsync([Path] Snowflake channelId, [Body] CreateWebhookParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Delete("webhooks/{webhookId}")]
Task DeleteWebhookAsync([Path] Snowflake webhookId);
Task DeleteWebhookAsync([Path] Snowflake webhookId, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Delete("webhooks/{webhookId}/{webhookToken}")]
[Header("Authorization", null)]
Task DeleteWebhookAsync([Path] Snowflake webhookId, [Path] Utf8String webhookToken);
Task DeleteWebhookAsync([Path] Snowflake webhookId, [Path] Utf8String webhookToken, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Patch("webhooks/{webhookId}")]
Task<Webhook> ModifyWebhookAsync([Path] Snowflake webhookId, ModifyWebhookParams args);
Task<Webhook> ModifyWebhookAsync([Path] Snowflake webhookId, ModifyWebhookParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);
[Patch("webhooks/{webhookId}/{webhookToken}")]
[Header("Authorization", null)]
Task<Webhook> ModifyWebhookAsync([Path] Snowflake webhookId, [Path] Utf8String webhookToken, ModifyWebhookParams args);
Task<Webhook> ModifyWebhookAsync([Path] Snowflake webhookId, [Path] Utf8String webhookToken, ModifyWebhookParams args, [Header(WumpusRestClient.ReasonHeader)] string reason = null);

[Post("webhooks/{webhookId}/{webhookToken}")]
[Header("Authorization", null)]
Expand Down
Loading