Skip to content

Commit 9bcc6c6

Browse files
fix: [billing] fixed resource_reference for name in GetProjectBillingInfo (#4619)
* fix: fixed resource_reference for name in GetProjectBillingInfo PiperOrigin-RevId: 563189185 Source-Link: googleapis/googleapis@4967815 Source-Link: googleapis/googleapis-gen@9f06f3e Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWJpbGxpbmcvLk93bEJvdC55YW1sIiwiaCI6IjlmMDZmM2UwYmMwZTE2NjYyYTI2NGUzZGRjMmVmMzliZjdhZDkzZWMifQ== * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 083c352 commit 9bcc6c6

4 files changed

Lines changed: 66 additions & 2 deletions

File tree

packages/google-cloud-billing/protos/google/cloud/billing/v1/cloud_billing.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ message GetProjectBillingInfoRequest {
378378
string name = 1 [
379379
(google.api.field_behavior) = REQUIRED,
380380
(google.api.resource_reference) = {
381-
type: "cloudbilling.googleapis.com/ProjectBillingInfo"
381+
type: "cloudresourcemanager.googleapis.com/Project"
382382
}
383383
];
384384
}

packages/google-cloud-billing/protos/protos.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/google-cloud-billing/src/v1/cloud_billing_client.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ export class CloudBillingClient {
181181
billingAccountPathTemplate: new this._gaxModule.PathTemplate(
182182
'billingAccounts/{billing_account}'
183183
),
184+
projectPathTemplate: new this._gaxModule.PathTemplate(
185+
'projects/{project}'
186+
),
184187
projectBillingInfoPathTemplate: new this._gaxModule.PathTemplate(
185188
'projects/{project}/billingInfo'
186189
),
@@ -1598,6 +1601,29 @@ export class CloudBillingClient {
15981601
).billing_account;
15991602
}
16001603

1604+
/**
1605+
* Return a fully-qualified project resource name string.
1606+
*
1607+
* @param {string} project
1608+
* @returns {string} Resource name string.
1609+
*/
1610+
projectPath(project: string) {
1611+
return this.pathTemplates.projectPathTemplate.render({
1612+
project: project,
1613+
});
1614+
}
1615+
1616+
/**
1617+
* Parse the project from Project resource.
1618+
*
1619+
* @param {string} projectName
1620+
* A fully-qualified path representing Project resource.
1621+
* @returns {string} A string representing the project.
1622+
*/
1623+
matchProjectFromProjectName(projectName: string) {
1624+
return this.pathTemplates.projectPathTemplate.match(projectName).project;
1625+
}
1626+
16011627
/**
16021628
* Return a fully-qualified projectBillingInfo resource name string.
16031629
*

packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,44 @@ describe('v1.CloudBillingClient', () => {
18601860
});
18611861
});
18621862

1863+
describe('project', () => {
1864+
const fakePath = '/rendered/path/project';
1865+
const expectedParameters = {
1866+
project: 'projectValue',
1867+
};
1868+
const client = new cloudbillingModule.v1.CloudBillingClient({
1869+
credentials: {client_email: 'bogus', private_key: 'bogus'},
1870+
projectId: 'bogus',
1871+
});
1872+
client.initialize();
1873+
client.pathTemplates.projectPathTemplate.render = sinon
1874+
.stub()
1875+
.returns(fakePath);
1876+
client.pathTemplates.projectPathTemplate.match = sinon
1877+
.stub()
1878+
.returns(expectedParameters);
1879+
1880+
it('projectPath', () => {
1881+
const result = client.projectPath('projectValue');
1882+
assert.strictEqual(result, fakePath);
1883+
assert(
1884+
(client.pathTemplates.projectPathTemplate.render as SinonStub)
1885+
.getCall(-1)
1886+
.calledWith(expectedParameters)
1887+
);
1888+
});
1889+
1890+
it('matchProjectFromProjectName', () => {
1891+
const result = client.matchProjectFromProjectName(fakePath);
1892+
assert.strictEqual(result, 'projectValue');
1893+
assert(
1894+
(client.pathTemplates.projectPathTemplate.match as SinonStub)
1895+
.getCall(-1)
1896+
.calledWith(fakePath)
1897+
);
1898+
});
1899+
});
1900+
18631901
describe('projectBillingInfo', () => {
18641902
const fakePath = '/rendered/path/projectBillingInfo';
18651903
const expectedParameters = {

0 commit comments

Comments
 (0)