Skip to content

Commit

Permalink
Merge pull request #3 from itential/change_output
Browse files Browse the repository at this point in the history
Change output
  • Loading branch information
ishitaprakash3112 committed Aug 14, 2023
2 parents e263529 + 9af5062 commit 35a801e
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 69 deletions.
46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ For new customers interested in an Itential trial, please click [here](https://w
1. Search for the Action on Github Marketplace.
2. Select the "Use the Latest Version" option on the top right of the screen.
3. Click the clipboard icon to copy the provided data.
4. Navigate to the '.github/workflows' file in the target repository (where you intend on using the action).
5. Paste the copied data in the correlating fields.
6. Configure the required inputs and optional inputs. (See note)
7. Save it as a main.yml file.

Sample
```
- name: itential-automation-start
uses: itential/itential-automation-start@0.0.1
```
4. Navigate to the '.github/workflows' folder in the target repository (where you intend on using the action).
5. Paste the copied data in the correlating fields of your workflow file.
6. Configure the required inputs and optional inputs. (See Note and [Configurations](#configurations))
7. Save the file with a (.yml) extension.

_For a sample workflow file, see [Example Usage](#example-usage)._

> **_Note:_** Users may manually enter required input parameters or use Github Secrets if they want to hide certain parameters. If you choose to use Github Secrets, please reference the instructions provided below.
Expand All @@ -48,6 +56,8 @@ For new customers interested in an Itential trial, please click [here](https://w
For SECRET enter your desired variable.
5. Click "Add Secret"

_For more information about Github Action secrets, see [Github Secrets](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28)_

_For more information about Github Actions variables, see [variables](https://docs.github.com/en/actions/learn-github-actions/variables)_

## Configurations
Expand All @@ -58,13 +68,15 @@ _For more information about connecting to private network, see [Connecting to a

### Required Input Parameters

The following table defines the required input parameters to run an Itential automation using a Github workflow.Input data is provided through Github Actions secrets. For more information about github action secrets, see [Github Secrets](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28)
The following table defines the required input parameters to run an Itential automation using a Github workflow.

| Parameter | Description |
| ----------------- | ------------------------------------------------ |
| itential_host_url | URL to the Itential Instance. |
| api_endpoint | API endpoint name to start an automation. |
| api_endpoint_body | The POST body used to create the workflow input. |
_For more information on Itential's API endpoint, see [here]( https://apidocs.itential.com/api/app-operations_manager/runEndpointTriggerWithPost/)._

| Parameter | Description |
| ----------------- | ------------------------------------------------------------------|
| itential_host_url | URL to the Itential Instance. |
| api_endpoint | API endpoint route name to start an automation. |
| api_endpoint_body | The POST body used to provide the input values for the automation |

### Required Authentication Parameters

Expand Down Expand Up @@ -108,10 +120,22 @@ The following table defines three parameters considered optional.

### Output

The following table defines parameters that are returned. The output is returned as an object with two keys - automation_status and automation_output.

| Parameter | Description |
| --------- | --------------------------------- |
| results | Automation Start output variables |

Sample Output

```
{
"automation_id": 4569ghffhgfdhg67,
"automation_status": "running",
"automation_output": null
}
```

## Example Usage

The example below displays how to configure a workflow that runs when issues or pull requests are opened or labeled in your repository. This workflow runs when new pull request is opened as defined in the `on` variable of the workflow.
Expand Down Expand Up @@ -145,7 +169,7 @@ jobs:
uses: actions/checkout@v3
- name: Itential Automation Start action step
id: step1
uses: itential/itential-automation-start@version_number
uses: itential/itential-automation-start@replace_with_latest_version
with:
#github_token: ${{secrets.GITHUB_TOKEN}} # include only if user requires a GitHub Token
itential_host_url: ${{secrets.ITENTIAL_HOST_URL}}
Expand Down
97 changes: 64 additions & 33 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10852,10 +10852,8 @@ class Authentication {
// if dynamic token
// will have understand the units followed in res for expires_in and accordingly modify the logic
const timeNow = new Date();
console.log('time now', timeNow);
console.log('time left to expire', this.users[indx].expires_in - timeNow);
timeNow.setMinutes(timeNow.getMinutes() + 1);
console.log('after inc', timeNow);

if (this.users[indx].expires_in <= timeNow) {
console.log('Token expired');
return false;
Expand All @@ -10877,11 +10875,10 @@ class Authentication {
const res = await lib_axios.post(url, data);
this.users[indx].token = res.data;
const timeNow = new Date();
console.log('time now', timeNow);

//setting the efault expiry duration since the responsed does not provide an appropriate expiry duration
this.users[indx].expires_in = timeNow.setMinutes(timeNow.getMinutes() + this.default_expiry_duration);
console.log('expiry set to ', timeNow);
console.log('the new token', this.users[indx].expires_in);

return callback(this.users[indx].token);
} catch (err) {
const error = this.utils.formatErrorObject("authentication-getNewPasswToken", "Error when fetching or renewing a token", null, null, null, err);
Expand All @@ -10903,11 +10900,10 @@ class Authentication {
const res = await lib_axios.post(url, data);
this.users[indx].token = res.data; // update the token in the list
const timeNow = new Date();
console.log('time now', timeNow);

//setting the efault expiry duration since the responsed does not provide an appropriate expiry duration
this.users[indx].expires_in = timeNow.setMinutes(timeNow.getMinutes() + this.default_expiry_duration);
console.log('expiry set to ', timeNow);
console.log('the renewed token ', this.users[indx].token);

return callback(this.users[indx].token);
} catch (err) {
const error = this.utils.formatErrorObject("authentication-renewPasswToken", "Error when fetching or renewing a token", null, null, null, err);
Expand Down Expand Up @@ -10966,7 +10962,6 @@ class Authentication {
const timeNow = new Date();
timeNow.setSeconds(timeNow.getSeconds() + res.data.expires_in);
this.users[indx].expires_in = timeNow;
console.log('expiry of renewed Token', timeNow);
return callback(this.users[indx].token);
} catch (err) {
const error = this.utils.formatErrorObject("authentication-renewOAuthToken", "Error when fetching or renewing an OAuth token", null, null, null, err);
Expand Down Expand Up @@ -11021,10 +11016,10 @@ class Authentication {
// oauth user, get new token
await this.getNewOAuthToken(indx, (res, err) => {
if (err) {
console.log('got error here');

return callback(null, err);
}
console.log('not here');

token_object.token = res;
return callback(token_object);
});
Expand Down Expand Up @@ -11059,7 +11054,7 @@ class Authentication {
basic: false,
staticToken: false
};
// console.log(user);

if (!Object.prototype.hasOwnProperty.call(user, 'hostname') || !user.hostname.length) {
errorMessage = 'For authentication, manadatory property \'hostname\' is missing';
} else {
Expand All @@ -11077,7 +11072,7 @@ class Authentication {
}

if (errorMessage.length > 0) {
// console.log(errorMessage);

user.errorMessage = errorMessage;
} else {
//a valid user will have the the authType property now
Expand All @@ -11096,10 +11091,10 @@ class Authentication {

if(!Object.prototype.hasOwnProperty.call(checkUser, 'validity') || checkUser.validity === false){
const user = this.checkValidUser(checkUser);
// console.log(user);

const valid = Object.prototype.hasOwnProperty.call(user, 'authType');
user.validity = valid;
// console.log(valid);

if (valid) {
//if valid user add the additional properties as per the auth type
if (user.hostname.endsWith('/')){
Expand Down Expand Up @@ -11223,7 +11218,7 @@ class GenericAPI {
method,
data,
url:
`${this.baseURL}${hyperSchema}${href}${query}token=${token_object.token_object}`
`${this.baseURL}${hyperSchema}${href}${query}token=${token_object.token}`
};

} else if (method === 'GET') {
Expand All @@ -11248,6 +11243,7 @@ class GenericAPI {
}
}
}

;// CONCATENATED MODULE: ./node_modules/ea-utils/lib/formsApi.js


Expand Down Expand Up @@ -11746,8 +11742,14 @@ async function run() {
authentication.users[0].token
)
.then((res) => {

const result = {
automation_id: automation_id,
automation_status: null,
automation_output: null
}
console.log("Automation Status: ", res.data.status);
if (res.data.status === "running" && count < no_of_attempts) {
if ((res.data.status === "running" || res.data.status === "paused" ) && count < no_of_attempts) {
console.log(" Getting Status Attempt # ", count);
setTimeout(() => {
count += 1;
Expand All @@ -11759,19 +11761,23 @@ async function run() {
authentication.users[0].token
)
.then((res) => {
(0,core.setOutput)("results", res.data);
result.automation_status = res.data.status;
result.automation_output = res.data;
(0,core.setOutput)("results", result);
})
.catch((err) => {
(0,core.setFailed)(err.response.data);
});
} else if (res.data.status === "canceled") {
(0,core.setFailed)("Automation Canceled");
result.automation_status = res.data.status;
(0,core.setOutput)("results", result);
} else if (res.data.status === "error") {
(0,core.setFailed)(res.data.error);
result.automation_status = res.data.status;
(0,core.setOutput)("results", result);
} else {
(0,core.setFailed)(
"Automation Timed out based upon user defined time_interval and no_of_attempts"
);
console.log('Automation Timed out based upon user defined time_interval and no_of_attempts');
result.automation_status = res.data.status;
(0,core.setOutput)("results", result);
}
})
.catch((err) => {
Expand All @@ -11790,23 +11796,34 @@ async function run() {
} else (0,core.setFailed)("Failed while getting automation result: " + message);

} else {

const result = {
automation_id: automation_id,
automation_status: null,
automation_output: null
}

console.log("Automation Status: ", res.status);
if (res.status === "running" && count < no_of_attempts) {
if ((res.status === "running" || res.status === "paused") && count < no_of_attempts) {
console.log(" Getting Status Attempt # ", count);
setTimeout(() => {
count += 1;
automationStatus221(automation_id);
}, time_interval * 1000);
} else if (res.status === "complete") {
(0,core.setOutput)("results", res.variables);
result.automation_status = res.status;
result.automation_output = res.variables;
(0,core.setOutput)("results", result);
} else if (res.status === "canceled") {
(0,core.setFailed)("Automation Canceled");
result.automation_status = res.status;
(0,core.setOutput)("results", result);
} else if (res.status === "error") {
(0,core.setFailed)(res.error);
result.automation_status = res.status;
(0,core.setOutput)("results", result);
} else {
(0,core.setFailed)(
'Automation Timed out based upon user defined time_interval and no_of_attempts'
);
console.log('Automation Timed out based upon user defined time_interval and no_of_attempts');
result.automation_status = res.status;
(0,core.setOutput)("results", result);
}

}
Expand Down Expand Up @@ -11847,13 +11864,27 @@ async function run() {

} else (0,core.setFailed)("Failed while starting automation: " + message);
}else {

const result = {
automation_id: null,
automation_status: null,
automation_output: null
}

if (Boolean(Number(automation_status)) === true) {
if (Number(release) <= 2021.1) automationStatus211(res._id);
else automationStatus221(res.data._id);
}
else {
if (Number(release) <= 2021.1) (0,core.setOutput)("results", res._id);
else (0,core.setOutput)("results", res.data._id);
//automation_status set to 0
if (Number(release) <= 2021.1){
result.automation_id = res._id;
(0,core.setOutput)("results", result);
}
else{
result.automation_id = res.data._id
;(0,core.setOutput)("results", result);
}
}
}
});
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@actions/github": "^5.1.1",
"@vercel/ncc": "^0.36.0",
"axios": "^1.2.1",
"ea-utils": "gitlab:itential/northbound-integrations/ea-utils#v0.0.37"
"ea-utils": "gitlab:itential/northbound-integrations/ea-utils#v0.0.39"
}
}

0 comments on commit 35a801e

Please sign in to comment.