Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postprovision.ps1 breaks when values contains '=', such as an AppInsights connection string containing (IngestionEndpoint= and LiveEndpoint=) #5

Open
pascostefan opened this issue Feb 7, 2024 · 9 comments

Comments

@pascostefan
Copy link

pascostefan commented Feb 7, 2024

A solution could be something like this perhaps?
foreach ($line in $lines) {
$index = $line.IndexOf('=')
$name = $line.Substring(0, $index)
$value = $line.Substring($index + 1)
$value = $value.Replace('"', '')
$name = $name.Replace('__', '')
if ($value -ne '') {
dotnet user-secrets set $name $value | Out-Null
}
}

@pascostefan pascostefan changed the title postprovision.ps1 breaks when values contains '=' such as an AppInsights connection string containing (IngestionEndpoint= and LiveEndpoint=) postprovision.ps1 breaks when values contains '=', such as an AppInsights connection string containing (IngestionEndpoint= and LiveEndpoint=) Feb 7, 2024
@bradygaster
Copy link
Owner

curious, were you planning on submitting a pull request inclusive of application insights?

@pascostefan
Copy link
Author

yeah, that was my idea

@bradygaster
Copy link
Owner

cc @jongio on what he'd suggest as the safest way to terminate strings like that on the incoming. thanks for the contribution idea, let's get it in there. any chance you could optimize for making the app produce a nice app map, too?

@pascostefan
Copy link
Author

the app insights, I can make a pr on that, but don't have access to the preview 3 packages, should I request to merge into '02-end'?

@jongio
Copy link
Contributor

jongio commented Feb 12, 2024

@pascostefan - Can you test this?

function Set-DotnetUserSecrets {
    param ($path, $lines)
    Push-Location
    cd $path
    dotnet user-secrets init
    dotnet user-secrets clear
    foreach ($line in $lines) {
        # Split the line at the first equal sign only
        $parts = $line -split '=', 2
        $name = $parts[0]
        $value = $parts[1]

        # Remove quotes from the value
        $value = $value -replace '"', ''
        
        # Replace double underscores with colon in the name
        $name = $name -replace '__', ':'

        # Set the secret if the value is not empty
        if ($value -ne '') {
            dotnet user-secrets set $name $value | Out-Null
        }
    }
    Pop-Location
}

@pascostefan
Copy link
Author

pascostefan commented Feb 13, 2024

@jongio hi, yes tested, and it worked for me 👍

@jongio
Copy link
Contributor

jongio commented Feb 14, 2024

Cool, do you want to do a PR with that code or should I?

@pascostefan
Copy link
Author

Please do 👍

@jongio
Copy link
Contributor

jongio commented Mar 4, 2024

Here: #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants