从资源访问Concourse REST API

问题描述 投票:0回答:1

我正在尝试编写自定义的Concourse资源(使用Python),该资源可访问Concourse实例的REST API以获得信息。我被困在登录时获取承载令牌。问题是,当我遵循此shell脚本的要旨时

#!/bin/bash

## Variables required  #need to update these to take inputs for getting token per team and target.
CONCOURSE_URL="http://localhost:8080"
CONCOURSE_USER="test"
CONCOURSE_PASSWORD="test"
CONCOURSE_TEAM="test"
CONCOURSE_TARGET="my-concourse"

function get_token() {
  ## Create a file named token that will be used to read and write tokens
  touch token

  ## extract the LDAP authentication url and write to token file
  LOCAL_AUTH_URL=$CONCOURSE_URL$(curl -b token -c token -L "$CONCOURSE_URL/sky/login" -s | grep "/sky/issuer/auth/local" | awk -F'"' '{print $4}')
  echo "url is $LOCAL_AUTH_URL"
  # login using username and password while writing to the token file
  curl -s -o /dev/null -b token -c token  -L --data-urlencode "login=$CONCOURSE_USER" --data-urlencode "password=$CONCOURSE_PASSWORD" "$LOCAL_AUTH_URL"

  ATC_BEARER_TOKEN=`grep 'Bearer' token | cut -d\   -f2 | sed 's/"$//'`
  echo $ATC_BEARER_TOKEN
}

涉及很多重定向,至少其中一些重定向将实例实例称为http://localhost:8080,在资源的Docker容器内部无法正常工作。

所以我想对外部基本URL进行参数化,并在资源配置中显式提供它。在最后的“批准”步骤中,使用代码400手动处理重定向并将本地IP重新写入URL失败,这可能是因为它看起来像某种跨域攻击。

环境变量ATC_EXTERNAL_URL始终为localhost:8080,我怀疑在形成重定向URL时也会使用该变量。可以在某个地方设置吗?

我对golang不好,但是在我看来https://github.com/concourse/concourse-pipeline-resource调用fly二进制文件来从资源内部实现某种登录。不能说我可以得到它的功能和方式。

感谢所有帮助...

concourse concourse-fly concourse-resource-types
1个回答
0
投票

env var $ATC_EXTERNAL_URL最有可能与您启动Concourse时指定的外部URL对应,因此,可以(并且,如果您使用的是Github或OAuth之类的外部身份验证,则必须)更改。您正确地假设它用于构造回调URL。

[此外,我也不想成为That Guy(TM),但是Concourse REST API不是公开的,并且随时可能更改。您要做什么,而您无法从fly CLI获得?您的资源可以在需要时调用ATC_EXTERNAL_URL以获取fly CLI,然后以这种方式执行命令。

© www.soinside.com 2019 - 2024. All rights reserved.