Skip to content

Commit

Permalink
Enterprise Store endpoints added.
Browse files Browse the repository at this point in the history
Curl logging added

Npm modules upgraded
  • Loading branch information
tosbaha committed May 9, 2022
1 parent 96dad07 commit d9249e9
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 132 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

### [1.0.3](https://github.com/appcircleio/appcircle-cli/compare/v1.0.2...v1.0.3) (2022-04-29)

**Added**

- Enterprise endpoints added
- [x] List Enterprise profiles
- [x] List Enterprise app versions
- [x] Publish Enterprise app version
- [x] Unpublish Enterprise app version
- [x] Remove Enterprise app version
- [x] Notify Enterprise app version
- [x] Upload Enterprise app version for a profile
- [x] Upload Enterprise app version without a profile
- [x] Get enterprise app download link
- Logging requests as curl command added
- `Appcircle CLI` User Agent added for requests
- Upgraded *axios* to `0.27.1`
- Upgraded *minimist* to `1.2.5`
- Upgraded *moment* to `2.29.1`
- Upgraded *strip-ansi* to `6.0.1` with selective dependency resolution

**Removed**

- *yargs* package was removed since it's not being used.

**Fixed**

- Error handling code is updated to remove warnings.


### [1.0.2](https://github.com/appcircleio/appcircle-cli/compare/v1.0.1...v1.0.2) (2022-02-08)

**Added**

- Upgraded axios dependency
- Added listBuildProfileWorkflows command
- `workflow` parameter added for the build command
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ Below is the list of commands currently supported by Appcircle CLI:
| `appcircle createEnvironmentVariableGroup [--name]` | Create an environment variable group |
| `appcircle listEnvironmentVariables [--variableGroupId]` | Get list of environment variables |
| `appcircle createEnvironmentVariable [--type] [-isSecret, --isSecret] [--variableGroupId] [--key] [--value] [--filePath]` | Create a file or text environment variable |
| `appcircle listEnterpriseProfiles` | List Enterprise profiles |
| `appcircle listEnterpriseAppVersions [--entProfileId] ` | List Enterprise app versions |
| `appcircle publishEnterpriseAppVersion [--entProfileId] [--entVersionId] [--entVersionId] [--summary] [--releaseNotes] [--publishType]` | Publish Enterprise app version |
| `appcircle publishEnterpriseAppVersion [--entProfileId] [--entVersionId]` | Unpublish Enterprise app version |
| `appcircle removeEnterpriseAppVersion [--entProfileId] [--entVersionId]` | Remove Enterprise app version |
| `appcircle notifyEnterpriseAppVersion [--entProfileId] [--entVersionId] [--subject] [--message]` | Notify Enterprise app version |
| `appcircle uploadEnterpriseApp [--app] ` | Upload Enterprise app version without a profile |
| `appcircle uploadEnterpriseAppVersion [--entProfileId] [--app] ` |Upload enterprise app version for a profile |
| `appcircle getEnterpriseDownloadLink [--entProfileId] [--entVersionId]` |Get enterprise app download link |

## Logging requests
If you want to log the requests as `curl` commands you can start appcircle CLI by setting the `CURL_LOGGING` environment variable.

Example:

```
CURL_LOGGING= appcircle
```

## How to Connect your Appcircle Account within CLI?
- [Generate a personal access token from the Appcircle dashboard](https://docs.appcircle.io/appcircle-api/api-authentication)
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appcircle/cli",
"version": "1.0.2",
"version": "1.0.3",
"description": "CLI tool for running Appcircle services from the command line",
"main": "bin/appcircle",
"bin": {
Expand Down Expand Up @@ -29,22 +29,24 @@
},
"homepage": "https://github.com/appcircleio/appcircle-cli#readme",
"dependencies": {
"axios": "^0.25.0",
"axios": "^0.27.1",
"chalk": "^4.1.1",
"commander": "^7.1.0",
"enquirer": "^2.3.6",
"esm": "^3.2.25",
"form-data": "^4.0.0",
"jsonfile": "^6.1.0",
"minimist": "^1.2.5",
"moment": "^2.29.1",
"ora": "^5.4.0",
"yargs": "^16.2.0"
"minimist": "^1.2.6",
"moment": "^2.29.3",
"ora": "^5.4.0"
},
"files": [
"bin/",
"dist/"
],
"resolutions": {
"ora/strip-ansi": "6.0.1"
},
"devDependencies": {
"@types/jsonfile": "^6.0.0",
"@types/minimist": "^1.2.1",
Expand Down
141 changes: 141 additions & 0 deletions src/curlhelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import type { AxiosRequestConfig } from "axios";
import FormData from 'form-data';
const commonHeaders = ["common", "delete", "get", "head", "patch", "post", "put"]
export default class CurlHelper {
private request: AxiosRequestConfig;
constructor(config: AxiosRequestConfig) {
this.request = config;
}

getHeaders() {
let headers = this.request.headers,
curlHeaders = "";

//@ts-ignore
if (headers.hasOwnProperty("common") && this.request.method) {
//@ts-ignore
headers = this.request.headers[this.request.method];
}

for (let property in this.request.headers) {
if (!commonHeaders.includes(property)) {
//@ts-ignore
headers[property] = this.request.headers[property];
}
}

for (let property in headers) {
if ({}.hasOwnProperty.call(headers, property)) {

if (this.request.data instanceof FormData && (/^content-type$/i).test(property)) {
continue;
}

let header = `${property}:${headers[property]}`;
curlHeaders = `${curlHeaders} -H "${header}"`;
}
}

return curlHeaders.trim();
}

getMethod() {
return `-X ${(this.request.method ?? "UNKNOWN").toUpperCase()}`;
}

parseFormData = (form: any) => form._streams.reduce((result: any, line: any) => {

if (typeof line === 'string') {
const key = line?.match(/\sname="(.*?)"/)?.[1];
const filename = line?.match(/filename="(.*?)"/)?.[1];
if (key) {
result._currentKey = key;
if (key === 'File') {
result[result._currentKey] = filename;
result['postData'] += ` -F "${key}=@${filename}"`;;
delete result._currentKey;
}
} else if (line !== '\\r\\n') {
result[result._currentKey] = line;
result['postData'] += ` -F "${result._currentKey}=${line}"`;
delete result._currentKey;
}
}
return result;
}, { postData: '' });

getBody() {
if (
typeof this.request.data !== "undefined" &&
this.request.data !== "" &&
this.request.data !== null &&
(this.request.method ?? "UNKNOWN").toUpperCase() !== "GET"
) {
if (this.request.data instanceof FormData) {
const formObjects = JSON.parse(JSON.stringify(this.request.data));
const obj = this.parseFormData(formObjects);
return obj.postData;
}
let data =
typeof this.request.data === "object" ||
Object.prototype.toString.call(this.request.data) === "[object Array]"
? JSON.stringify(this.request.data)
: this.request.data;
return `--data '${data}'`.trim();
} else {
return "";
}
}

getUrl(): string | undefined {
if (this.request.baseURL) {
let baseUrl = this.request.baseURL
let url = this.request.url
let finalUrl = baseUrl + "/" + url
return finalUrl
.replace(/\/{2,}/g, '/')
.replace("http:/", "http://")
.replace("https:/", "https://")
}
return this.request.url;
}

getQueryString() {
if (this.request.paramsSerializer) {
const params = this.request.paramsSerializer(this.request.params)
if (!params || params.length === 0) return ''
if (params.startsWith('?')) return params
return `?${params}`
}
let params = ""
let i = 0

for (let param in this.request.params) {
if ({}.hasOwnProperty.call(this.request.params, param)) {
params +=
i !== 0
? `&${param}=${this.request.params[param]}`
: `?${param}=${this.request.params[param]}`;
i++;
}
}

return params;
}

getBuiltURL() {
let url = this.getUrl();

if (this.getQueryString() !== "") {
url += this.getQueryString();
}

return (url ?? "UNKNOWN_URL").trim();
}

generateCommand() {
return `curl ${this.getMethod()} "${this.getBuiltURL()}" ${this.getHeaders()} ${this.getBody()}`
.trim()
.replace(/\s{2,}/g, " ");
}
}
Loading

0 comments on commit d9249e9

Please sign in to comment.