我正在尝试创建一个 Cloud Build 触发器,其中使用 Cloud KMS 对秘密环境变量进行加密并存储为 Cloud Build 中的替换变量。这样我的云构建 yaml 是相当通用的,并且在我们部署到的所有环境中都是相同的。
这个云构建 yaml 工作正常:
steps:
- name: 'ubuntu'
entrypoint: 'bash'
args: ['-c', 'echo "$$APP_NAME HAS A VALUE $$HELLO_WORLD"']
env:
- 'APP_NAME=${_APP_NAME}'
secretEnv:
- 'HELLO_WORLD'
secrets:
- kmsKeyName: 'projects/my-first-cicd-project/locations/europe-west1/keyRings/keyring-dev/cryptoKeys/key-backend'
secretEnv:
HELLO_WORLD: xxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
构建步骤生成此日志行:
My App Name HAS A VALUE Hello there world!
Run Code Online (Sandbox Code Playgroud)
完全符合预期。
现在对于不起作用的事情,或者至少我无法上班。假设我想让密钥环名称动态化。然后我将该 yaml 中的“keyring-dev”替换为${_KMS_KEYRING_NAME}. 这将产生如下错误:
invalid build: failed to check access to "projects/my-first-cicd-project/locations/europe-west1/keyRings/${_KMS_KEYRING_NAME}/cryptoKeys/key-backend"
Run Code Online (Sandbox Code Playgroud)
如果我将 YAML 中的 base64 字符串(以“CiQAH...”开头)更改为诸如 ${_KMS_VAR_HELLO_WORLD} 之类的替换变量,我将收到此错误:
failed unmarshalling build config cloudbuild.yaml: illegal …Run Code Online (Sandbox Code Playgroud) 我想要实现的目标:
我希望 Terraform 在 GCP 中创建基于经典路由的 VPN 隧道。
背景:
在 GCP 中设置 VPN 隧道时,有 3 个选项用于路由 BGP 基于路由 基于策略
在 GCP 中创建基于路由的 VPN 隧道时,您需要指定远程子网。如果您要创建基于策略的 VPN 隧道,您还需要指定本地子网。
由于我想创建基于路由的 VPN 隧道,因此我只需要提供远程子网。
问题:
但是在 Terraform 中,资源“google_compute_vpn_tunnel”没有与要使用的路由类型有关的选项。好吧,也许它是由缺少“local_traffic_selector”决定的,然后变成基于路由的 VPN 隧道。但即使我在 main.tf 中省略了“local_traffic_selector”选项,它仍然存在于计划中。
' + local_traffic_selector =(应用后已知)
由于我没有为其指定任何值,Terraform 尝试将其与空值一起使用,这是不可能的。
Error: Error creating VpnTunnel: googleapi: Error 400: Invalid value for field 'resource.localTrafficSelector[0]': ''. The local_traffic_selector field cannot be empty for network in custom subnet mode., invalid
on main.tf line 51, in resource "google_compute_vpn_tunnel" "tunnel1":
51: resource "google_compute_vpn_tunnel" …Run Code Online (Sandbox Code Playgroud) 我想执行以下步骤:
1) tempfileA(注意:这是从 Google Cloud Storage 下载的 blob)
2) 临时文件B = 函数(临时文件A)
3) 临时文件C = 函数(临时文件B)
这应该非常简单,但是,我不确定访问基于前一个文件按顺序创建的不同临时文件的最佳方法是什么。
到目前为止,我已经从docs找到了下面的示例,但是Temporaryfile在子句的退出处关闭了with,因此在下一步中应该无法访问临时文件。
# create a temporary file using a context manager
with tempfile.TemporaryFile() as fp:
fp.write(b'Hello world!')
fp.seek(0)
fp.read()
Run Code Online (Sandbox Code Playgroud)
您能否建议实现上述目标的好方法是什么?请注意,在每个步骤中都会调用外部库中的方法来处理当前临时文件,结果应该是下一个临时文件。
python temporary-files python-3.x google-cloud-storage google-cloud-platform
查询BigTable时,我们遇到了一些性能问题。
查询约1400行时,监控仪表板中将获得约500行/秒的速度,而在与BigTable实例位于同一区域的计算机中运行下一个代码片段时,则需要约1.6秒:
partial_rows = instance.table(table_name).read_rows(filter_=row_filter, row_set=row_set)
ids = {}
for row in partial_rows:
key = row.row_key.decode()
category = key[0:5]
id_, year_month = key[5:].split('_')
dates = ids.get(id_, {})
for k, v in row.cells[column_family].items():
sub_key = k.decode()
day = sub_key[0:2]
measurement = f'{category}_{sub_key[3:]}'
date = datetime.date(int(year_month[0:4]), int(year_month[4:6]), int(day))
value = struct.unpack('>i', v[0].value)[0]
measurements = dates.get(date, {})
measurements[measurement] = value
dates[date] = measurements
ids[id_] = dates
Run Code Online (Sandbox Code Playgroud)
我们使用的表模式是:
{category}{id}_{year}{month}{day}{measurement_name}在我们的案例中,此架构完全遵循BigTable的准则。
该代码段非常简单,我们使用键和列名执行一些操作以创建如下所示的ids字典:
{
"4326": {
"2019-01-01": {
"value_a": 49
}, …Run Code Online (Sandbox Code Playgroud) 在查询中,如果我LIKE '<value>%'在主键上使用它,它使用索引执行得很好:
Operator | Rows returned | Executions | Latency
-- | -- | -- | --
Serialize Result 32 1 1.80 ms
Sort 32 1 1.78 ms
Hash Aggregate 32 1 1.73 ms
Distributed union 32 1 1.61 ms
Hash Aggregate 32 1 1.56 ms
Distributed union 128 1 1.34 ms
Compute - - -
FilterScan 128 1 1.33 ms
Table Scan: <tablename> 128 1 1.30 ms
Run Code Online (Sandbox Code Playgroud)
尽管如此, usingLIKE '<value>_'执行全表扫描:
Operator | Rows returned | …Run Code Online (Sandbox Code Playgroud) 我是 php 新手,我正在尝试使用 ssl 证书连接到 gloudsql。但它给了我一个关于 CN 的错误。这是什么意思以及我的代码中缺少什么?我的项目名称是wiiboardtest,我的实例名称是personal
$key = 'C:/Users/tasne/Downloads/client-key.pem';
$cert = 'C:/Users/tas/Downloads/client-cert.pem';
$ca = 'C:/Users/tas/Downloads/server-ca (1).pem';
$con = mysqli_init();
if(!$con){
die("mysqli_init failed");
}
$trial =
mysqli_ssl_set($con,$key,$cert,$ca,NULL,'ECDHE-RSA-AES256-SHA');
mysqli_options($con,
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
$dbhost = '35.246.68.234';
$dbuser = 'root';
$dbpass = 'waffer';
$database = 'personal';
$port = '3306';
$conn=mysqli_real_connect($con,$dbhost,$dbuser,$dbpass,$database,$port,
MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT );
if(!$conn){
die("connect error due
to:".mysqli_connect_error());
};
Run Code Online (Sandbox Code Playgroud)
mysqli_real_connect(): 对等证书 CN=
wiiboardtest:personal' did not match expected CN=35.246.68.234'
所以我有服务帐户凭据 json(作为字符串,或我的代码中的 json 对象):
{
"type": "service_account",
"project_id": "myproject",
"private_key_id": "lkjshdjhskas",
//.... etc
}
Run Code Online (Sandbox Code Playgroud)
然后我有这个简单的云存储上传片段:
const {Storage} = require('@google-cloud/storage');
const creds = {service_account_object:"creds are here"};
const storage = new Storage();
const bucketName = 'my-bucket';
const filename = 'my-file.txt';
storage.bucket(bucketName).upload(filename, {
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
});
Run Code Online (Sandbox Code Playgroud)
这给了我一个 invalid_grant 错误,当然:
(node:15920) UnhandledPromiseRejectionWarning: Error: invalid_grant
at Gaxios.request (C:\Users\Yuri\Documents\Code\btests\node_modules\gaxios\build\src\gaxios.js:70:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:15920) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a …Run Code Online (Sandbox Code Playgroud) google-authentication node.js google-cloud-storage google-cloud-platform