Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    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

    Scheduled Pinned Locked Moved Support
    otter
    4 Posts 2 Posters 11 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      PhilippeC.
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • ? This user is from outside of this forum
        Guest
        last edited by

        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>

        1 Reply Last reply Reply Quote 0
        • ? This user is from outside of this forum
          Guest
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • ? This user is from outside of this forum
            Guest
            last edited by

            It is working :)

            Thank you

            Have a nice week-end

            Regards
            Philippe

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post
            Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation