Skip to content

Instantly share code, notes, and snippets.

@bluecmd
Created March 10, 2016 00:46
Show Gist options
  • Save bluecmd/f9bc77f9dcf917f65b16 to your computer and use it in GitHub Desktop.
Save bluecmd/f9bc77f9dcf917f65b16 to your computer and use it in GitHub Desktop.
from grpc.beta import implementations
import pwservice_pb2
TIMEOUT_SECONDS = 10
def run():
channel = implementations.insecure_channel('localhost', 50051)
stub = pwservice_pb2.beta_create_PasswordService_stub(channel)
response = stub.ChangePassword(pwservice_pb2.ChangePasswordRequest(
user='testuser', old_password='helloworld', new_password='newworld'),
TIMEOUT_SECONDS)
print "Password change response: ", response
if __name__ == '__main__':
run()
import pamela as pam
import pwservice_pb2
import signal
import time
class PasswordServer(pwservice_pb2.BetaPasswordServiceServicer):
def ChangePassword(self, request, context):
try:
pam.authenticate(request.user, request.old_password, 'login')
except pam.PAMError, e:
# TODO(bluecmd): Return some error code here
return None
# User is authenticated, change the password
try:
pam.change_password(request.user, request.old_password, 'login')
except pam.PAMError, e:
# TODO(bluecmd): Return some error code here
return None
return pwservice_pb2.EmptyReply()
def serve():
server = pwservice_pb2.beta_create_PasswordService_server(
PasswordServer())
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
signal.pause()
except KeyboardInterrupt:
pass
server.stop(0)
if __name__ == '__main__':
serve()
syntax = "proto3";
package pwservice;
service PasswordService {
rpc ChangePassword (ChangePasswordRequest) returns (EmptyReply) {}
}
message ChangePasswordRequest {
string user = 1;
string old_password = 2;
string new_password = 3;
}
message EmptyReply {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment