Skip to content

Improve detection of #include directives for arduino_secrets.h #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
per1234 opened this issue Jul 9, 2021 · 0 comments
Open

Improve detection of #include directives for arduino_secrets.h #447

per1234 opened this issue Jul 9, 2021 · 0 comments
Assignees
Labels
topic: cloud Related to Arduino Cloud and cloud sketches topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Jul 9, 2021

Describe the bug

Arduino Web Editor has a "Secret tab" feature that makes it easy to share sketches without accidentally exposing sensitive data (e.g., passwords or tokens).

The values of these secrets can be defined on Arduino Cloud via a form in the "Secret" tab in Arduino Web Editor.

On Arduino Cloud, secrets are stored in a secure database and the secret macro values populated from there.

The secrets database capability is not available when using the Arduino IDE, so a more conventional approach is taken by defining the secrets macros in a header file named arduino_secrets.h. In order to allow the use of the macros from this file, it's necessary to add an #include directive at the top of the primary sketch file for arduino_secrets.h (#438) when it is pulled. Before pushing, the #include directive should be removed.

Arduino Language syntax allows for an arbitrary number of spaces within an #include directive at two locations:

  • Between the # and the include identifier.
  • Between the include identifier and the header file path.

The regular expression used by the Arduino IDE to find and remove this code:
https://github.com/arduino/arduino-ide/blob/2.0.0-beta.9/arduino-ide-extension/src/browser/create/create-api.ts#L247-L248

const includeString = `#include "${Create.arduino_secrets_file}"`;
const includeRegexp = new RegExp(includeString + '\\s*', 'g');

🐛 Does not currently accommodate any variation in the number of spaces.

🐛 In addition, it will match to incidental occurrences of this string which are not valid syntax.

To Reproduce

  1. Open a sketch from your Remote Sketchbook in the Arduino IDE
  2. Add the following line to the sketch file:
    #  include "arduino_secrets.h"
  3. Push the sketch to Arduino Cloud
  4. Pull the sketch from Arduino Cloud

🐛 You will now have this:

#include "arduino_secrets.h"
#  include "arduino_secrets.h"

🐛 You will also have this line in the sketch when opened in Arduino Cloud:

#  include "arduino_secrets.h"

  1. Open a sketch from your Remote Sketchbook in the Arduino IDE
  2. Add the following line to the sketch file:
    #include                  "arduino_secrets.h"
  3. Push the sketch to Arduino Cloud
  4. Pull the sketch from Arduino Cloud

🐛 You will now have this:

#include "arduino_secrets.h"
#include                  "arduino_secrets.h"

  1. Open a sketch from your Remote Sketchbook in the Arduino IDE
  2. Add the following line to the sketch file:
    // the purpose of #include "arduino_secrets.h" is to provide the secrets
  3. Push the sketch to Arduino Cloud
  4. Pull the sketch from Arduino Cloud

🐛 You will now have this:

// the purpose of is to provide the secrets

Expected behavior

Any valid form of #include directive for arduino_secrets.h to be recognized.

Occurrences of #include "arduino_secrets.h" in comments to be left alone.

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop

  • OS: Windows
  • Version: Version: 2.0.0-beta.9
    Date: 2021-07-08T14:42:27.433Z
    CLI Version: 0.18.3 alpha [d710b642]
@per1234 per1234 added type: bug topic: code Related to content of the project itself labels Jul 9, 2021
@cmaglie cmaglie removed the type: bug label Sep 16, 2021
@rsora rsora added the type: imperfection Perceived defect in any part of project label Sep 22, 2021
@kittaakos kittaakos added the topic: cloud Related to Arduino Cloud and cloud sketches label Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: cloud Related to Arduino Cloud and cloud sketches topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

5 participants