Skip to content

Commit

Permalink
Make generate idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
henryrecker-pingidentity committed Oct 16, 2024
1 parent 9b4e497 commit 359605d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/updateClientAndConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
line = clientFile.readline()
# Use configuration.go method for UserAgent
if "User-Agent" in line:
line = line.replace("c.cfg.UserAgent", "c.cfg.UserAgent()")
line = line.replace("c.cfg.UserAgent)", "c.cfg.UserAgent())")
updatedClientLines.append(line)

with open("client.go", 'w') as clientFile:
Expand All @@ -25,6 +25,7 @@

# Update configuration.go
updatedConfigurationLines = []
userAgentMethodFound = False
with open("configuration.go", 'r') as configurationFile:
for line in configurationFile:
# Split UserAgent into two fields in the Configuration struct
Expand All @@ -35,10 +36,13 @@
# Remove UserAgent from the default configuration struct
if "UserAgent:" in line:
continue
if "UserAgent()" in line:
userAgentMethodFound = True
updatedConfigurationLines.append(line)

# Add new UserAgent() method with default that handle override and suffix
updatedConfigurationLines.append("""
if not userAgentMethodFound:
updatedConfigurationLines.append("""
func (c *Configuration) UserAgent() string {
if c.UserAgentOverride != nil {
return *c.UserAgentOverride
Expand Down

0 comments on commit 359605d

Please sign in to comment.