-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge current feature/serverless contents preparatory to a release (#…
…1186) * Rename sandbox to serverless + drop sandbox term (#1178) In order to drop the term "sandbox" the help texts now use the terms "functions project" (for the disk area) and "functions namespace". * Change 'actions' to 'functions' in externals where feasible (#1177) * Replace 'actions' with 'functions' in externals 1. Re-do 'doctl sis fn list' output processing. - revised header and columns 2. Increment nim version, which will a. Cause 'functions' to be accepted in project.yml b. Use 'functions' in generated project.yml. c. Use 'functions' in output of get-metadata. * Adopt suggestions from PR review (1) The displayer is now properly attached to the command so that the --format flag will work. (2) The --count flag is mutually exclusive with the format flag, since it will bypass the displayer. * Set a unique user agent string for doctl sls (#1183) Previously, the use of doctl sls could not be distinguished from the use of 'nim' CLI. * Store serverless credentials directly instead of invoking the plugin with auth/login (#1184) * Eliminate call to nim auth login Replaced by a pure file system implementation that achieves the same result. * Tight file permissions on credentials * Fix test failures, clean up a few comments * Fix problem with first connect after install * Fix transcription error
- Loading branch information
1 parent
f285080
commit 8dc2afa
Showing
10 changed files
with
303 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright 2018 The Doctl Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package displayers | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
"time" | ||
|
||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
// Functions is the type of the displayer for functions list | ||
type Functions struct { | ||
Info []do.FunctionInfo | ||
} | ||
|
||
var _ Displayable = &Functions{} | ||
|
||
// JSON is the displayer JSON method specialized for functions list | ||
func (i *Functions) JSON(out io.Writer) error { | ||
return writeJSON(i.Info, out) | ||
} | ||
|
||
// Cols is the displayer Cols method specialized for functions list | ||
func (i *Functions) Cols() []string { | ||
return []string{ | ||
"Update", "Version", "Runtime", "Function", | ||
} | ||
} | ||
|
||
// ColMap is the displayer ColMap method specialized for functions list | ||
func (i *Functions) ColMap() map[string]string { | ||
return map[string]string{ | ||
"Update": "Latest Update", | ||
"Runtime": "Runtime Kind", | ||
"Version": "Latest Version", | ||
"Function": "Function Name", | ||
} | ||
} | ||
|
||
// KV is the displayer KV method specialized for functions list | ||
func (i *Functions) KV() []map[string]interface{} { | ||
out := make([]map[string]interface{}, 0, len(i.Info)) | ||
for _, ii := range i.Info { | ||
x := map[string]interface{}{ | ||
"Update": time.UnixMilli(ii.Updated).Format("01/02 03:04:05"), | ||
"Runtime": findRuntime(ii.Annotations), | ||
"Version": ii.Version, | ||
"Function": computeFunctionName(ii.Name, ii.Namespace), | ||
} | ||
out = append(out, x) | ||
} | ||
|
||
return out | ||
} | ||
|
||
// findRuntime finds the runtime string amongst the annotations of a function | ||
func findRuntime(annots []do.Annotation) string { | ||
for i := range annots { | ||
if annots[i].Key == "exec" { | ||
return annots[i].Value.(string) | ||
} | ||
} | ||
return "<unknown>" | ||
} | ||
|
||
// computeFunctionName computes the effective name of a function from its simple name and the 'namespace' field | ||
// (which actually encodes both namespace and package). | ||
func computeFunctionName(simpleName string, namespace string) string { | ||
nsparts := strings.Split(namespace, "/") | ||
if len(nsparts) > 1 { | ||
return nsparts[1] + "/" + simpleName | ||
} | ||
return simpleName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.