小编dev*_*min的帖子

如何使用 jq 从 json 数组/对象中获取多个值

如何在一行中使用 jq 从 JSON 数组/对象中获取多个值?

这里是curl请求及其响应

curl -s -k --location --request GET "https://${HOSTNAME}/api/v1/projects/myProjects?page=1&pageSize=2" --header "Authorization: Bearer "$token"" | jq -r '.["data"]'


# Response
[
  {
    "id": "8a70803f8045722601804f62d54c5d9d",
    "createdBy": "8a70802980325cdc0180326b5fe60006",
    "createdDate": "2022-04-22T03:48:38.860+0000",
    "modifiedBy": "8a70802980325cdc0180326b5fe60006",
    "modifiedDate": "2022-04-22T03:48:38.860+0000",
    "version": null,
    "inactive": false,
    "name": "Netbank734113",
  },
  {
    "id": "8a70801c804568ae01804f625a923f8d",
    "createdBy": "8a70802980325cdc0180326b5fe60006",
    "createdDate": "2022-04-22T03:48:07.442+0000",
    "modifiedBy": "8a70802980325cdc0180326b5fe60006",
    "modifiedDate": "2022-04-22T03:48:07.442+0000",
    "version": null,
    "inactive": false,
    "name": "Netbank734112",
  }
]

Run Code Online (Sandbox Code Playgroud)

现在尝试以下命令在一行中获取 id 和名称,但会出现重复的结果。

result=$(curl -s -k --location --request GET "https://${HOSTNAME}/api/v1/projects/myProjects?page=1&pageSize=2" --header "Authorization: Bearer "$token"" | jq -r '.["data"]|.[].name +" …
Run Code Online (Sandbox Code Playgroud)

shell jq

8
推荐指数
1
解决办法
3772
查看次数

如何使用containerd从私有存储库中提取图像?

如何使用containerd从私有存储库中提取图像?

我使用下面的 containerd 命令从私有存储库中提取图像,但失败并显示以下错误消息。

sudo crictl pull qtech/graphql:latest

FATA[0002] pulling image: rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/qtech/graphql:latest": failed to resolve reference "docker.io/qtech/graphql:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

Run Code Online (Sandbox Code Playgroud)

我确实使用我的 docker 凭据登录并成功提取了相同的图像。

azureuser@zk-master:~$ sudo docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. …
Run Code Online (Sandbox Code Playgroud)

containerd containerdctl

7
推荐指数
1
解决办法
3万
查看次数

如何有条件地跳过使用 terraform 创建/实现的部分 terraform 资源

如何有条件地跳过使用 terraform 创建/实现的部分 terraform 资源?

# main.tf file
locals {
  vnet_type = (var.vnet_type != "" ? var.vnet_type : "None")
}

data "azurerm_virtual_network" vnet {
  name = "testvnet"
  resource_group_name = "rest1"
}
  
data "azurerm_subnet" subnets {
  name = "testSubnet"
   resource_group_name  = "rest1"
   virtual_network_name = data.azurerm_virtual_network.vnet.name

}


resource "azurerm_api_management" "apim_demo" {
  name                = "test-apim"
  location            = "East US"
  resource_group_name = "rest1"
  publisher_name      = "admin"
  publisher_email     = "admin@gmail.com"

  sku_name = "Developer_1"

  identity {
    type = "SystemAssigned"
  }

 # vnet_Type can be External, None …
Run Code Online (Sandbox Code Playgroud)

azure terraform terraform-provider-azure azure-rm

5
推荐指数
1
解决办法
3877
查看次数

如何使用 bicep 将父资源名称引用到模块内的资源

如何使用 Microsoft bicep 代码将父资源名称引用到模块内的资源。

下面的 main.bicep 文件代码正在运行。

# main.bicep

param apimName string = 'devApim'
param apimLocation string = 'eastus'
param publisherName string = 'danny'
param publisherEmail string = 'danny@gmail.com'

param api_display_name string = 'Test Consumer API'
param api_description         = 'Test API description'
param api_versioningScheme    = 'Segment'

resource devApim_resource 'Microsoft.ApiManagement/service@2021-01-01-preview' = {
  name: apimName
  location: apimLocation
  sku: {
    name: 'Developer'
    capacity: 1
  }
  properties: {
    publisherEmail: publisherEmail
    publisherName: publisherName
  }
}


resource test_api_vs_v1 'Microsoft.ApiManagement/service/apiVersionSets@2021-01-01-preview' = {
// Below reference to first/parent …
Run Code Online (Sandbox Code Playgroud)

azure azure-resource-manager azure-bicep

3
推荐指数
1
解决办法
6151
查看次数

如何在 terraform 中检查具有两个值的变量字符串

如何在 terraform 中检查具有两个值的变量字符串。

\n

我想用两个字符串值检查变量中的字符串,类似于下面的代码。

\n
virtual_network_type = var.vnet_type == "External" || "Internal" ? var.vnet_type : null\n\n
Run Code Online (Sandbox Code Playgroud)\n

但 terraform 抛出以下错误消息

\n
Error: Invalid operand\n\xe2\x94\x82 \n\xe2\x94\x82   on ../../modules/test/test-instance.tf line 51, in resource "azurerm_api_management" "apim_demo":\n\xe2\x94\x82   51:  virtual_network_type = var.vnet_type == "External" || "Internal" ? var.vnet_type : null\n\xe2\x94\x82 \n\xe2\x94\x82 Unsuitable value for right operand: a bool is required.\n\xe2\x95\xb5\n
Run Code Online (Sandbox Code Playgroud)\n

我们可以在地形中做到这一点吗?

\n

terraform terraform-provider-azure

2
推荐指数
1
解决办法
8012
查看次数

我们可以将具有多个私有 dns 区域名称空间的虚拟网络分配为虚拟链接吗?

我们可以将具有多个私有 DNS 区域命名空间的虚拟网络分配为虚拟链接吗?

我有一个虚拟网络privateEndpoint-VNet,需要添加为具有多个私有 DNS 区域的虚拟链接,每个区域privatelink.blob.core.windows.net在不同的资源组中具有相同的命名空间,如果我尝试在创建选择了集成私有 DNS 区域选项的私有端点时添加它,我低于错误

"A virtual network cannot be linked to multiple zones with overlapping namespaces. 
You tried to link virtual network with 'privatelink.blob.core.windows.net' and 'privatelink.blob.core.windows.net' zones.".

Run Code Online (Sandbox Code Playgroud)

如果我们无法分配具有多个私有 DNS 区域的虚拟网络,每个区域都具有与虚拟链接相同的命名空间,我们如何解决上述错误消息?

我们的要求是,我们需要资源来privateEndpoint-VNet私下连接所有资源组中的所有托管存储帐户服务。

azure azure-private-dns azure-private-link azure-private-dns-zone

2
推荐指数
1
解决办法
6289
查看次数

如何在bash shell脚本中将json文件数据转换为字符串?

如何在bash shell脚本中将json文件数据转换为字符串?我有以下 json 格式的 petstore swagger 文件(https://petstore.swagger.io/v2/swagger.json)。

我已将此 json 文件转换为使用此网站https://jsontostring.com/进行一项操作所需的带有退格字符 \ 的字符串。

我已经尝试过 jq 工具来实现这一点,但没有得到结果,也许它不会使用 jq 工具来实现。

我们如何将这个相同的 petstore swagger json 文件转换为在 linux 或 bash shell 脚本中具有低于预期输出的字符串?

{"swagger":"2.0","info":{"description":"This is a sample server Petstore server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the authorization filters.","version":"1.0.6","title":"Swagger Petstore","termsOfService":"http://swagger.io/terms/","contact":{"email":"apiteam@swagger.io"},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}},"host":"petstore.swagger.io","basePath":"/v2","tags":[{"name":"pet","description":"Everything about your Pets","externalDocs":{"description":"Find out more","url":"http://swagger.io"}},{"name":"store","description":"Access to Petstore orders"},{"name":"user","description":"Operations about user","externalDocs":{"description":"Find out more …
Run Code Online (Sandbox Code Playgroud)

linux bash json

2
推荐指数
1
解决办法
3747
查看次数