Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

API Key broken after upgrade from 4.6 to 5.2



  • Hello

    API Keys are broken after I upgrade Otter from 4.6 to 5.2

    I use the following Powershell to autoregister an host after I install the Otter


    ``
    $SERVEUR=$env:computername
    [xml]$XmlDocument = Get-Content -Path "C:\Program Files\InedoAgent\InedoAgentService.exe.config"
    $AESKey=($XmlDocument.configuration.appsettings.add | where-object {$_.key -eq "EncryptionKey"}).value
    $body = @{
    name="$SERVEUR";
    hostname="$SERVEUR";
    active=$true;
    serverType="windows";
    drift="reportOnly";
    port="46336";
    roles=@("Baseline");
    environments=@("Integration");
    encryptionType="AES";
    encryptionKey=$AESKey
    }
    $URI="https://maestro.opcalim.org/api/infrastructure/servers/create/"+$SERVEUR+"?key=TEST"
    Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri $URI -Body (ConvertTo-Json $body)
    $URI="https://maestro.opcalim.org/api/configuration/check?server="+$SERVEUR+"&key=CONFIGURATION"
    Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri $URI

    `

    This works fine until I upgrade to 5.2.
    Now I have the following error msg:

    ``
    PS Microsoft.PowerShell.Core\FileSystem::\opcalim.org\Installation\Logiciels\Inedo\Agent Otter\1.4.6> \opcalim.org\Installation\Logiciels\Inedo\Agent Otter\1.4.6\register-otter.ps1
    Invoke-RestMethod : An API key is required to view or update infrastructure.
    At \opcalim.org\Installation\Logiciels\Inedo\Agent Otter\1.4.6\register-otter.ps1:21 char:1

    • Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri ...
    •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
      

    Invoke-RestMethod : Error reading JObject from JsonReader. Path '', line 0, position 0.
    At \opcalim.org\Installation\Logiciels\Inedo\Agent Otter\1.4.6\register-otter.ps1:24 char:1

    • Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri ...
    •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
      

    ``

    I recreate the API Key and it gives me the same result

    New bug or bad syntax ?

    Best Regards

    Philippe



  • Bad interface :(

    Here the power shell code
    <code>
    $SERVEUR=$env:computername
    [xml]$XmlDocument = Get-Content -Path "C:\Program Files\InedoAgent\InedoAgentService.exe.config"
    $AESKey=($XmlDocument.configuration.appsettings.add | where-object {$_.key -eq "EncryptionKey"}).value
    $body = @{
    name="$SERVEUR";
    hostname="$SERVEUR";
    active=$true;
    serverType="windows";
    drift="reportOnly";
    port="46336";
    roles=@("Baseline");
    environments=@("Integration");
    encryptionType="AES";
    encryptionKey=$AESKey
    }
    $URI="https://maestro.opcalim.org/api/infrastructure/servers/create/"+$SERVEUR+"?key=TEST"
    Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri $URI -Body (ConvertTo-Json $body)
    $URI="https://maestro.opcalim.org/api/configuration/check?server="+$SERVEUR+"&key=CONFIGURATION"
    Invoke-RestMethod -Method Post -ContentType 'application/json;' -Uri $URI
    </code>



  • You can either modify the JSON to support the key:

    $body = @{
        ...
        environments=@("Integration");
        encryptionType="AES";
        encryptionKey="00000000000000000000000000000000";
        "API_Key"="full"
    }
    

    Or supply it via an HTTP header:

    Invoke-RestMethod -Method Post -ContentType 'application/json' -Uri $URI 
       -Body (ConvertTo-Json $body) -Headers @{'X-ApiKey' = 'full'}
    

    Normally $key in the query string would also be accepted, but that is ignored when POSTing a body with application/json content type.



  • It is working :)

    Thank you

    Have a nice week-end

    Regards
    Philippe


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation