File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 3030CFG_BUCKET_KEY = 'cluster-state-gcs-bucket'
3131CLUSTER_NAME_KEY = 'cluster-name'
3232PROJECT_KEY = 'project-id'
33+ CLIENT_ID_KEY = 'client-id'
3334ZONE_KEY = 'zone'
3435KJOB_BATCH_IMAGE = 'batch-image'
3536KJOB_BATCH_WORKING_DIRECTORY = 'batch-working-directory'
4546 CFG_BUCKET_KEY ,
4647 CLUSTER_NAME_KEY ,
4748 PROJECT_KEY ,
49+ CLIENT_ID_KEY ,
4850 ZONE_KEY ,
4951 GKE_ENDPOINT_KEY ,
5052 DEPENDENCIES_KEY ,
Original file line number Diff line number Diff line change 1+ """
2+ Copyright 2025 Google LLC
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ https://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ """
16+
17+ import uuid
18+ from .config import xpk_config , CLIENT_ID_KEY
19+
20+
21+ def generate_client_id ():
22+ """Generates Client ID and stores in configuration if not already present."""
23+ if xpk_config .get (CLIENT_ID_KEY ) is None :
24+ xpk_config .set (CLIENT_ID_KEY , str (uuid .uuid4 ()))
Original file line number Diff line number Diff line change 1+ """
2+ Copyright 2025 Google LLC
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ https://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ """
16+
17+ from .config import xpk_config , CLIENT_ID_KEY
18+ from .telemetry import generate_client_id
19+
20+
21+ def test_generates_client_id_when_its_not_present ():
22+ xpk_config .set (CLIENT_ID_KEY , None )
23+ generate_client_id ()
24+ assert xpk_config .get (CLIENT_ID_KEY ) is not None
25+
26+
27+ def test_does_not_generate_client_id_when_its_present ():
28+ client_id = '1337'
29+ xpk_config .set (CLIENT_ID_KEY , client_id )
30+ generate_client_id ()
31+ assert xpk_config .get (CLIENT_ID_KEY ) == client_id
Original file line number Diff line number Diff line change 3737
3838from .parser .core import set_parser
3939from .core .updates import print_xpk_hello
40+ from .core .telemetry import generate_client_id
4041from .utils .console import xpk_print
4142from .utils .execution_context import set_context
4243################### Compatibility Check ###################
@@ -71,6 +72,7 @@ def main() -> None:
7172 dry_run_value = 'dry_run' in main_args and main_args .dry_run ,
7273 quiet_value = 'quiet' in main_args and main_args .quiet ,
7374 )
75+ generate_client_id ()
7476 print_xpk_hello ()
7577 main_args .func (main_args )
7678 xpk_print ('XPK Done.' , flush = True )
You can’t perform that action at this time.
0 commit comments