Skip to content

Commit

Permalink
add service marketplace endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JanST123 committed May 9, 2023
1 parent bd7ce59 commit 3726a6b
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 7 deletions.
Binary file modified apiversion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions src/Objects/MarketplacePlan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { GridscaleObjects } from './GridscaleObjects';
import { APIClass, ApiResult, RequestOptions, VoidApiResult } from '../api';
import { MarketplaceNamedVersion } from './MarketplaceService';


export type MarketplaceProductInterval = 'minute' | 'hour' | 'day' | 'month' | 'quarter' | 'year';
export type MarketplaceProductType = 'subscription' | 'metered';

export interface MarketplaceProductExcerpt {
type: 'product_excerpt';
id: string;
attributes: {
interval: MarketplaceProductInterval;
price_per_interval_in_euro_cent: number;
type: MarketplaceProductType;
};
links: {
self?: string;
}
}

export interface MarketplacePlanDetailResponse {
data: MarketplacePlanDetailData;
included: (
MarketplaceNamedVersion | MarketplaceProductExcerpt
)[]
}

export interface MarketplacePlanDetailAttributes {
plan_key: string;
name: string;
terms_of_use: string;
description: string;
features: string[];
state: 'private' | 'archived' | 'public' | 'deleted';
allow_updates_from: string[];
}

export interface MarketplacePlanDetailData {
attributes: MarketplacePlanDetailAttributes;
id: string;
type: 'detailed_plan';
relationships: {
version: {
data: {
id: string;
type: 'named_version';
}
};
product_excerpts: {
data: {
id: string;
type: 'product_excerpt'
}[]
}
}
}

interface MarketplacePlan {
get(
_uuid: string,
_callback?: Function
): Promise<ApiResult<MarketplacePlanDetailResponse>>;
}
class MarketplacePlan extends GridscaleObjects {
constructor(_api: APIClass) {
super(_api, '/marketplace/v1/plans');
}
}

export { MarketplacePlan };
134 changes: 134 additions & 0 deletions src/Objects/MarketplaceService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { GridscaleObjects } from './GridscaleObjects';
import { APIClass, ApiResult, RequestOptions } from '../api';

export interface MarketplaceNamedPlan {
type: 'named_plan';
id: string;
attributes: {
name: string;
};
links: {
self?: string;
};
}

export interface MarketplaceServiceListRow {
attributes: {
name: string;
category_name: string;
links: {
linkServiceDetails: string
};
logo: string;
state: string;
vendor_name: string;
description?: string;
};
id: string;
type: string;
}



export interface MarketplaceServiceListResponse {
data: MarketplaceServiceListRow[],
links: {
first: string;
last: string;
next: string;
prev: string;
self: string;
};
meta: {
count: string;
limit: string;
page: string;
total: string;
};
}

export interface MarketplaceServiceDetailData {
attributes: {
name: string;
description: string;
category_name: string;
logo: string;
state: string;
};
id: string;
type: 'services';
relationships: {
vendor?: {
data: {
id: string,
type: 'vendors',
}
},
named_versions?: {
data: [
{
id: string,
type: 'named_version',
}
]
}
}
}

export interface MarketplaceVendorAttributes {
name: string;
description: string;
support_contact_uuid: string;
legal_contact_uuid: string;
partner_uuid: string;
}

export interface MarketplaceNamedVersion {
type: 'named_version';
id: string;
attributes: MarketplaceNamedVersionAttributes;
links: {
self?: string;
}
}
export interface MarketplaceNamedVersionAttributes {
name: string;
}

export interface MarketplaceServiceDetailVendor {
attributes: MarketplaceVendorAttributes;
id: string;
type: 'vendors';
}



export interface MarketplaceServiceDetailResponse {
data: MarketplaceServiceDetailData;
included: (
MarketplaceServiceDetailVendor | MarketplaceNamedVersion
)[];
links: {
self?: string;
relatedVersions?: string;
}
}


interface MarketplaceService {
list(
_options?: RequestOptions,
_callback?: Function
): Promise<ApiResult<MarketplaceServiceListResponse>>;
get(
_uuid: string,
_callback?: Function
): Promise<ApiResult<MarketplaceServiceDetailResponse>>;
}
class MarketplaceService extends GridscaleObjects {
constructor(_api: APIClass) {
super(_api, '/marketplace/v1/services');
}
}

export { MarketplaceService };
171 changes: 171 additions & 0 deletions src/Objects/MarketplaceServiceInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { GridscaleObjects } from './GridscaleObjects';
import { APIClass, ApiResult, RequestOptions } from '../api';

export interface MarketplaceServiceInstanceCreateResult {
links?: null;
data?: {
type: "service_instances",
id: string;
attributes?: {
service_uuid: string;
plan_uuid: string;
version_uuid: string;
release_uuid: string;
name: string;
state: string;
settings: null;
properties: null;
}
};
included?: null;
request_uuid?: string;
object_uuid?: string;
}

export interface MarketplaceServiceInstanceDataRow {
type: "service_instances_list";
id: string;
attributes?: {
name: string;
state: string;
links?: {
linkServiceInstanceDetail?: string;
}
}
}

export interface MarketplaceServiceInstanceListResponse {
links?: {
self?: string;
first?: string;
prev?: string;
next?: string;
last?: string;
},
data?: MarketplaceServiceInstanceDataRow[];
meta?: {
count?: string;
limit?: string;
page?: string;
total?: string;
}
}

export interface MarketplaceServiceInstanceDetailData {
type: "service_instances";
id: string;
attributes?: {
service_uuid?: string;
plan_uuid?: string;
version_uuid?: string;
release_uuid?: string;
name?: string;
state?: string;
settings?: null;
properties?: null;
}
}

export interface MarketplaceServiceInstanceDetailResponse {
links?: null;
data?: MarketplaceServiceInstanceDetailData;
included?: null;
}




class MarketplaceServiceInstance extends GridscaleObjects {
constructor(_api: APIClass) {
super(_api, '/marketplace/v1/projects');
}

/**
* Create a new service instance
*/
create(_attributes: {
name: string;
service_uuid: string;
plan_uuid: string;
version_uuid: string;
location_uuid: string;
contract_uuid: string;
project_uuid: string;
release_uuid: string;
vendor_keys: Record<string, string>;
settings: Record<string, string>;
}, _callback?: (response: Response, result: ApiResult<MarketplaceServiceInstanceCreateResult>) => void) {
return new Promise<ApiResult<MarketplaceServiceInstanceCreateResult>>((resolve, reject) => {
(this._api.post(this._basepath + '/' + _attributes.project_uuid + '/service-instances', _attributes, _callback) as Promise<ApiResult<MarketplaceServiceInstanceCreateResult>>)
.then(res => {
if (res.result?.data?.id) {
resolve({
...res,
result: {
...res.result,
object_uuid: res.result.data.id,
request_uuid: res.response.headers.get('x-correlate-id')
}
});
} else {
reject(new Error('unknown response'));
}

})
.catch(e => reject(e));
});
}

/**
* @deprecated please use `listInstances` method for this object type
*/
list(_options?: RequestOptions, _callback?: (response: Response, result: ApiResult<any>) => void): Promise<ApiResult<any>> {
return new Promise<ApiResult<any>>((resolve, reject) => {
reject(new Error('Unsupported method MarketplaceServiceInstance.list: Please use `listInstances` method for this object type!'));
});
}

/**
* List service instances
*/
listInstances(_project_uuid?: string, _options?: RequestOptions, _callback?: (response: Response, result: ApiResult<MarketplaceServiceInstanceListResponse>) => void): Promise<ApiResult<MarketplaceServiceInstanceListResponse>> {
// Get Defaults
const requestOptions = this._buildRequestOptions(_options);

return this._api.get(this._basepath + '/' + _project_uuid + '/service-instances', requestOptions, _callback);
}

/**
* @deprecated: Please use `getInstance` method for this object type
*/
get(_uuid: string, _callback?: (response: Response, result: ApiResult<any>) => void): Promise<ApiResult<any>> {
return new Promise<ApiResult<any>>((resolve, reject) => {
reject(new Error('Unsupported method MarketplaceServiceInstance.list: Please use `getInstance` method for this object type!'));
});
}

/**
* get service instance detail
*/
getInstance(_project_uuid: string, _uuid: string, _callback?: (response: Response, result: ApiResult<MarketplaceServiceInstanceDetailResponse>) => void): Promise<ApiResult<MarketplaceServiceInstanceDetailResponse>> {
return this._api.get(this._basepath + '/' + _project_uuid + '/service-instances/' + _uuid, {}, _callback);
}

/**
* @deprecated: Please use `requestDeleteInstance` method for this object type
*/
remove(_uuid: string, _callback?: (response: Response, result: ApiResult<any>) => void): Promise<ApiResult<void>> {
return new Promise<ApiResult<any>>((resolve, reject) => {
reject(new Error('Unsupported method MarketplaceServiceInstance.list: Please use `requestDeleteInstance` method for this object type!'));
});
}

/**
* request deletion of the instance
*/
requestDeleteInstance(_project_uuid: string, _uuid: string, _callback?: (response: Response, result: ApiResult<any>) => void): Promise<ApiResult<void>> {
return this._api.remove(this._basepath + '/' + _project_uuid + '/service-instances/' + _uuid, _callback);
}
}

export { MarketplaceServiceInstance };
Loading

0 comments on commit 3726a6b

Please sign in to comment.