Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@cloudfoundry/api
Advanced tools
This is a client for interacting with the Cloud Foundry API.
This project is still in development, which means only few resourcess is implemented.
Luckily it is very simple to contribute. Please read the contribution guide below.
This library delivers a class, CloudFoundryClient
, which can be used to interact with the Cloud Foundry API. It composes resources apis as nested clients.
import { CloudFoundryClient } from '@cloudfoundry/api';
const client = new CloudFoundryClient({
apiEndpoint: 'https://api.cf.us10-001.hana.ondemand.com',
accessToken: 'bearer your_access_token',
});
const services = await client.serviceInstances.list();
console.log(JSON.stringify(services.data, null, 2));
For local testing, you can use the getOauthToken
function to retrieve a new token and getCFConfig
to retrieve target from CF CLI config.
import {
getOauthToken,
getCFConfig,
CloudFoundryClient,
} from '@cloudfoundry/api';
const config = await getCFConfig();
const token = await getOauthToken(config.Target);
const client = new CloudFoundryClient({
apiEndpoint: config.Target,
accessToken: token,
});
getCFConfig allow you to read ~/.cf/config.json
and return as a fully-typed object.
import { getCFConfig } from '@cloudfoundry/api';
const config = await getCFConfig();
console.log(config.Target);
To get a new token for local testing we're supposed to call cf oauth-token
.
With a following code we can do the same programmatically.
import { getOauthToken } from '@cloudfoundry/api';
const token = await getOauth();
console.log(token);
To onboard a new resource you need to:
src/api/resources
src/api/resources/{resource_type}/types.ts
src/api/resources/{resource_type}/api.ts
BaseClient
src/api/resources/index.ts
src/api/resources/common.ts
)CF API Resource contains required fields. Just to avoid repeating them in every resource we can use a generic type.
export interface ServiceInstanceResource extends Resource<ServiceInstanceEntity> {
...
}
which will add following types to a resource:
guid: uuid;
created_at: timestamp;
updated_at: timestamp;
links: links;
Almost every CF resource supports list operations with paginated responses. To unify the way we handle them a special utility type is provided.
list = (params?: {
names?: string[],
service_instance_guids?: string[],
service_instance_names?: string[],
...
}) => this.client.get<PaginatedResponse<ServiceCredentialBinding>>('/v3/service_credential_bindings', { params })
Some endpoints support a special fields query parameter, which allows to specify which fields should be returned.
These fields are specific per resource and described in a format like this:
Resource | Allowed Keys |
---|---|
space | guid, name, relationships.organization |
space.organization | guid, name |
service_plan | guid, name, relationships.service_offering |
service_plan.service_offering | guid, name, description, documentation_url, tags, relationships.service_broker |
service_plan.service_offering.service_broker | guid, name |
So what we do in code, to support such a parameter, is to define a type like this:
//defined allowed fields as a type in a following map format
type allowed_fields = {
space: ['guid', 'name', 'relationships.organization'];
'space.organization': ['guid', 'name'];
service_plan: ['guid', 'name', 'relationships.service_offering'];
'service_plan.service_offering': [
'guid',
'name',
'description',
'documentation_url',
'tags',
'relationships.service_broker'
];
'service_plan.service_offering.service_broker': ['guid', 'name'];
};
// use this type in a method signature
list = (params?: {
...
// only values from allowed_fields
fields?: AllowedFields<allowed_fields>,
}) => this.client.get<PaginatedResponse<ServiceInstance>>('/v3/service_instances', { params })
as a result in your code you'll be able to use like this:
const serviceInstances = await cf.serviceInstances.list({
fields: {
service_plan: ['name'],
'service_plan.service_offering.service_broker': ['name'],
'service_plan.service_offering': ['name'],
},
});
A nice feature is that you'll be able to use autocomplete in your IDE.
and as a result this code will trigger the URL like this (formatted for better understanding):
https://api.cf.us10-001.hana.ondemand.com
/v3/service_instances?
fields[service_plan]=name&
fields[service_plan.service_offering]=name&
fields[service_plan.service_offering.service_broker]=name&
page=1&
per_page=50
FAQs
Cloud Foundry API(v3) client
We found that @cloudfoundry/api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.