@skyramp/skyramp 0.4.32 → 0.4.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # skyramp
2
2
 
3
- `skyramp` is an npm module that provides utility functions for leveraging [skyramp CLI](https://skyramp.dev/docs/commands/skyramp/) commands. The `skyramp` module provides functionalities to create and apply mock configurations for both gRPC and REST APIs. It also offers features for testing and asserting scenarios in various test environments. The module exports the following classes: `RestEndpoint`, `GrpcEndpoint`, `Scenario`, and `SkyrampClient`.
3
+ `skyramp` is an npm module that provides utility functions for leveraging [skyramp CLI](https://skyramp.dev/docs/reference/cli-commands/) commands. The `skyramp` module provides functionalities to create and apply mock configurations for both gRPC and REST APIs. It also offers features for testing and asserting scenarios in various test environments. The module exports the following classes: `RestEndpoint`, `GrpcEndpoint`, `Scenario`, and `SkyrampClient`.
4
4
 
5
5
  ## Installation
6
6
  To install Skyramp, simply run the following command in your terminal:
7
7
  ```bash
8
- npm install skyramp
8
+ npm install @skyramp/skyramp
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
  Once you've installed Skyramp, you can import it into your project like this:
13
13
 
14
- ```bash
14
+ ```javascript
15
15
  const { GrpcEndpoint, RestEndpoint, SkyrampClient, Scenario } = require('skyramp');
16
16
  ```
17
17
 
@@ -19,7 +19,7 @@ const { GrpcEndpoint, RestEndpoint, SkyrampClient, Scenario } = require('skyramp
19
19
  The `SkyrampClient` class is the main entry point to interact with the skyramp module. It allows you to apply configurations, start test scenarios, and deploy and delete workers. First, you must set up the `SkyrampClient` with a kubernetes cluster.
20
20
 
21
21
  **Example: Provision Local Cluster with Skyramp**
22
- ```bash
22
+ ```javascript
23
23
  const skyrampClient = new SkyrampClient();
24
24
  skyrampClient.applyLocal().then(function() {
25
25
  // Local cluster provisioned
@@ -28,8 +28,9 @@ skyrampClient.applyLocal().then(function() {
28
28
  });
29
29
  ```
30
30
  Once you have a `SkyrampClient` instance configured with a kubernetes cluster, you can deploy the Skyramp Worker in-cluster, for applying mocks and running tests.
31
+
31
32
  **Example: Deploy Skyramp Worker**
32
- ```bash
33
+ ```javascript
33
34
  skyrampClient.deployWorker('my-namespace').then(function() {
34
35
  // Worker deployed successfully
35
36
  }).catch(function(error) {
@@ -41,10 +42,10 @@ skyrampClient.deployWorker('my-namespace').then(function() {
41
42
  The `RestEndpoint` class represents a REST API endpoint and provides methods to configure mock responses to apply them to the `SkyrampClient`.
42
43
 
43
44
  **Example: Create REST Mock Configuration**
44
- ```bash
45
+ ```javascript
45
46
  restEndpoint = new RestEndpoint('artists', 'artists-GET', 50050, 'api/openapi/artists.yaml');
46
47
  restEndpoint.mockMethodFromFile('artists-GET', 'files/rest-values.yaml');
47
- skyrampClient.mockerApply('my-namespace', restEndpoint).then(function() {
48
+ skyrampClient.mockerApply('my-namespace', '', restEndpoint).then(function() {
48
49
  // Mock applied successfully
49
50
  }).catch(function(error) {
50
51
  // Error occurred during mock application
@@ -55,10 +56,10 @@ skyrampClient.mockerApply('my-namespace', restEndpoint).then(function() {
55
56
  The `GrpcEndpoint` class represents a gRPC API endpoint and provides methods to configure mock responses to apply them to the `SkyrampClient`.
56
57
 
57
58
  **Example: Create gRPC Mock Configuration**
58
- ```bash
59
+ ```javascript
59
60
  grpcEndpoint = new GrpcEndpoint('routeguide', 'RouteGuide', 50051, 'api/pb/routeguide.proto');
60
61
  grpcEndpoint.mockMethodFromFile('GetFeature', 'files/grpc-response.yaml');
61
- skyrampClient.mockerApply('my-namespace', grpcEndpoint).then(function() {
62
+ skyrampClient.mockerApply('my-namespace', '', grpcEndpoint).then(function() {
62
63
  // Mock applied successfully
63
64
  }).catch(function(error) {
64
65
  // Error occurred during mock application
@@ -69,11 +70,11 @@ skyrampClient.mockerApply('my-namespace', grpcEndpoint).then(function() {
69
70
  The `Scenario` class allows you to define test scenarios by specifying a series of API requests and assertions to be made. Once a `Scenario` is created, you can start it using the `SkyrampClient` instance.
70
71
 
71
72
  **Example: Test Assert Scenario (REST)**
72
- ```bash
73
+ ```javascript
73
74
  scenario = new Scenario('rest-test')
74
75
  step1 = scenario.addRequest(restEndpoint, 'artists-GET');
75
76
  step2 = scenario.addAssertEqual(`${step1}.res.items[0].artist_name`, 'abc');
76
- skyrampClient.testerStart('test-worker', scenario).then(function() {
77
+ skyrampClient.testerStart('test-worker', '', scenario).then(function() {
77
78
  // Test scenario started
78
79
  }).catch(function(error) {
79
80
  // Error occurred during the test scenario
@@ -81,13 +82,13 @@ skyrampClient.testerStart('test-worker', scenario).then(function() {
81
82
  ```
82
83
 
83
84
  **Example: Test Assert Scenario (gRPC)**
84
- ```bash
85
+ ```javascript
85
86
  scenario = new Scenario('routeguide-assert-test')
86
87
  step1 = scenario.addRequestFromFile(grpcEndpoint, 'GetFeature', 'files/grpc-request.yaml');
87
88
  step2 = scenario.addAssertEqual(`${step1}.res.name`, 'test-feature');
88
- skyrampClient.testerStart('test-worker', scenario).then(function() {
89
+ skyrampClient.testerStart('test-worker', '', scenario).then(function() {
89
90
  // Test scenario started
90
91
  }).catch(function(error) {
91
92
  // Error occurred during the test scenario
92
93
  });
93
- ```
94
+ ```
Binary file
@@ -0,0 +1,118 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/letsramp/dev/cmd/libs */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 7 "client.go"
23
+
24
+ struct oauthresponse {
25
+ char *emails[10]; // for the time being, it is a bit tricky to deal with dynamic array with koffi
26
+ int num_emails;
27
+ char *token;
28
+ char *error;
29
+ };
30
+
31
+ struct credential_response {
32
+ char *email;
33
+ char *user_token;
34
+ char *provider;
35
+ char *error;
36
+ };
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+
41
+
42
+ /* End of preamble from import "C" comments. */
43
+
44
+
45
+ /* Start of boilerplate cgo prologue. */
46
+ #line 1 "cgo-gcc-export-header-prolog"
47
+
48
+ #ifndef GO_CGO_PROLOGUE_H
49
+ #define GO_CGO_PROLOGUE_H
50
+
51
+ typedef signed char GoInt8;
52
+ typedef unsigned char GoUint8;
53
+ typedef short GoInt16;
54
+ typedef unsigned short GoUint16;
55
+ typedef int GoInt32;
56
+ typedef unsigned int GoUint32;
57
+ typedef long long GoInt64;
58
+ typedef unsigned long long GoUint64;
59
+ typedef GoInt64 GoInt;
60
+ typedef GoUint64 GoUint;
61
+ typedef size_t GoUintptr;
62
+ typedef float GoFloat32;
63
+ typedef double GoFloat64;
64
+ #ifdef _MSC_VER
65
+ #include <complex.h>
66
+ typedef _Fcomplex GoComplex64;
67
+ typedef _Dcomplex GoComplex128;
68
+ #else
69
+ typedef float _Complex GoComplex64;
70
+ typedef double _Complex GoComplex128;
71
+ #endif
72
+
73
+ /*
74
+ static assertion to make sure the file is being used on architecture
75
+ at least with matching size of GoInt.
76
+ */
77
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
78
+
79
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
80
+ typedef _GoString_ GoString;
81
+ #endif
82
+ typedef void *GoMap;
83
+ typedef void *GoChan;
84
+ typedef struct { void *t; void *v; } GoInterface;
85
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
86
+
87
+ #endif
88
+
89
+ /* End of boilerplate cgo prologue. */
90
+
91
+ #ifdef __cplusplus
92
+ extern "C" {
93
+ #endif
94
+
95
+ extern char* removeLocalWrapper();
96
+ extern char* removeClusterFromConfigWrapper(char* clusterName);
97
+ extern char* getKubeConfigPath();
98
+ extern char* applyLocalWrapper(char* token);
99
+ extern char* addKubeconfigWrapper(char* context, char* clusterName, char* kubeconfigPath);
100
+ extern char* deploySkyrampWorkerWrapper(char* namespace, char* workerImage, GoUint8 localImage);
101
+ extern char* deleteSkyrampWorkerWrapper(char* namespace);
102
+ extern struct credential_response readCredentialWrapper();
103
+ extern char* getOAuthURLWrapper(char* provider, GoInt port);
104
+ extern char* registerUserWrapper(char* provider, char* email, char* code);
105
+ extern struct oauthresponse runOAuthLoopback(char* provider, GoInt port);
106
+ extern char* validateTokenWrapper(char* userToken);
107
+ extern char* generateUserTokenWrapper(char* provider, char* email, char* oauthToken);
108
+ extern char* newGrpcEndpointWrapper(char* name, char* serviceName, GoInt port, char* inputFile);
109
+ extern char* newRestEndpointWrapper(char* name, char* openApiTag, GoInt port, char* inputFile);
110
+ extern char* writeMockDescriptionWrapper(char* mockDescription, char* kubernetesService);
111
+ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
112
+ extern char* applyMockDescriptionWrapper(char* namespace, char* address, char* mockDescription);
113
+ extern char* buildRequestsWrapper(char* mockDescription);
114
+ extern char* runTesterStartWrapper(char* namespace, char* address, char* testDescription, GoUint8 generateResult);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
Binary file
@@ -0,0 +1,118 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/letsramp/dev/cmd/libs */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 7 "client.go"
23
+
24
+ struct oauthresponse {
25
+ char *emails[10]; // for the time being, it is a bit tricky to deal with dynamic array with koffi
26
+ int num_emails;
27
+ char *token;
28
+ char *error;
29
+ };
30
+
31
+ struct credential_response {
32
+ char *email;
33
+ char *user_token;
34
+ char *provider;
35
+ char *error;
36
+ };
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+
41
+
42
+ /* End of preamble from import "C" comments. */
43
+
44
+
45
+ /* Start of boilerplate cgo prologue. */
46
+ #line 1 "cgo-gcc-export-header-prolog"
47
+
48
+ #ifndef GO_CGO_PROLOGUE_H
49
+ #define GO_CGO_PROLOGUE_H
50
+
51
+ typedef signed char GoInt8;
52
+ typedef unsigned char GoUint8;
53
+ typedef short GoInt16;
54
+ typedef unsigned short GoUint16;
55
+ typedef int GoInt32;
56
+ typedef unsigned int GoUint32;
57
+ typedef long long GoInt64;
58
+ typedef unsigned long long GoUint64;
59
+ typedef GoInt64 GoInt;
60
+ typedef GoUint64 GoUint;
61
+ typedef size_t GoUintptr;
62
+ typedef float GoFloat32;
63
+ typedef double GoFloat64;
64
+ #ifdef _MSC_VER
65
+ #include <complex.h>
66
+ typedef _Fcomplex GoComplex64;
67
+ typedef _Dcomplex GoComplex128;
68
+ #else
69
+ typedef float _Complex GoComplex64;
70
+ typedef double _Complex GoComplex128;
71
+ #endif
72
+
73
+ /*
74
+ static assertion to make sure the file is being used on architecture
75
+ at least with matching size of GoInt.
76
+ */
77
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
78
+
79
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
80
+ typedef _GoString_ GoString;
81
+ #endif
82
+ typedef void *GoMap;
83
+ typedef void *GoChan;
84
+ typedef struct { void *t; void *v; } GoInterface;
85
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
86
+
87
+ #endif
88
+
89
+ /* End of boilerplate cgo prologue. */
90
+
91
+ #ifdef __cplusplus
92
+ extern "C" {
93
+ #endif
94
+
95
+ extern char* removeLocalWrapper();
96
+ extern char* removeClusterFromConfigWrapper(char* clusterName);
97
+ extern char* getKubeConfigPath();
98
+ extern char* applyLocalWrapper(char* token);
99
+ extern char* addKubeconfigWrapper(char* context, char* clusterName, char* kubeconfigPath);
100
+ extern char* deploySkyrampWorkerWrapper(char* namespace, char* workerImage, GoUint8 localImage);
101
+ extern char* deleteSkyrampWorkerWrapper(char* namespace);
102
+ extern struct credential_response readCredentialWrapper();
103
+ extern char* getOAuthURLWrapper(char* provider, GoInt port);
104
+ extern char* registerUserWrapper(char* provider, char* email, char* code);
105
+ extern struct oauthresponse runOAuthLoopback(char* provider, GoInt port);
106
+ extern char* validateTokenWrapper(char* userToken);
107
+ extern char* generateUserTokenWrapper(char* provider, char* email, char* oauthToken);
108
+ extern char* newGrpcEndpointWrapper(char* name, char* serviceName, GoInt port, char* inputFile);
109
+ extern char* newRestEndpointWrapper(char* name, char* openApiTag, GoInt port, char* inputFile);
110
+ extern char* writeMockDescriptionWrapper(char* mockDescription, char* kubernetesService);
111
+ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
112
+ extern char* applyMockDescriptionWrapper(char* namespace, char* address, char* mockDescription);
113
+ extern char* buildRequestsWrapper(char* mockDescription);
114
+ extern char* runTesterStartWrapper(char* namespace, char* address, char* testDescription, GoUint8 generateResult);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
@@ -0,0 +1,118 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/letsramp/dev/cmd/libs */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 7 "client.go"
23
+
24
+ struct oauthresponse {
25
+ char *emails[10]; // for the time being, it is a bit tricky to deal with dynamic array with koffi
26
+ int num_emails;
27
+ char *token;
28
+ char *error;
29
+ };
30
+
31
+ struct credential_response {
32
+ char *email;
33
+ char *user_token;
34
+ char *provider;
35
+ char *error;
36
+ };
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+
41
+
42
+ /* End of preamble from import "C" comments. */
43
+
44
+
45
+ /* Start of boilerplate cgo prologue. */
46
+ #line 1 "cgo-gcc-export-header-prolog"
47
+
48
+ #ifndef GO_CGO_PROLOGUE_H
49
+ #define GO_CGO_PROLOGUE_H
50
+
51
+ typedef signed char GoInt8;
52
+ typedef unsigned char GoUint8;
53
+ typedef short GoInt16;
54
+ typedef unsigned short GoUint16;
55
+ typedef int GoInt32;
56
+ typedef unsigned int GoUint32;
57
+ typedef long long GoInt64;
58
+ typedef unsigned long long GoUint64;
59
+ typedef GoInt32 GoInt;
60
+ typedef GoUint32 GoUint;
61
+ typedef size_t GoUintptr;
62
+ typedef float GoFloat32;
63
+ typedef double GoFloat64;
64
+ #ifdef _MSC_VER
65
+ #include <complex.h>
66
+ typedef _Fcomplex GoComplex64;
67
+ typedef _Dcomplex GoComplex128;
68
+ #else
69
+ typedef float _Complex GoComplex64;
70
+ typedef double _Complex GoComplex128;
71
+ #endif
72
+
73
+ /*
74
+ static assertion to make sure the file is being used on architecture
75
+ at least with matching size of GoInt.
76
+ */
77
+ typedef char _check_for_32_bit_pointer_matching_GoInt[sizeof(void*)==32/8 ? 1:-1];
78
+
79
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
80
+ typedef _GoString_ GoString;
81
+ #endif
82
+ typedef void *GoMap;
83
+ typedef void *GoChan;
84
+ typedef struct { void *t; void *v; } GoInterface;
85
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
86
+
87
+ #endif
88
+
89
+ /* End of boilerplate cgo prologue. */
90
+
91
+ #ifdef __cplusplus
92
+ extern "C" {
93
+ #endif
94
+
95
+ extern char* removeLocalWrapper();
96
+ extern char* removeClusterFromConfigWrapper(char* clusterName);
97
+ extern char* getKubeConfigPath();
98
+ extern char* applyLocalWrapper(char* token);
99
+ extern char* addKubeconfigWrapper(char* context, char* clusterName, char* kubeconfigPath);
100
+ extern char* deploySkyrampWorkerWrapper(char* namespace, char* workerImage, GoUint8 localImage);
101
+ extern char* deleteSkyrampWorkerWrapper(char* namespace);
102
+ extern struct credential_response readCredentialWrapper();
103
+ extern char* getOAuthURLWrapper(char* provider, GoInt port);
104
+ extern char* registerUserWrapper(char* provider, char* email, char* code);
105
+ extern struct oauthresponse runOAuthLoopback(char* provider, GoInt port);
106
+ extern char* validateTokenWrapper(char* userToken);
107
+ extern char* generateUserTokenWrapper(char* provider, char* email, char* oauthToken);
108
+ extern char* newGrpcEndpointWrapper(char* name, char* serviceName, GoInt port, char* inputFile);
109
+ extern char* newRestEndpointWrapper(char* name, char* openApiTag, GoInt port, char* inputFile);
110
+ extern char* writeMockDescriptionWrapper(char* mockDescription, char* kubernetesService);
111
+ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
112
+ extern char* applyMockDescriptionWrapper(char* namespace, char* address, char* mockDescription);
113
+ extern char* buildRequestsWrapper(char* mockDescription);
114
+ extern char* runTesterStartWrapper(char* namespace, char* address, char* testDescription, GoUint8 generateResult);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
Binary file
@@ -0,0 +1,118 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/letsramp/dev/cmd/libs */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 7 "client.go"
23
+
24
+ struct oauthresponse {
25
+ char *emails[10]; // for the time being, it is a bit tricky to deal with dynamic array with koffi
26
+ int num_emails;
27
+ char *token;
28
+ char *error;
29
+ };
30
+
31
+ struct credential_response {
32
+ char *email;
33
+ char *user_token;
34
+ char *provider;
35
+ char *error;
36
+ };
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+
41
+
42
+ /* End of preamble from import "C" comments. */
43
+
44
+
45
+ /* Start of boilerplate cgo prologue. */
46
+ #line 1 "cgo-gcc-export-header-prolog"
47
+
48
+ #ifndef GO_CGO_PROLOGUE_H
49
+ #define GO_CGO_PROLOGUE_H
50
+
51
+ typedef signed char GoInt8;
52
+ typedef unsigned char GoUint8;
53
+ typedef short GoInt16;
54
+ typedef unsigned short GoUint16;
55
+ typedef int GoInt32;
56
+ typedef unsigned int GoUint32;
57
+ typedef long long GoInt64;
58
+ typedef unsigned long long GoUint64;
59
+ typedef GoInt64 GoInt;
60
+ typedef GoUint64 GoUint;
61
+ typedef size_t GoUintptr;
62
+ typedef float GoFloat32;
63
+ typedef double GoFloat64;
64
+ #ifdef _MSC_VER
65
+ #include <complex.h>
66
+ typedef _Fcomplex GoComplex64;
67
+ typedef _Dcomplex GoComplex128;
68
+ #else
69
+ typedef float _Complex GoComplex64;
70
+ typedef double _Complex GoComplex128;
71
+ #endif
72
+
73
+ /*
74
+ static assertion to make sure the file is being used on architecture
75
+ at least with matching size of GoInt.
76
+ */
77
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
78
+
79
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
80
+ typedef _GoString_ GoString;
81
+ #endif
82
+ typedef void *GoMap;
83
+ typedef void *GoChan;
84
+ typedef struct { void *t; void *v; } GoInterface;
85
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
86
+
87
+ #endif
88
+
89
+ /* End of boilerplate cgo prologue. */
90
+
91
+ #ifdef __cplusplus
92
+ extern "C" {
93
+ #endif
94
+
95
+ extern char* removeLocalWrapper();
96
+ extern char* removeClusterFromConfigWrapper(char* clusterName);
97
+ extern char* getKubeConfigPath();
98
+ extern char* applyLocalWrapper(char* token);
99
+ extern char* addKubeconfigWrapper(char* context, char* clusterName, char* kubeconfigPath);
100
+ extern char* deploySkyrampWorkerWrapper(char* namespace, char* workerImage, GoUint8 localImage);
101
+ extern char* deleteSkyrampWorkerWrapper(char* namespace);
102
+ extern struct credential_response readCredentialWrapper();
103
+ extern char* getOAuthURLWrapper(char* provider, GoInt port);
104
+ extern char* registerUserWrapper(char* provider, char* email, char* code);
105
+ extern struct oauthresponse runOAuthLoopback(char* provider, GoInt port);
106
+ extern char* validateTokenWrapper(char* userToken);
107
+ extern char* generateUserTokenWrapper(char* provider, char* email, char* oauthToken);
108
+ extern char* newGrpcEndpointWrapper(char* name, char* serviceName, GoInt port, char* inputFile);
109
+ extern char* newRestEndpointWrapper(char* name, char* openApiTag, GoInt port, char* inputFile);
110
+ extern char* writeMockDescriptionWrapper(char* mockDescription, char* kubernetesService);
111
+ extern char* writeTestDescriptionWrapper(char* testDescription, char* testName);
112
+ extern char* applyMockDescriptionWrapper(char* namespace, char* address, char* mockDescription);
113
+ extern char* buildRequestsWrapper(char* mockDescription);
114
+ extern char* runTesterStartWrapper(char* namespace, char* address, char* testDescription, GoUint8 generateResult);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
Binary file
Binary file
@@ -0,0 +1,118 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/letsramp/dev/cmd/libs */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 7 "client.go"
23
+
24
+ struct oauthresponse {
25
+ char *emails[10]; // for the time being, it is a bit tricky to deal with dynamic array with koffi
26
+ int num_emails;
27
+ char *token;
28
+ char *error;
29
+ };
30
+
31
+ struct credential_response {
32
+ char *email;
33
+ char *user_token;
34
+ char *provider;
35
+ char *error;
36
+ };
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+
41
+
42
+ /* End of preamble from import "C" comments. */
43
+
44
+
45
+ /* Start of boilerplate cgo prologue. */
46
+ #line 1 "cgo-gcc-export-header-prolog"
47
+
48
+ #ifndef GO_CGO_PROLOGUE_H
49
+ #define GO_CGO_PROLOGUE_H
50
+
51
+ typedef signed char GoInt8;
52
+ typedef unsigned char GoUint8;
53
+ typedef short GoInt16;
54
+ typedef unsigned short GoUint16;
55
+ typedef int GoInt32;
56
+ typedef unsigned int GoUint32;
57
+ typedef long long GoInt64;
58
+ typedef unsigned long long GoUint64;
59
+ typedef GoInt64 GoInt;
60
+ typedef GoUint64 GoUint;
61
+ typedef size_t GoUintptr;
62
+ typedef float GoFloat32;
63
+ typedef double GoFloat64;
64
+ #ifdef _MSC_VER
65
+ #include <complex.h>
66
+ typedef _Fcomplex GoComplex64;
67
+ typedef _Dcomplex GoComplex128;
68
+ #else
69
+ typedef float _Complex GoComplex64;
70
+ typedef double _Complex GoComplex128;
71
+ #endif
72
+
73
+ /*
74
+ static assertion to make sure the file is being used on architecture
75
+ at least with matching size of GoInt.
76
+ */
77
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
78
+
79
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
80
+ typedef _GoString_ GoString;
81
+ #endif
82
+ typedef void *GoMap;
83
+ typedef void *GoChan;
84
+ typedef struct { void *t; void *v; } GoInterface;
85
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
86
+
87
+ #endif
88
+
89
+ /* End of boilerplate cgo prologue. */
90
+
91
+ #ifdef __cplusplus
92
+ extern "C" {
93
+ #endif
94
+
95
+ extern __declspec(dllexport) char* removeLocalWrapper();
96
+ extern __declspec(dllexport) char* removeClusterFromConfigWrapper(char* clusterName);
97
+ extern __declspec(dllexport) char* getKubeConfigPath();
98
+ extern __declspec(dllexport) char* applyLocalWrapper(char* token);
99
+ extern __declspec(dllexport) char* addKubeconfigWrapper(char* context, char* clusterName, char* kubeconfigPath);
100
+ extern __declspec(dllexport) char* deploySkyrampWorkerWrapper(char* namespace, char* workerImage, GoUint8 localImage);
101
+ extern __declspec(dllexport) char* deleteSkyrampWorkerWrapper(char* namespace);
102
+ extern __declspec(dllexport) struct credential_response readCredentialWrapper();
103
+ extern __declspec(dllexport) char* getOAuthURLWrapper(char* provider, GoInt port);
104
+ extern __declspec(dllexport) char* registerUserWrapper(char* provider, char* email, char* code);
105
+ extern __declspec(dllexport) struct oauthresponse runOAuthLoopback(char* provider, GoInt port);
106
+ extern __declspec(dllexport) char* validateTokenWrapper(char* userToken);
107
+ extern __declspec(dllexport) char* generateUserTokenWrapper(char* provider, char* email, char* oauthToken);
108
+ extern __declspec(dllexport) char* newGrpcEndpointWrapper(char* name, char* serviceName, GoInt port, char* inputFile);
109
+ extern __declspec(dllexport) char* newRestEndpointWrapper(char* name, char* openApiTag, GoInt port, char* inputFile);
110
+ extern __declspec(dllexport) char* writeMockDescriptionWrapper(char* mockDescription, char* kubernetesService);
111
+ extern __declspec(dllexport) char* writeTestDescriptionWrapper(char* testDescription, char* testName);
112
+ extern __declspec(dllexport) char* applyMockDescriptionWrapper(char* namespace, char* address, char* mockDescription);
113
+ extern __declspec(dllexport) char* buildRequestsWrapper(char* mockDescription);
114
+ extern __declspec(dllexport) char* runTesterStartWrapper(char* namespace, char* address, char* testDescription, GoUint8 generateResult);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyramp/skyramp",
3
- "version": "0.4.32",
3
+ "version": "0.4.35",
4
4
  "description": "module for leveraging skyramp cli functionality",
5
5
  "scripts": {
6
6
  "pack": "npm pack"
@@ -1,12 +1,11 @@
1
1
  import { Endpoint } from './Endpoint';
2
2
  import { Scenario } from './Scenario';
3
3
  export declare class SkyrampClient {
4
- constructor(kubeconfigPath?: string, clusterName?: string, context?: string);
4
+ constructor(kubeconfigPath?: string, clusterName?: string, context?: string, userToken?: string);
5
5
  applyLocal(): Promise<void>;
6
6
  addKubeconfig(context: string, clusterName: string, kubeconfigPath: string): Promise<void>;
7
- removeCluster(clusterName?: string): Promise<void>;
8
7
  removeLocal(): Promise<void>;
9
- removeClusterFromConfig(clusterName: string): Promise<void>;
8
+ removeCluster(clusterName?: string): Promise<void>;
10
9
  mockerApply(namespace: string, address: string, endpoint: Endpoint): Promise<void>;
11
10
 
12
11
  mockerApplyFromFile(namespace: string, address: string, filePath: string): Promise<void>;
@@ -14,4 +13,19 @@ export declare class SkyrampClient {
14
13
  testerStart(namespace: string, address: string, scenario: Scenario): Promise<void>;
15
14
  testerStartFromFile(namespace: string, address: string, filePath: string): Promise<void>;
16
15
  runTesterStart(namespace: string, address: string, testYamlContent: string, generateReport: boolean): Promise<void>;
16
+
17
+ // login / oauth related
18
+ userEmail: string;
19
+ userToken: string;
20
+ userProvider: string;
21
+ getUserToken(): string;
22
+ getUserEmail(): string;
23
+ getUserProvider(): string;
24
+
25
+ setUserToken(userToken: string): void;
26
+ validateToken(userToken: string): Promise<any>;
27
+ readCredential(): Promise<any>;
28
+ getOAuthURL(provider: string, port: number): string;
29
+ runOAuthLoopback(provider: string, port: number): Promise<any>;
30
+ registerUser(provider: string, email: string, oauthToken: string): Promise<string>;
17
31
  }
@@ -1,6 +1,22 @@
1
1
  const lib = require('../lib');
2
+ const koffi = require('koffi');
3
+
4
+ const oauthResponseType = koffi.struct({
5
+ emails: koffi.array('char*', 10),
6
+ num_emails: 'int',
7
+ token: 'char*',
8
+ error: 'char*'
9
+ });
10
+
11
+ const credResponseType = koffi.struct({
12
+ email: 'char*',
13
+ user_token: 'char*',
14
+ provider: 'char*',
15
+ error: 'char*',
16
+ });
17
+
2
18
  const { createTestDescriptionFromScenario, getYamlBytes, readDataFromFile } = require('../utils');
3
- const applyLocalWrapper = lib.func('applyLocalWrapper', 'string', []);
19
+ const applyLocalWrapper = lib.func('applyLocalWrapper', 'string', ['string']);
4
20
  const addKubeconfigWrapper = lib.func('addKubeconfigWrapper', 'string', ['string', 'bool', 'string', 'string']);
5
21
  const deleteSkyrampWorkerWrapper = lib.func('deleteSkyrampWorkerWrapper', 'string', ['string'])
6
22
  const deploySkyrampWorkerWrapper = lib.func('deploySkyrampWorkerWrapper', 'string', ['string', 'string', 'bool']);
@@ -10,17 +26,108 @@ const removeClusterFromConfigWrapper = lib.func('removeClusterFromConfigWrapper'
10
26
  const runTesterStartWrapper = lib.func('runTesterStartWrapper', 'string', ['string', 'string', 'string', 'bool']);
11
27
  const applyMockDescriptionWrapper = lib.func('applyMockDescriptionWrapper', 'string', ['string', 'string', 'string']);
12
28
 
29
+ // credential / oauth related
30
+ const readCredentialWrapper = lib.func('readCredentialWrapper', credResponseType, []);
31
+ const validateTokenWrapper = lib.func('validateTokenWrapper', 'string', ['string']);
32
+ const registerUserWrapper = lib.func('registerUserWrapper', 'string', ['string', 'string', 'string']);
33
+ const getOAuthURL = lib.func('getOAuthURLWrapper', 'string', ['string', 'int']);
34
+ const runOAuthLoopback = lib.func('runOAuthLoopback', oauthResponseType, ['string', 'int']);
35
+
13
36
  class SkyrampClient {
14
- constructor(kubeconfigPath, clusterName, context) {
15
- this.workerNamespaces = [];
37
+ constructor(kubeconfigPath, clusterName, context, userToken) {
16
38
  if (kubeconfigPath || clusterName || context) {
17
39
  this.addKubeconfig(clusterName, context, kubeconfigPath);
18
40
  }
41
+ this.workerNamespaces = [];
42
+ this.userToken = userToken;
43
+ }
44
+
45
+ setUserToken(userToken) {
46
+ this.userToken = userToken;
47
+ }
48
+
49
+ getOAuthURL(provider, port) {
50
+ return getOAuthURL(provider, port);
51
+ }
52
+
53
+ getUserEmail() {
54
+ return this.userEmail;
55
+ }
56
+
57
+ getUserToken() {
58
+ return this.userToken;
59
+ }
60
+
61
+ getUserProvider() {
62
+ return this.userProvider;
63
+ }
64
+
65
+ async readCredential() {
66
+ return new Promise((resolve, reject) => {
67
+ readCredentialWrapper.async((err, res) => {
68
+ if (err) {
69
+ reject(err);
70
+ } else if (res) {
71
+ if (res.error != null) {
72
+ reject(res.error);
73
+ } else {
74
+ this.userToken = res.user_token;
75
+ this.userEmail = res.email;
76
+ this.userProvider = res.provider;
77
+ resolve(res);
78
+ }
79
+ } else {
80
+ reject(new Error('failed to read credential'));
81
+ }
82
+ });
83
+ });
84
+ }
85
+
86
+ async runOAuthLoopback(provider, port) {
87
+ return new Promise((resolve, reject) => {
88
+ runOAuthLoopback.async(provider, port, (err, res) => {
89
+ if (err) {
90
+ reject(err);
91
+ } else if (res) {
92
+ resolve(res);
93
+ } else {
94
+ reject(new Error("failed to get oauth token"));
95
+ }
96
+ });
97
+ });
98
+ }
99
+
100
+ async validateToken(userToken) {
101
+ return new Promise((resolve, reject) => {
102
+ validateTokenWrapper.async(userToken, (err, res) => {
103
+ if (err) {
104
+ reject(err);
105
+ } else if (res) {
106
+ resolve(new Error(res));
107
+ } else {
108
+ resolve();
109
+ }
110
+ });
111
+ });
112
+ }
113
+
114
+ async registerUser(provider, email, oauthToken) {
115
+ return new Promise((resolve, reject) => {
116
+ registerUserWrapper.async(provider, email, oauthToken, (err, res) => {
117
+ if (err) {
118
+ reject(err);
119
+ } else if (res) {
120
+ reject(new Error(res));
121
+ } else {
122
+ resolve();
123
+ }
124
+ });
125
+ });
19
126
  }
20
127
 
21
128
  async applyLocal() {
22
129
  return new Promise((resolve, reject) => {
23
- applyLocalWrapper.async((err, res) => {
130
+ applyLocalWrapper.async(this.userToken, (err, res) => {
24
131
  if (err) {
25
132
  reject(err);
26
133
  } else if (res) {
@@ -28,9 +135,9 @@ class SkyrampClient {
28
135
  } else {
29
136
  this.kubeConfigPath = getKubeConfigPath();
30
137
  if (this.kubeConfigPath == "") {
31
- reject(new Error("no kubeconfig found"));
138
+ reject(new Error("no kubeconfig found"));
32
139
  } else {
33
- resolve();
140
+ resolve();
34
141
  }
35
142
  }
36
143
  });
@@ -52,14 +159,6 @@ class SkyrampClient {
52
159
  });
53
160
  }
54
161
 
55
- async removeCluster(clusterName) {
56
- if (clusterName) {
57
- return this.removeClusterFromConfig(clusterName);
58
- } else {
59
- return this.removeLocal();
60
- }
61
- }
62
-
63
162
  async removeLocal() {
64
163
  return new Promise((resolve, reject) => {
65
164
  removeLocalWrapper.async((err, res) => {
@@ -74,7 +173,7 @@ class SkyrampClient {
74
173
  });
75
174
  }
76
175
 
77
- async removeClusterFromConfig(clusterName) {
176
+ async removeCluster(clusterName) {
78
177
  return new Promise((resolve, reject) => {
79
178
  removeClusterFromConfigWrapper.async(clusterName, (err, res) => {
80
179
  if (err) {
package/src/lib.js CHANGED
@@ -27,4 +27,4 @@ if (!libPath) {
27
27
  const libFullPath = path.join(__dirname, '..', 'lib', libPath);
28
28
  const lib = koffi.load(libFullPath);
29
29
 
30
- module.exports = lib;
30
+ module.exports = lib;