Is it possible to use Authorization: Bearer token encrupted?

adamstyl's Avatar

adamstyl

28 May, 2022 02:45 AM

I am desperately trying to reset the build number to zero. I am using this script:

  $apiUrl = 'https://ci.appveyor.com/api'
  $accountName = $env:APPVEYOR_ACCOUNT_NAME
  $projectSlug = $env:APPVEYOR_PROJECT_SLUG
  
  $headers = @{
    "Authorization" = "Bearer [the token here]"
    "Content-type" = "application/json"
    "Accept" = "application/json"
  }
  $build = @{
      nextBuildNumber = 0
  }
  $json = $build | ConvertTo-Json
  
  Invoke-RestMethod -Method Put $apiUrl/projects/$accountName/$projectSlug/settings/build-number -Body $json -Headers $headers

My problem is that I want to make this script part of the yml and that will expose the api token. As far as I'm concerned this is a baddie. Is there a way to work this around?

PS: why is it so hard to reset the build counter? I was quite disappointed to realize that ps: Set-AppveyorBuildVariable -Name 'APPVEYOR_BUILD_NUMBER' -Value '0' simply doesn't do anything and I have to resort to these gimmicks. :(

  1. 1 Posted by adamstyl on 28 May, 2022 10:43 AM

    adamstyl's Avatar

    Well never mind. I figured this out (with some hints from this discussion forum 😊)

    It's as simple as doing

    environment:
      my_api_token:
        secure: [the encrypted value here]
    

    And the key is that you can use the my_api_token in the script without any gimmicks:

      $apiUrl = 'https://ci.appveyor.com/api'
      $accountName = $env:APPVEYOR_ACCOUNT_NAME
      $projectSlug = $env:APPVEYOR_PROJECT_SLUG
      $token = $env:my_api_token
      
      $headers = @{
        "Authorization" = "Bearer $token"
        "Content-type" = "application/json"
        "Accept" = "application/json"
      }
      $build = @{
          nextBuildNumber = 0
      }
      $json = $build | ConvertTo-Json
      
      Invoke-RestMethod -Method Put $apiUrl/projects/$accountName/$projectSlug/settings/build-number -Body $json -Headers $headers
    

    If that's ok with you (when my time permits it) I will create a pull request in the documentation to mention that small detail -maybe that will save the next poor soul some time. :)

  2. adamstyl closed this discussion on 28 May, 2022 10:43 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Sep, 2024 03:49 PM
26 Sep, 2024 09:02 AM
25 Sep, 2024 07:07 PM
24 Sep, 2024 08:39 PM
24 Sep, 2024 06:47 AM
20 Sep, 2024 05:50 PM