Skip to content

Instantly share code, notes, and snippets.

@SpencerSharkey
Created April 10, 2023 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpencerSharkey/e340c1eca2b044c23cf68bf2e3c6dd38 to your computer and use it in GitHub Desktop.
Save SpencerSharkey/e340c1eca2b044c23cf68bf2e3c6dd38 to your computer and use it in GitHub Desktop.

File Dropper Service

This service is intended to be ran across a fleet of servers (bare metal or virtualized) to keep configuration files up to date. The clients connect to a centralized server who's implementation is out of scope for this assignment.

Your client should initiate a server-side streaming Watch request that will emit events on source updates. It's up to the client to consume this event stream and keep the requested files up to date. After connecting and making the watch request, OpSync will be the first message received. Additionally, the OpSync event may be received at any point in the stream for various upstream reasons. OpUpdate and OpRemove are called when files must be updated or removed from the destination system.

Resources:

syntax = "proto3";
package dropperv1;
/// A struct describing a file item to be updated on the target.
message FileItem {
/// File destination path
string path = 1;
/// File contents (bytes)
bytes contents = 2;
/// File Permissions
uint32 permissions = 3;
/// File owner (user id)
string user = 4;
/// File group (group id)
string group = 5;
/// Shell command to run on file change
string command = 6;
}
/// A watch request, parameters are derived from client identity.
message WatchRequest {}
/// A message sent from the watch stream.
message WatchResponse {
/// Sent when the client has reconnected or fallen behind.
/// Contains the whole list of files.
message OpSync {
repeated FileItem items = 1;
}
/// Sent when a single file entry has been updated.
message OpUpdate {
FileItem item = 1;
}
/// Sent when a single file entry has been removed.
message OpRemove {
string path = 1;
}
/// The possible message types sent during a watch session.
oneof op {
OpSync sync = 1;
OpUpdate update = 2;
OpRemove remove = 3;
}
}
/// Dropper service provides an op stream.
service DropperService {
rpc Watch(WatchRequest) returns (stream WatchResponse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment