当我从 Azure AD 使用 Python 收到 JWK 时,我想对其进行验证和解码。但是,我不断收到错误“签名验证失败”。
我有以下设置:
使用 Azure 门户中的凭据,我设置了一个用于获取令牌的客户端。
import msal
ad_auth_client = msal.ConfidentialClientApplication(
client_id = client_id,
client_credential = client_secret,
authority = "https://login.microsoftonline.com/consumers"
)
my_token = ad_auth_client.acquire_token_for_client(scopes=['https://graph.microsoft.com/.default'])
Run Code Online (Sandbox Code Playgroud)
如果我将令牌放入https://jwt.io/这样的网站,一切看起来都很好。接下来,我需要来自 Azure 的公钥来验证令牌。
import requests
response = requests.get("https://login.microsoftonline.com/common/discovery/keys")
keys = response.json()['keys']
Run Code Online (Sandbox Code Playgroud)
为了将公钥与令牌相匹配,我在令牌标头中使用“kid”。我还知道使用哪种算法进行加密。
import jwt
token_headers = jwt.get_unverified_header(my_token['access_token'])
token_alg = token_headers['alg']
token_kid = token_headers['kid']
public_key = None
for key in …Run Code Online (Sandbox Code Playgroud) python decode public-key-encryption jwt azure-active-directory
因此,我们使用 Loki/Grafana 从 Kubernetes 集群收集日志,该工具非常适合这样做。但现在我已经清理了日志,我还想将它们可视化!
仅选择 JSON 行
# My query
{namespace="default",pod=~"kkds-dockerscanner-test.+"} |= "SchemaVersion" | json
Run Code Online (Sandbox Code Playgroud)
我只选择要在表格中显示的两列
{namespace="default",pod=~"kkds-dockerscanner-test.+"} |= "SchemaVersion" | json | line_format "{{.ArtifactName}} {{.Metadata_OS_Family}}"
Run Code Online (Sandbox Code Playgroud)
现在我想在表格中显示结果,但 Grafana 并没有完全显示我想要的表格。我想在表中显示查询的输出,而不仅仅是将输出显示为列中的字符串。您对如何完成这项工作有什么建议,或者您可以指出一个教程吗?
我无法使组变量在传单中工作,无法为每个组创建多边形。
我的资料:
data <- data.frame(group = c("p_pladser.1", "p_pladser.1", "p_pladser.2","p_pladser.2", "p_pladser.3", "p_pladser.3", "p_pladser.4", "p_pladser.4","p_pladser.6", "p_pladser.6", "p_pladser.6"), lat = c(55.67179, 55.67171, 55.67143, 55.67135, 55.67110, 55.67099, 55.67173, 55.67158, 55.67155, 55.67154, 55.67145), long = c(12.55825, 12.55853, 12.55956, 12.55984, 12.56041, 12.56082, 12.55819, 12.55873, 12.55913, 12.55914, 12.55946))
Run Code Online (Sandbox Code Playgroud)
我尝试过的
leaflet(data) %>%
addTiles() %>%
addPolygons(lat = ~ lat, lng = ~ long, group = ~ group)
Run Code Online (Sandbox Code Playgroud)
结果是:
我需要的是单独连接的停车位,下面分别用ggplot2中的相同数据完成。
ggplot() +
geom_line(data=data, aes(lat, long, group=group)) +
theme(legend.position="none")
Run Code Online (Sandbox Code Playgroud)
编辑:用于按组创建多边形的示例数据。
df <- data.frame(group = c(9,9,9,9,3,3,4,10,4,4,6,6,9,9,6,7,8,6,6,6,4,10,10,10,10,5,5,5,5,6,2,6,8,10,4,1,1,8,2,2,8,1,1,2,3,3,1,2,3,5,5,7,7,7,7,7), lat = c(12.51324264,12.513305365,12.513460965,12.513471705,12.51323028,12.51343869,12.51002744,12.50998803,12.50981405,12.50976721,12.511631235,12.513047085,12.513872565,12.51284178,12.512897255,12.51491698,12.51098456,12.51271646,12.512567055,12.51193457,12.510672405,12.509586335,12.509513235,12.509228595,12.51019304,12.514326785,12.51430267,12.51431847,12.514476435,12.512163885,12.51235039,12.51238198,12.51063921,12.51044102,12.510237215,12.510051915,12.51031317,12.511275515,12.51133816,12.51112378,12.51150496,12.50974082,12.51063222,12.51169496,12.512893665,12.51391899,12.510612445,12.51168118,12.5127838,12.5139199,12.515012135,12.51503213,12.515610885,12.515487105,12.515415995,12.51546271), long = c(55.662148595,55.66274813,55.662200085,55.662681285,55.6618097,55.66187776,55.66261815,55.66273954,55.66191013,55.66203335,55.66224483,55.66231779,55.662361495,55.662510495,55.662309905,55.66241728,55.66220386,55.662301165,55.6622937,55.662261925,55.66218702,55.663355645,55.663463555,55.66335952,55.663351875,55.661814145,55.66214884,55.661928915,55.662022445,55.66189588,55.66176534,55.662082195,55.66289834,55.663009465,55.66231188,55.661666315,55.66180155,55.662641355,55.661861295,55.661826095,55.662688875,55.66121794,55.66126692,55.66132434,55.661389205,55.66144555,55.66141339,55.661468365,55.661532485,55.66159399,55.66165429,55.661505195,55.662096835,55.6617923,55.662226165,55.661944765))
Run Code Online (Sandbox Code Playgroud) 我使用 data.tree 结构来汇总文件文件夹中的各种信息。在每个文件夹中我都有许多文件(值),我需要为每个文件夹做的是总结该文件夹+所有子文件夹包含多少个文件。
\n\n示例数据:
\n\nlibrary(data.tree)\ndata <- data.frame(pathString = c("MainFolder",\n "MainFolder/Folder1",\n "MainFolder/Folder2",\n "MainFolder/Folder3",\n "MainFolder/Folder1/Subfolder1",\n "MainFolder/Folder1/Subfolder2"),\n Value = c(1,1,5,2,4,10))\ntree <- as.Node(data, Value)\nprint(tree, "Value")\n levelName Value\n1 MainFolder 1\n2 \xc2\xa6--Folder1 1\n3 \xc2\xa6 \xc2\xa6--Subfolder1 4\n4 \xc2\xa6 \xc2\xb0--Subfolder2 10\n5 \xc2\xa6--Folder2 5\n6 \xc2\xb0--Folder3 2\nRun Code Online (Sandbox Code Playgroud)\n\n我目前对问题的解决方案非常缓慢:
\n\n# Function to sum up file counts pr folder + subfolders\ntotal_count <- function(node) {\n results <- sum(as.data.frame(print(node, "Value"))$Value)\n return(results)\n}\n\n# Summing up file counts pr folder + subfolders\ntree$Do(function(node) node$Value_by_folder <- total_count(node))\n\n\n# Results\nprint(tree, "Value", "Value_by_folder")\n levelName Value Value_by_folder\n1 MainFolder 1 …Run Code Online (Sandbox Code Playgroud) Databricks 非常智能,但如何识别当前笔记本的路径?网站上的指南没有帮助。
它建议:
%scala
dbutils.notebook.getContext.notebookPath
res1: Option[String] = Some(/Users/user@org.dk/my_test_notebook)
Run Code Online (Sandbox Code Playgroud)
这并没有给我完整的路径,而是给我一些无法从笔记本访问的文件夹结构的路径。我需要路径,以便我可以在与.ipynb文件相同的文件夹中进行系统调用。
有什么建议?
我有一个矢量:
as <- c(1,2,3,4,5,9)
Run Code Online (Sandbox Code Playgroud)
我需要从索引1开始提取向量中的第一个连续序列,以便输出如下:
1 2 3 4 5
Run Code Online (Sandbox Code Playgroud)
这样做是否有智能功能,或者我必须做一些不那么优雅的事情:
a <- c(1,2,3,4,5,9)
is_continunous <- c()
for (i in 1:length(a)) {
if(a[i+1] - a[i] == 1) {
is_continunous <- c(is_continunous, i)
} else {
break
}
}
continunous_numbers <- c()
if(is_continunous[1] == 1) {
is_continunous <- c(is_continunous, length(is_continunous)+1)
continunous_numbers <- a[is_continunous]
}
Run Code Online (Sandbox Code Playgroud)
它可以解决问题,但我希望有一个功能可以做到这一点.
我需要删除第二个冒号之后的所有内容。我有几种日期格式,需要使用相同的算法进行清理。
a <- "2016-12-31T18:31:34Z"
b <- "2016-12-31T18:31Z"
Run Code Online (Sandbox Code Playgroud)
我尝试匹配两个列组,但我似乎无法找出如何删除第二个匹配组。
sub("(:.*){2}", "", "2016-12-31T18:31:34Z")
Run Code Online (Sandbox Code Playgroud) 如何将字符串转换为时间戳?
我找到的文档和所有答案都显示了如何使用 to_timestamp 函数将字符串列转换为时间戳,但这显然不适用于单个字符串。
to_timestamp('2019-09-20 13:59', 'DD-MM-YYYY HH24:MI:SS')
Cast('2019-09-20 13:59' as timestamp)
Run Code Online (Sandbox Code Playgroud)
我想向表中添加一列,并以此日期作为重复值。
-- Creating timestamp column
ALTER TABLE my_table ADD creation_date timestamp
-- Repeating timestamp
UPDATE my_table SET creation_date = TO_TIMESTAMP('2019-09-20 13:59', 'YYYY-MM-DD HH24:MI')
Run Code Online (Sandbox Code Playgroud) 我有一个矢量列表
list_of_vectors <- list(c("a", "b", "c"), c("a", "c", "b"), c("b", "c", "a"), c("b", "b", "c"), c("c", "c", "b"), c("b", "c", "b"), c("b", "b", "c", "d"), NULL)
Run Code Online (Sandbox Code Playgroud)
对于此列表,我想知道哪些向量在其元素方面是唯一的.也就是说,我想要以下输出
[[1]]
[1] "a" "b" "c"
[[2]]
[1] "b" "b" "c"
[[3]]
[1] "c" "c" "b"
[[4]]
[1] "b" "b" "c" "d"
[[5]]
[1] NULL
Run Code Online (Sandbox Code Playgroud)
R中是否有用于执行此检查的功能?或者我是否需要通过编写函数来做很多变通办法?
我目前不那么优雅的解决方案:
# Function for turning vectors into strings ordered by alphabet
stringer <- function(vector) {
if(is.null(vector)) {
return(NULL)
} else {
vector_ordered <- vector[order(vector)]
vector_string <- paste(vector_ordered, collapse …Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的 JSON 文件:
{
"Results": [
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "1.21.1ubuntu2.1"
},
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2"
},
{
"Severity": "HIGH",
"VulnerabilityID": "CVE-2016-2781"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想创建以下 JSON 文件:
[
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "1.21.1ubuntu2.1",
"VulnerabilityID": ""
},
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "",
"VulnerabilityID": ""
},
{
"Severity": "HIGH",
"InstalledVersion": "",
"FixedVersion": "",
"VulnerabilityID": "CVE-2016-2781"
}
]
Run Code Online (Sandbox Code Playgroud)
我尝试过迭代第一个 JSON 文件,但是当我按照以下方式执行此操作时,会出现随机解析错误(使用我正在使用的真实 JSON 文件)。所以我认为我正在做的管道有问题。
jq -c '.Results[]' my.json | while read i; do
echo $i;
done …Run Code Online (Sandbox Code Playgroud) 我很难弄清楚如何从递归函数返回嵌套列表。我有一个嵌套的结构,我想从中返回每个级别的元素。
我的结构类似于以下内容,但是我不知道其深度。
# Data
my_input = {'a': {'d':None, 'e':None, 'f':{'g':None}}, 'b':None, 'c':None}
Run Code Online (Sandbox Code Playgroud)
我需要将所有可能的级别输出到列表列表
# Desired output
[['a'], ['b'], ['c'], ['a', 'd'], ['a', 'e'], ['a', 'f'], ['a', 'f', 'g']]
Run Code Online (Sandbox Code Playgroud)
此功能根本不起作用。看来我无法理解如何从递归函数返回。每当我运行该函数时,最终要么覆盖输出,要么没有上一次迭代中的正确信息。关于如何正确编写此功能的任何建议?
def output_levels(dictionary, output=None):
print(dictionary)
if not output:
output = []
if len(dictionary.keys()) == 1:
return output.append(dictionary.keys())
for key in dictionary.keys():
if not dictionary[key]:
output.append(key)
continue
output.append(output_levels(dictionary[key], output.append(key)))
return output
Run Code Online (Sandbox Code Playgroud) r ×5
list ×2
python ×2
recursion ×2
arrays ×1
bash ×1
continuous ×1
databricks ×1
decode ×1
dictionary ×1
directory ×1
grafana ×1
grafana-loki ×1
indexing ×1
jq ×1
json ×1
jwt ×1
kubernetes ×1
leaflet ×1
nested ×1
path ×1
postgresql ×1
regex ×1
regex-group ×1
sql ×1
string ×1
timestamp ×1
tree ×1
unique ×1
vector ×1