MCPcopy
hub / github.com/digitalocean/doctl / NewServerlessService

Function NewServerlessService

do/serverless.go:348–371  ·  view source on GitHub ↗

NewServerlessService returns a configured ServerlessService.

(client *godo.Client, usualServerlessDir string, accessToken string)

Source from the content-addressed store, hash-verified

346
347// NewServerlessService returns a configured ServerlessService.
348func 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

Callers 3

RunServerlessInstallFunction · 0.92
NewCmdConfigFunction · 0.92

Calls 4

HashAccessTokenFunction · 0.85
GetCredentialDirectoryFunction · 0.85
SprintfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected