MCPcopy Create free account
hub / github.com/apache/openwhisk-cli / parseApi

Function parseApi

commands/api.go:829–940  ·  view source on GitHub ↗

* * if # args = 4 * args[0] = API base path * args[0] = API relative path * args[1] = API verb * args[2] = Optional. Action name (may or may not be qualified with namespace and package name) * * if # args = 3 * args[0] = API relative path * args[1] = API verb * args[2] = Optional. Action

(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

827 * args[2] = Optional. Action name (may or may not be qualified with namespace and package name)
828 */
829func parseApi(cmd *cobra.Command, args []string) (*whisk.Api, *QualifiedName, error) {
830 var err error
831 var basepath string = "/"
832 var apiname string
833 var basepathArgIsApiName = false
834
835 api := new(whisk.Api)
836
837 if len(args) > 3 {
838 // Is the argument a basepath (must start with /) or an API name
839 if _, ok := isValidBasepath(args[0]); !ok {
840 whisk.Debug(whisk.DbgInfo, "Treating '%s' as an API name; as it does not begin with '/'\n", args[0])
841 basepathArgIsApiName = true
842 }
843 if err, _ := isBasepathParameterized(args[0]); err != nil {
844 return nil, nil, err
845 }
846 basepath = args[0]
847
848 // Shift the args so the remaining code works with or without the explicit base path arg
849 args = args[1:]
850 }
851
852 // Is the API path valid?
853 if len(args) > 0 {
854 if whiskErr, ok := isValidRelpath(args[0]); !ok {
855 return nil, nil, whiskErr
856 }
857 api.GatewayRelPath = args[0] // Maintain case as URLs may be case-sensitive
858 }
859
860 // Attempting to use path parameters, lets validate that they provided them correctly.
861 hasPathParams, err := hasPathParameters(api.GatewayRelPath)
862 if err != nil {
863 return nil, nil, err
864 }
865 // If they provided path Parameters, the response type better be http as its the only one that supports path parameters right now.
866 if hasPathParams && Flags.api.resptype != "http" {
867 errMsg := wski18n.T("A response type of 'http' is required when using path parameters.")
868 whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL,
869 whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
870 return nil, nil, whiskErr
871 }
872
873 // Is the API verb valid?
874 if len(args) > 1 {
875 if whiskErr, ok := IsValidApiVerb(args[1]); !ok {
876 return nil, nil, whiskErr
877 }
878 api.GatewayMethod = strings.ToUpper(args[1])
879 }
880
881 // Is the specified action name valid?
882 var qName = new(QualifiedName)
883 if len(args) == 3 {
884 qName, err = NewQualifiedName(args[2])
885 if err != nil {
886 whisk.Debug(whisk.DbgError, "NewQualifiedName(%s) failed: %s\n", args[2], err)

Callers 1

api.goFile · 0.85

Calls 11

isValidBasepathFunction · 0.85
isBasepathParameterizedFunction · 0.85
isValidRelpathFunction · 0.85
hasPathParametersFunction · 0.85
IsValidApiVerbFunction · 0.85
NewQualifiedNameFunction · 0.85
generatePathParametersFunction · 0.85
GetEntityNameMethod · 0.80
GetPackageNameMethod · 0.80
GetNamespaceMethod · 0.80
GetEntityMethod · 0.80

Tested by

no test coverage detected