NewServerlessService returns a configured ServerlessService.
(client *godo.Client, usualServerlessDir string, accessToken string)
| 346 | |
| 347 | // NewServerlessService returns a configured ServerlessService. |
| 348 | func NewServerlessService(client *godo.Client, usualServerlessDir string, accessToken string) ServerlessService { |
| 349 | nodeBin := "node" |
| 350 | if runtime.GOOS == "windows" { |
| 351 | nodeBin = "node.exe" |
| 352 | } |
| 353 | // The following is needed to support snap installation. For snap, the installation directory |
| 354 | // is relocated to a snap-managed area. That area is not user-writable, so, the credsDir location |
| 355 | // is always computed relative to the normal installation area (usualServerlessDir). |
| 356 | serverlessDir := os.Getenv("OVERRIDE_SANDBOX_DIR") |
| 357 | if serverlessDir == "" { |
| 358 | serverlessDir = usualServerlessDir |
| 359 | } |
| 360 | credsToken := HashAccessToken(accessToken) |
| 361 | return &serverlessService{ |
| 362 | serverlessJs: filepath.Join(serverlessDir, "sandbox.js"), |
| 363 | serverlessDir: serverlessDir, |
| 364 | credsDir: GetCredentialDirectory(credsToken, usualServerlessDir), |
| 365 | node: filepath.Join(serverlessDir, nodeBin), |
| 366 | userAgent: fmt.Sprintf("doctl/%s serverless/%s", doctl.DoitVersion.String(), minServerlessVersion), |
| 367 | client: client, |
| 368 | owClient: nil, |
| 369 | accessToken: accessToken, |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | // HashAccessToken converts a DO access token string into a shorter but suitably random string |
| 374 | // via hashing. This is used to form part of the path for storing OpenWhisk credentials |
no test coverage detected