Repository: oxctl/lti-auto-configuration
Pull request #40: Allow the tool to not be added
Author: login: buckett
Created: 2025-04-02T12:51:56Z | Merged: 2025-04-02T14:37:16Z

When deploying new tools you sometimes don't want the tool to be made available to users. This change allows the `canvas_account_id` to be set to `none` which causes it to no longer add or update the external tool.


Diff:
diff --git a/README.md b/README.md
index 2cc86a8..5f1686f 100644
--- a/README.md
+++ b/README.md
@@ -189,3 +189,18 @@ Bumping up the version with `npm version` and pushing those changes should resul
 npm version patch
 git push && git push --tags
 ```
+
+# Notes
+
+## Disabling adding tool to sub-account
+
+If you don't want a tool to be added to a sub-account you can set the `canvas_account_id` configuration to `none`. This can be useful when initially releasing a tool to a production instance and you wish to have more control over when end users see it.
+## Automatic Variables
+
+The following variables are automatically set by the tool and can be used in the configuration:
+
+ - `canvas_provider_url` - The URL of the LTI 1.3 initation endpoint for the Canvas instance.
+ - `lti_dev_id` - The LTI developer key Client ID.
+ - `lti_dev_key` - The LTI developer key Client secret.
+ - `api_dev_id` - The API developer key Client ID.
+ - `api_dev_key` - The API developer key Client secret.
\ No newline at end of file
diff --git a/bin/index.js b/bin/index.js
index 1ca75ed..1295fed 100755
--- a/bin/index.js
+++ b/bin/index.js
@@ -344,8 +344,10 @@ program
 
 
             // Finally we just need to add the LTI tool to the testing subaccount
-            const externalTool = await canvas.addLtiToolToSubaccount(ltiDevId, canvasAccountId);
-            console.log(`LTI tool with id ${ltiDevId} added to the sub-account ${canvasAccountId} on ${canvasUrl}.`);
+            if (canvasAccountId !== 'none') {
+                await canvas.addLtiToolToSubaccount(ltiDevId, canvasAccountId);
+                console.log(`LTI tool with id ${ltiDevId} added to the sub-account ${canvasAccountId} on ${canvasUrl}.`);
+            }
         }
     )
 program
@@ -555,14 +557,16 @@ program
             console.log(`API developer key enabled with id ${apiDevId}`);
         }
 
-        const ltiTools = await canvas.getLtiTools(canvasAccountId);
-        const canvasLtiKeyId = ltiToolRegistration.lti.clientId;
-        // For local tools the external tools API uses the shorter ID.
-        const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
-        const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
-        if (!ltiTool) {
-            await canvas.addLtiToolToSubaccount(ltiDevId, canvasAccountId);
-            console.log(`LTI tool with id ${ltiDevId} added to the sub-account ${canvasAccountId} on ${canvasUrl}.`);
+        if (canvasAccountId !== 'none') {
+            const ltiTools = await canvas.getLtiTools(canvasAccountId);
+            const canvasLtiKeyId = ltiToolRegistration.lti.clientId;
+            // For local tools the external tools API uses the shorter ID.
+            const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
+            const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
+            if (!ltiTool) {
+                await canvas.addLtiToolToSubaccount(ltiDevId, canvasAccountId);
+                console.log(`LTI tool with id ${ltiDevId} added to the sub-account ${canvasAccountId} on ${canvasUrl}.`);
+            }
         }
     })
 
@@ -615,17 +619,18 @@ program
             const ltiKey = developerKeys.find(key => key.id === canvasLtiKeyId);
             if (ltiKey) {
                 console.log(`Found LTI developer key ${canvasLtiKeyId}`)
-                const ltiTools = await canvas.getLtiTools(canvasAccountId);
-                // For local tools the external tools API uses the shorter ID.
-                const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
-                const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
-                if (ltiTool) {
-                    console.info(`LTI tool ${ltiTool.id} found with developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
-                } else {
-                    console.warn(`Warning: Can't find LTI tool for developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
-                    hasError = true
+                if (canvasAccountId !== 'none') {
+                    const ltiTools = await canvas.getLtiTools(canvasAccountId);
+                    // For local tools the external tools API uses the shorter ID.
+                    const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
+                    const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
+                    if (ltiTool) {
+                        console.info(`LTI tool ${ltiTool.id} found with developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
+                    } else {
+                        console.warn(`Warning: Can't find LTI tool for developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
+                        hasError = true
+                    }
                 }
-                
             } else {
                 console.warn(`Warning: Can't find LTI developer key ${canvasLtiKeyId}`)
                 hasError = true
@@ -771,15 +776,20 @@ program
         const canvasLtiKeyId = ltiRegistration.lti.clientId
 
         const canvas = canvasCreate(canvasUrl, canvasToken)
-        const ltiTools = await canvas.getLtiTools(canvasAccountId)
-
-        // For local tools the external tools API uses the shorter ID.
-        const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
-        const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
-        if (ltiTool) {
-            console.info(JSON.stringify(ltiTool, null, 4))
+        if (canvasAccountId !== 'none') {
+            const ltiTools = await canvas.getLtiTools(canvasAccountId)
+            // For local tools the external tools API uses the shorter ID.
+            const localKeyId = (BigInt(canvasLtiKeyId) % BigInt("10000000000000")).toString()
+            const ltiTool = ltiTools.find(tool => tool.developer_key_id === localKeyId || tool.developer_key_id === canvasLtiKeyId);
+            if (ltiTool) {
+                console.info(JSON.stringify(ltiTool, null, 4))
+            } else {
+                console.error(`Warning: Can't find LTI tool for developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
+                process.exit(1)
+            }
         } else {
-            console.error(`Warning: Can't find LTI tool for developer key ${canvasLtiKeyId} in account ${canvasAccountId}`)
+            // We need a sub-account to look up the tool in.
+            console.error(`No sub-account to lookup the LTI tool in.`)
             process.exit(1)
         }
     })


Reviews:
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR adds documentation that explains how to disable adding a tool to a sub-account by setting the canvas_account_id to "none".  
- Added a "Notes" section in the README with detailed instructions on disabling tool addition.  
- Updated the list of automatic variables for clarity.




state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T12:52:21Z
user: login: sebastianchristopher
body: LGTM
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-02T14:36:12Z

Review comments:
diff_hunk: @@ -189,3 +189,20 @@ Bumping up the version with `npm version` and pushing those changes should resul
 npm version patch
 git push && git push --tags
 ```
+
+# Notes
+
+## Disabling adding tool to sub-account
+
+If you don't want a tool to be added to a sub-account you can set the `canvas_account_id` configuratino to `none`. This can be useful when initially releasing a tool to a production instance and you wish to have more control over when end users see it.
+
path: README.md
user: login: Copilot
body: There is a typo in 'configuratino'. It should be 'configuration'.
```suggestion
If you don't want a tool to be added to a sub-account you can set the `canvas_account_id` configuration to `none`. This can be useful when initially releasing a tool to a production instance and you wish to have more control over when end users see it.
```
created_at: 2025-04-02T12:52:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -189,3 +189,20 @@ Bumping up the version with `npm version` and pushing those changes should resul
 npm version patch
 git push && git push --tags
 ```
+
+# Notes
+
+## Disabling adding tool to sub-account
+
+If you don't want a tool to be added to a sub-account you can set the `canvas_account_id` configuratino to `none`. This can be useful when initially releasing a tool to a production instance and you wish to have more control over when end users see it.
+
+## Automatic Variables
+
+The following variables are automatically set by the tool and can be used in the configuration:
+
+ - `canvas_provider_url` - The URL of the LTI 1.3 initation endpoint for the Canvas instance.
+ - ``
path: README.md
user: login: Copilot
body: The bullet point appears incomplete. It should either be removed or completed with the missing variable name and description.
```suggestion

```
created_at: 2025-04-02T12:52:21Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-04-02T12:56:04Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=oxctl_lti-auto-configuration&pullRequest=40) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=oxctl_lti-auto-configuration&pullRequest=40&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=oxctl_lti-auto-configuration&pullRequest=40&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=oxctl_lti-auto-configuration&pullRequest=40&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=oxctl_lti-auto-configuration&pullRequest=40&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=oxctl_lti-auto-configuration&pullRequest=40&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=oxctl_lti-auto-configuration&pullRequest=40)


author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-04-02T12:56:04Z
body: Please retry analysis of this Pull-Request directly on SonarQube Cloud
author_association: NONE