Created
March 10, 2016 00:46
-
-
Save bluecmd/f9bc77f9dcf917f65b16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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