-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(samples): add Service directory samples (#42)
- Loading branch information
1 parent
2bfc36b
commit 06a0df2
Showing
11 changed files
with
595 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-east1', | ||
namespaceId = 'my-namespace', | ||
serviceId = 'my-service', | ||
endpointId = 'my-endpoint' | ||
) { | ||
// [START servicedirectory_create_endpoint] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
// const serviceId = 'my-service'; | ||
// const endpointId = 'my-endpoint'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the service name | ||
const serviceName = registrationServiceClient.servicePath( | ||
projectId, | ||
locationId, | ||
namespaceId, | ||
serviceId | ||
); | ||
|
||
async function createEndpoint() { | ||
const [endpoint] = await registrationServiceClient.createEndpoint({ | ||
parent: serviceName, | ||
endpointId: endpointId, | ||
endpoint: {address: '10.0.0.1', port: 8080}, | ||
}); | ||
|
||
console.log(`Created endpoint: ${endpoint.name}`); | ||
return endpoint; | ||
} | ||
|
||
return createEndpoint(); | ||
// [END servicedirectory_create_endpoint] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-central1', | ||
namespaceId = 'my-namespace' | ||
) { | ||
// [START servicedirectory_create_namespace] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the location name | ||
const locationName = registrationServiceClient.locationPath( | ||
projectId, | ||
locationId | ||
); | ||
|
||
async function createNamespace() { | ||
const [namespace] = await registrationServiceClient.createNamespace({ | ||
parent: locationName, | ||
namespaceId: namespaceId, | ||
}); | ||
|
||
console.log(`Created namespace: ${namespace.name}`); | ||
return namespace; | ||
} | ||
|
||
return createNamespace(); | ||
// [END servicedirectory_create_namespace] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-east1', | ||
namespaceId = 'my-namespace', | ||
serviceId = 'my-service' | ||
) { | ||
// [START servicedirectory_create_service] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
// const serviceId = 'my-service'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the namespace name | ||
const namespaceName = registrationServiceClient.namespacePath( | ||
projectId, | ||
locationId, | ||
namespaceId | ||
); | ||
|
||
async function createService() { | ||
const [service] = await registrationServiceClient.createService({ | ||
parent: namespaceName, | ||
serviceId: serviceId, | ||
}); | ||
|
||
console.log(`Created service: ${service.name}`); | ||
return service; | ||
} | ||
|
||
return createService(); | ||
// [END servicedirectory_create_service] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-east1', | ||
namespaceId = 'my-namespace', | ||
serviceId = 'my-service', | ||
endpointId = 'my-endpoint' | ||
) { | ||
// [START servicedirectory_delete_endpoint] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
// const serviceId = 'my-service'; | ||
// const endpointId = 'my-endpoint'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the endpoint name | ||
const endpointName = registrationServiceClient.endpointPath( | ||
projectId, | ||
locationId, | ||
namespaceId, | ||
serviceId, | ||
endpointId | ||
); | ||
|
||
async function deleteEndpoint() { | ||
await registrationServiceClient.deleteEndpoint({ | ||
name: endpointName, | ||
}); | ||
|
||
console.log(`Deleted endpoint: ${endpointName}`); | ||
} | ||
|
||
deleteEndpoint(); | ||
// [END servicedirectory_delete_endpoint] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-east1', | ||
namespaceId = 'my-namespace' | ||
) { | ||
// [START servicedirectory_delete_namespace] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the namespace name | ||
const namespaceName = registrationServiceClient.namespacePath( | ||
projectId, | ||
locationId, | ||
namespaceId | ||
); | ||
|
||
async function deleteNamespace() { | ||
await registrationServiceClient.deleteNamespace({ | ||
name: namespaceName, | ||
}); | ||
|
||
console.log(`Deleted namespace: ${namespaceName}`); | ||
} | ||
|
||
deleteNamespace(); | ||
// [END servicedirectory_delete_namespace] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
'use strict'; | ||
|
||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-east1', | ||
namespaceId = 'my-namespace', | ||
serviceId = 'my-service' | ||
) { | ||
// [START servicedirectory_delete_service] | ||
// | ||
// TODO(developer): Uncomment these variables before running the sample. | ||
// | ||
// const projectId = 'my-project'; | ||
// const locationId = 'us-central1'; | ||
// const namespaceId = 'my-namespace'; | ||
// const serviceId = 'my-service'; | ||
|
||
// Imports the Google Cloud client library | ||
const { | ||
RegistrationServiceClient, | ||
} = require('@google-cloud/service-directory'); | ||
|
||
// Creates a client | ||
const registrationServiceClient = new RegistrationServiceClient(); | ||
|
||
// Build the service name | ||
const serviceName = registrationServiceClient.servicePath( | ||
projectId, | ||
locationId, | ||
namespaceId, | ||
serviceId | ||
); | ||
|
||
async function deleteService() { | ||
await registrationServiceClient.deleteService({ | ||
name: serviceName, | ||
}); | ||
|
||
console.log(`Deleted service: ${serviceName}`); | ||
} | ||
|
||
deleteService(); | ||
// [END servicedirectory_delete_service] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.