github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/sandboxes/passthrough-mode/config/hello.py (about)

     1  # Copyright 2023 Google Inc.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     https://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  from absl import app
    16  from fleetspeak.client_connector.connector import FleetspeakConnection
    17  from fleetspeak.src.common.proto.fleetspeak.common_pb2 import Message
    18  from google.protobuf.wrappers_pb2 import StringValue
    19  
    20  
    21  def main(argv):
    22    del argv  # Unused.
    23  
    24    conn = FleetspeakConnection(version="0.0.1")
    25    while True:
    26      request, _ = conn.Recv()
    27  
    28      data = StringValue()
    29      request.data.Unpack(data)
    30  
    31      data.value = f"Hello {data.value}!"
    32  
    33      response = Message()
    34      response.destination.service_name = request.source.service_name
    35      response.data.Pack(data)
    36  
    37      conn.Send(response)
    38  
    39  
    40  if __name__ == "__main__":
    41    app.run(main)