Fix: Run both sonar and clm scans in parallel
[ccsdk/cds.git] / ms / py-executor / resource_resolution / README.md
1 # Resource resolution GRPC client
2
3 ##  How to use examples
4
5 ### Insecure channel
6
7 ```
8 from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
9 from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
10 from resource_resolution.grpc.client import Client as ResourceResolutionClient
11
12
13 def generate_messages():
14     commonHeader = CommonHeader()
15     commonHeader.requestId = "1234"
16     commonHeader.subRequestId = "1234-1"
17     commonHeader.originatorId = "CDS"
18
19     actionIdentifiers = ActionIdentifiers()
20     actionIdentifiers.blueprintName = "sample-cba"
21     actionIdentifiers.blueprintVersion = "1.0.0"
22     actionIdentifiers.actionName = "SampleScript"
23
24     input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
25
26     commonHeader2 = CommonHeader()
27     commonHeader2.requestId = "1235"
28     commonHeader2.subRequestId = "1234-2"
29     commonHeader2.originatorId = "CDS"
30
31     input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
32
33     yield from [input, input2]
34
35
36 if __name__ == "__main__":
37     with ResourceResolutionClient("localhost:50052") as client:
38         for response in client.process(generate_messages()):
39             print(response)
40
41 ```
42
43 ### Secure channel
44
45 ```
46 from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
47 from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
48 from resource_resolution.grpc.client import Client as ResourceResolutionClient
49
50
51 def generate_messages():
52     commonHeader = CommonHeader()
53     commonHeader.requestId = "1234"
54     commonHeader.subRequestId = "1234-1"
55     commonHeader.originatorId = "CDS"
56
57     actionIdentifiers = ActionIdentifiers()
58     actionIdentifiers.blueprintName = "sample-cba"
59     actionIdentifiers.blueprintVersion = "1.0.0"
60     actionIdentifiers.actionName = "SampleScript"
61
62     input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
63
64     commonHeader2 = CommonHeader()
65     commonHeader2.requestId = "1235"
66     commonHeader2.subRequestId = "1234-2"
67     commonHeader2.originatorId = "CDS"
68
69     input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
70
71     yield from [input, input2]
72
73
74 if __name__ == "__main__":
75     with open("certs/py-executor/py-executor-chain.pem", "rb") as f:
76         with ResourceResolutionClient("localhost:50052", use_ssl=True, root_certificates=f.read()) as client:
77             for response in client.process(generate_messages()):
78                 print(response)
79
80 ```
81
82 ### Authorizarion header
83
84 ```
85 from proto.BluePrintCommon_pb2 import ActionIdentifiers, CommonHeader
86 from proto.BluePrintProcessing_pb2 import ExecutionServiceInput
87 from resource_resolution.grpc.client import Client as ResourceResolutionClient
88
89
90 def generate_messages():
91     commonHeader = CommonHeader()
92     commonHeader.requestId = "1234"
93     commonHeader.subRequestId = "1234-1"
94     commonHeader.originatorId = "CDS"
95
96     actionIdentifiers = ActionIdentifiers()
97     actionIdentifiers.blueprintName = "sample-cba"
98     actionIdentifiers.blueprintVersion = "1.0.0"
99     actionIdentifiers.actionName = "SampleScript"
100
101     input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
102
103     commonHeader2 = CommonHeader()
104     commonHeader2.requestId = "1235"
105     commonHeader2.subRequestId = "1234-2"
106     commonHeader2.originatorId = "CDS"
107
108     input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
109
110     yield from [input, input2]
111
112
113 if __name__ == "__main__":
114     with ResourceResolutionClient("127.0.0.1:9111", use_header_auth=True, header_auth_token="Token test") as client:
115         for response in client.process(generate_messages()):
116             print(response)
117
118 ```
119
120 # ResourceResoulution helper class
121
122 ## How to use examples
123
124 ### GRPC insecure channel
125
126 ```
127 from resource_resolution.resource_resolution import ResourceResolution, WorkflowExecution, WorkflowExecutionResult
128
129
130 if __name__ == "__main__":
131     with ResourceResolution(use_header_auth=True, header_auth_token="Basic token") as rr:
132         for response in rr.execute_workflows(  # type: WorkflowExecutionResult
133             WorkflowExecution(
134                 blueprint_name="blueprintName",
135                 blueprint_version="1.0",
136                 workflow_name="resource-assignment"
137             )
138         ):
139             if response.has_error:
140                 print(response.error_message)
141             else:
142                 print(response.payload)
143 ```
144
145 ### HTTP retrieve/store template
146
147 ```
148 from resource_resolution.resource_resolution import ResourceResolution
149
150 if __name__ == "__main__":
151     # If you want to use only HTTP you don't have to use context manager
152     r = ResourceResolution(
153         http_server_port=8081,
154         http_auth_user="ccsdkapps",
155         http_auth_pass="ccsdkapps",
156         http_use_tls=False
157     )
158     r.store_template(
159         blueprint_name="blueprintName",
160         blueprint_version="1.0.0", 
161         artifact_name="test",
162         resolution_key="test", 
163         result="test")
164     template = r.retrieve_template(
165         blueprint_name="blueprintName",
166         blueprint_version="1.0.0", 
167         artifact_name="test",
168         resolution_key="test",
169     )
170     assert template.result == "test"
171     template.result = "another value"
172     template.store()
173     another_template = r.retrieve_template(
174         blueprint_name="blueprintName",
175         blueprint_version="1.0.0", 
176         artifact_name="test",
177         resolution_key="test",
178     )
179     assert another_template.result == "another_value"
180 ```