Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export interface ApifyEnv {
*/
actorBuildId: string | null;

/**
* [Permission level](https://docs.apify.com/platform/actors/development/permissions) the Actor is run under. (ACTOR_PERMISSION_LEVEL)
*/
actorPermissionLevel: string | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an enum, I'm wondering if we could type this strictly ('LIMITED_PERMISSIONS' | 'FULL_PERMISSIONS' | null).

It would help users with adoption, but might require some well-placed casts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I typed it using the ACTOR_PERMISSION_LEVEL from @apify/consts


/**
* ID of the user who started the Actor - note that it might be
* different than the owner of the Actor (APIFY_USER_ID)
Expand Down Expand Up @@ -497,6 +502,10 @@ export class Actor<Data extends Dictionary = Dictionary> {
// reset global config instance to respect APIFY_ prefixed env vars
CoreConfiguration.globalConfig = Configuration.getGlobalConfig();

log.info('Permissions', {
actorPermissionLevel: this.getEnv().actorPermissionLevel,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this should not be somehow conditional, as most of the time it would be defined only when run on Apify. Locally, it won't be defined if the user doesn't do so.

However, I can imagine some cases when my code depends on the permission level, so I am passing it "artificially" even locally to test things out.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking that we'd print it via worker. That would be more universal 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the original intention was to put it in the system message (= SDK), but when implementing it, I decided not to put it there, as the system message consists of more "low level" information.

I guess we can log it through Worker.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought system message means worker 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for logging this elsewhere, locally this IMO doesn't add much value. It's either unset, i.e., this line will print Permissions { actorPermissionLevel: null }, or I pass it manually = I did that intentionally, I know what permission level I'm on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also vote for worker or in worst case maybe add it to log.info('System info', getSystemInfo());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add it to the system message as I said here: #516 (comment)

Lets move to to Worker 👍


if (this.isAtHome()) {
this.config.set('availableMemoryRatio', 1);
this.config.set('disableBrowserSandbox', true); // for browser launcher, adds `--no-sandbox` to args
Expand Down
2 changes: 2 additions & 0 deletions packages/apify/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface ConfigurationOptions extends CoreConfigurationOptions {
* ---|---|---
* `actorEventsWsUrl` | `ACTOR_EVENTS_WEBSOCKET_URL` | -
* `actorId` | `ACTOR_ID` | -
* `actorPermissionLevel` | `ACTOR_PERMISSION_LEVEL` | -
* `actorRunId` | `ACTOR_RUN_ID` | -
* `actorTaskId` | `ACTOR_TASK_ID` | -
* `apiBaseUrl` | `APIFY_API_BASE_URL` | `'https://api.apify.com'`
Expand Down Expand Up @@ -172,6 +173,7 @@ export class Configuration extends CoreConfiguration {
ACTOR_ID: 'actorId',
ACTOR_INPUT_KEY: 'inputKey',
ACTOR_MEMORY_MBYTES: 'memoryMbytes',
ACTOR_PERMISSION_LEVEL: 'actorPermissionLevel',
ACTOR_RUN_ID: 'actorRunId',
ACTOR_STANDBY_PORT: 'standbyPort',
ACTOR_STANDBY_URL: 'standbyUrl',
Expand Down