Comments (6)
你好 @gotnix,很高兴再次看到你在这里提问!希望你一切都好。
您的 Bash 脚本看起来是正确的,但是我注意到您在构造签名字符串时,可能没有正确地处理路径和查询参数。在 Apollo 的 Java 和 Python 实现中,路径和查询参数都是 URL 编码的。这意味着所有的特殊字符,如空格和某些符号,都被转换为 URL 安全的编码。在 Bash 脚本中,您可以使用 curl
的 -G
和 --data-urlencode
选项来实现这一点。
另外,我注意到您在构造签名字符串时,使用的是 "\n" 作为分隔符。在 Bash 中,这可能不会被解析为换行符,而是被解析为两个字符:反斜杠和 n。您可以尝试使用 $'\n'
来表示换行符。
以下是一个修改后的 Bash 脚本示例:
#!/bin/bash
# Function to sign a string with HmacSHA1
function signature() {
# Get arguments: timestamp in milliseconds, path with query, and secret
timestamp_ms="$1"
path_with_query="$2"
secret="$3"
# Define delimiter for string construction
delimiter=$'\n'
# Construct string to sign
string_to_sign="$timestamp_ms$delimiter$path_with_query"
# Use openssl for HmacSHA1 (assuming it's installed)
signature=$(echo -n "${string_to_sign}" | openssl dgst -sha1 -hmac "${secret}" -binary | openssl enc -base64 -A)
# Return the signature
echo "$signature"
}
# 请求 Apollo
timestamp_ns=$(date +%s%N) # Get current timestamp in milliseconds
timestamp_ms=$((timestamp_ns / 1000000))
secret="$1"
path_with_query="$2"
url_encode="$(printf %s ${path_with_query} | jq -sRr @uri)"
signature=$(signature "$timestamp_ms" "${url_encode}" "$secret")
#echo "Signature: $signature"
curl -v -G -H "Authorization: Apollo biz-sea-zl-api:${signature}" \
-H "Timestamp: ${timestamp_ms}" \
--data-urlencode "${url_encode}" \
http://10.200.12.104:8080
如果这个修改后的脚本仍然无法解决您的问题,那么可能需要进一步检查 Apollo 服务器的日志,看看是否有更多关于 401 错误的详细信息。
Sources
- apollo-portal/src/main/resources/static/app/access_key.html
- apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AccessKeyController.java
- apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from apollo.
I'm glad to hear that the suggested changes resolved your issue, @gotnix! It's completely okay to seek help here, and I'm here to assist you. If you have any more questions or run into any other issues in the future, feel free to reach out. Utilizing Discussions for smaller issues is a great idea, and it can also help other community members who might have similar questions.
If you have any more questions or need further assistance, don't hesitate to ask. I'm here to help!
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from apollo.
@dosu-bot 的回答是正确的,用 $'\n'
来表示换行符,delimiter="\n"
修改为 delimiter=$'\n'
解决了问题。
感觉这个问题太小白了,更适合在 Discussions讨论,准备在 Discussions 建好帖子来关闭这个 Issue 的,结果发现 dosu-bot 已经解决问题了。
之前没有用过 Discussions ,我以后注意,优先使用 Discussions,打扰各位了。
from apollo.
@dosu-bot Awesome response! Really cool to see you getting better and better.
from apollo.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.
from apollo.
This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.
from apollo.
Related Issues (20)
- Portal 模块 RestTemplate 支持配置 ConnectionTimeToLive
- apollo2.1.0集成pgsql,求给一份pgsql的sql文件。mysql的不可以用 HOT 4
- 无法删除旧的配置 HOT 7
- 在项目namespace数量比较多的情况下(大约1000个),打开页面加载速度很慢,比较影响用户体验,这个是否有什么优化改进方案? HOT 7
- Apollo是否可以支持按照key维度来发布? HOT 3
- 1.8.0,接入一个app.id 使用多个namespace的时候,多个namesapce均开启了accesskey.sercet,这时候接入的配置代码要怎么写呢 HOT 3
- OidcLocalUserService throw an Exception when executing createLocalUser in OIDC profile HOT 6
- 麻烦问下,有什么办法能同时读到多个环境同一个配置的值吗? HOT 3
- 使用客户端添加string类型的配置项时会报错 HOT 1
- 配置从 2.1.0导出,导入到 2.2.0,数据中时间解析失败 HOT 1
- 在 apollo-portal统一增加访问路径的前缀/apollo 时,导入配置的请求url 有部分没有添加前缀 HOT 1
- apollo-portal 使用统一前缀/apollo以后,创建集群失败 HOT 1
- k8s部署apollo 接入ldap报错 HOT 1
- 请问有大佬已经在2.2.0版本上,数据源由mysql切换至pg了嘛? HOT 1
- 脚本启动与停止的问题 HOT 3
- 删除App后,相似的AppID权限异常,并无法恢复 HOT 4
- dockerfile基础镜像漏洞 HOT 4
- 使用docker安装apollo 镜像里面的demo.sh缺少读取环境变量的逻辑 HOT 1
- yml读取k-v的值错误 HOT 2
- Beautify Portal TraceLog UI interface
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo.