repo stringlengths 5 67 | sha stringlengths 40 40 | path stringlengths 4 234 | url stringlengths 85 339 | language stringclasses 6 values | split stringclasses 3 values | doc stringlengths 3 51.2k | sign stringlengths 5 8.01k | problem stringlengths 13 51.2k | output stringlengths 0 3.87M |
|---|---|---|---|---|---|---|---|---|---|
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/configv3/env.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/configv3/env.go#L49-L58 | go | train | // DialTimeout returns the timeout to use when dialing. This is based off of:
// 1. The $CF_DIAL_TIMEOUT environment variable if set
// 2. Defaults to 5 seconds | func (config *Config) DialTimeout() time.Duration | // DialTimeout returns the timeout to use when dialing. This is based off of:
// 1. The $CF_DIAL_TIMEOUT environment variable if set
// 2. Defaults to 5 seconds
func (config *Config) DialTimeout() time.Duration | {
if config.ENV.CFDialTimeout != "" {
envVal, err := strconv.ParseInt(config.ENV.CFDialTimeout, 10, 64)
if err == nil {
return time.Duration(envVal) * time.Second
}
}
return DefaultDialTimeout
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/configv3/env.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/configv3/env.go#L69-L78 | go | train | // Experimental returns whether or not to run experimental CLI commands. This
// is based off of:
// 1. The $CF_CLI_EXPERIMENTAL environment variable if set
// 2. Defaults to false | func (config *Config) Experimental() bool | // Experimental returns whether or not to run experimental CLI commands. This
// is based off of:
// 1. The $CF_CLI_EXPERIMENTAL environment variable if set
// 2. Defaults to false
func (config *Config) Experimental() bool | {
if config.ENV.Experimental != "" {
envVal, err := strconv.ParseBool(config.ENV.Experimental)
if err == nil {
return envVal
}
}
return false
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/configv3/env.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/configv3/env.go#L107-L129 | go | train | // LogLevel returns the global log level. The levels follow Logrus's log level
// scheme. This value is based off of:
// - The $CF_LOG_LEVEL and an int/warn/info/etc...
// - Defaults to PANIC/0 (ie no logging) | func (config *Config) LogLevel() int | // LogLevel returns the global log level. The levels follow Logrus's log level
// scheme. This value is based off of:
// - The $CF_LOG_LEVEL and an int/warn/info/etc...
// - Defaults to PANIC/0 (ie no logging)
func (config *Config) LogLevel() int | {
if config.ENV.CFLogLevel != "" {
envVal, err := strconv.ParseInt(config.ENV.CFLogLevel, 10, 32)
if err == nil {
return int(envVal)
}
switch strings.ToLower(config.ENV.CFLogLevel) {
case "fatal":
return 1
case "error":
return 2
case "warn":
return 3
case "info":
return 4
case "debug":
return 5
}
}
return 0
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/configv3/env.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/configv3/env.go#L135-L145 | go | train | // StagingTimeout returns the max time an application staging should take. The
// time is based off of:
// 1. The $CF_STAGING_TIMEOUT environment variable if set
// 2. Defaults to the DefaultStagingTimeout | func (config *Config) StagingTimeout() time.Duration | // StagingTimeout returns the max time an application staging should take. The
// time is based off of:
// 1. The $CF_STAGING_TIMEOUT environment variable if set
// 2. Defaults to the DefaultStagingTimeout
func (config *Config) StagingTimeout() time.Duration | {
if config.ENV.CFStagingTimeout != "" {
timeoutInMin, err := strconv.ParseFloat(config.ENV.CFStagingTimeout, 64)
timeoutInSec := int64(timeoutInMin * 60)
if err == nil {
return time.Duration(timeoutInSec) * time.Second
}
}
return DefaultStagingTimeout
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/configv3/env.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/configv3/env.go#L151-L161 | go | train | // StartupTimeout returns the max time an application should take to start. The
// time is based off of:
// 1. The $CF_STARTUP_TIMEOUT environment variable if set
// 2. Defaults to the DefaultStartupTimeout | func (config *Config) StartupTimeout() time.Duration | // StartupTimeout returns the max time an application should take to start. The
// time is based off of:
// 1. The $CF_STARTUP_TIMEOUT environment variable if set
// 2. Defaults to the DefaultStartupTimeout
func (config *Config) StartupTimeout() time.Duration | {
if config.ENV.CFStartupTimeout != "" {
timeoutInMin, err := strconv.ParseFloat(config.ENV.CFStartupTimeout, 64)
timeoutInSec := int64(timeoutInMin * 60)
if err == nil {
return time.Duration(timeoutInSec) * time.Second
}
}
return DefaultStartupTimeout
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/resources.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/resources.go#L11-L42 | go | train | // SetupResources configures the client to use the specified settings and diescopers the UAA and Authentication resources | func (client *Client) SetupResources(bootstrapURL string) error | // SetupResources configures the client to use the specified settings and diescopers the UAA and Authentication resources
func (client *Client) SetupResources(bootstrapURL string) error | {
request, err := client.newRequest(requestOptions{
Method: http.MethodGet,
URL: fmt.Sprintf("%s/login", bootstrapURL),
})
if err != nil {
return err
}
info := NewInfo(bootstrapURL)
response := Response{
Result: &info,
}
err = client.connection.Make(request, &response)
if err != nil {
return err
}
resources := map[string]string{
"uaa": info.UAALink(),
"authorization_endpoint": bootstrapURL,
}
client.router = internal.NewRouter(internal.APIRoutes, resources)
client.Info = info
client.config.SetUAAEndpoint(info.UAALink())
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/sharedaction/help.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/sharedaction/help.go#L60-L120 | go | train | // CommandInfoByName returns the help information for a particular commandName in
// the commandList. | func (Actor) CommandInfoByName(commandList interface{}, commandName string) (CommandInfo, error) | // CommandInfoByName returns the help information for a particular commandName in
// the commandList.
func (Actor) CommandInfoByName(commandList interface{}, commandName string) (CommandInfo, error) | {
field, found := reflect.TypeOf(commandList).FieldByNameFunc(
func(fieldName string) bool {
field, _ := reflect.TypeOf(commandList).FieldByName(fieldName)
return field.Tag.Get("command") == commandName || field.Tag.Get("alias") == commandName
},
)
if !found {
return CommandInfo{}, actionerror.InvalidCommandError{CommandName: commandName}
}
tag := field.Tag
cmd := CommandInfo{
Name: tag.Get("command"),
Description: tag.Get("description"),
Alias: tag.Get("alias"),
Flags: []CommandFlag{},
Environment: []EnvironmentVariable{},
}
command := field.Type
for i := 0; i < command.NumField(); i++ {
fieldTag := command.Field(i).Tag
if fieldTag.Get("hidden") != "" {
continue
}
if fieldTag.Get("usage") != "" {
cmd.Usage = fieldTag.Get("usage")
continue
}
if fieldTag.Get("related_commands") != "" {
relatedCommands := strings.Split(fieldTag.Get("related_commands"), ", ")
sort.Slice(relatedCommands, sorting.SortAlphabeticFunc(relatedCommands))
cmd.RelatedCommands = relatedCommands
continue
}
if fieldTag.Get("description") != "" {
cmd.Flags = append(cmd.Flags, CommandFlag{
Short: fieldTag.Get("short"),
Long: fieldTag.Get("long"),
Description: fieldTag.Get("description"),
Default: fieldTag.Get("default"),
})
}
if fieldTag.Get("environmentName") != "" {
cmd.Environment = append(cmd.Environment, EnvironmentVariable{
Name: fieldTag.Get("environmentName"),
DefaultValue: fieldTag.Get("environmentDefault"),
Description: fieldTag.Get("environmentDescription"),
})
}
}
return cmd, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/sharedaction/help.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/sharedaction/help.go#L124-L139 | go | train | // CommandInfos returns a slice of CommandInfo that only fills in
// the Name and Description for all the commands in commandList | func (Actor) CommandInfos(commandList interface{}) map[string]CommandInfo | // CommandInfos returns a slice of CommandInfo that only fills in
// the Name and Description for all the commands in commandList
func (Actor) CommandInfos(commandList interface{}) map[string]CommandInfo | {
handler := reflect.TypeOf(commandList)
infos := make(map[string]CommandInfo, handler.NumField())
for i := 0; i < handler.NumField(); i++ {
fieldTag := handler.Field(i).Tag
commandName := fieldTag.Get("command")
infos[commandName] = CommandInfo{
Name: commandName,
Description: fieldTag.Get("description"),
Alias: fieldTag.Get("alias"),
}
}
return infos
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/resource.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/resource.go#L33-L46 | go | train | // MarshalJSON converts a resource into a Cloud Controller Resource. | func (r Resource) MarshalJSON() ([]byte, error) | // MarshalJSON converts a resource into a Cloud Controller Resource.
func (r Resource) MarshalJSON() ([]byte, error) | {
var ccResource struct {
FilePath string `json:"path,omitempty"`
Mode string `json:"mode,omitempty"`
Checksum Checksum `json:"checksum"`
SizeInBytes int64 `json:"size_in_bytes"`
}
ccResource.FilePath = r.FilePath
ccResource.SizeInBytes = r.SizeInBytes
ccResource.Checksum = r.Checksum
ccResource.Mode = strconv.FormatUint(uint64(r.Mode), 8)
return json.Marshal(ccResource)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/resource.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/resource.go#L58-L81 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Resource response. | func (r *Resource) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Resource response.
func (r *Resource) UnmarshalJSON(data []byte) error | {
var ccResource struct {
FilePath string `json:"path,omitempty"`
Mode string `json:"mode,omitempty"`
Checksum Checksum `json:"checksum"`
SizeInBytes int64 `json:"size_in_bytes"`
}
err := cloudcontroller.DecodeJSON(data, &ccResource)
if err != nil {
return err
}
r.FilePath = ccResource.FilePath
r.SizeInBytes = ccResource.SizeInBytes
r.Checksum = ccResource.Checksum
mode, err := strconv.ParseUint(ccResource.Mode, 8, 32)
if err != nil {
return err
}
r.Mode = os.FileMode(mode)
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/job_url.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/job_url.go#L14-L27 | go | train | // DeleteApplication deletes the app with the given app GUID. Returns back a
// resulting job URL to poll. | func (client *Client) DeleteApplication(appGUID string) (JobURL, Warnings, error) | // DeleteApplication deletes the app with the given app GUID. Returns back a
// resulting job URL to poll.
func (client *Client) DeleteApplication(appGUID string) (JobURL, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.DeleteApplicationRequest,
URIParams: internal.Params{"app_guid": appGUID},
})
if err != nil {
return "", nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return JobURL(response.ResourceLocationURL), response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/job_url.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/job_url.go#L31-L48 | go | train | // UpdateApplicationApplyManifest applies the manifest to the given
// application. Returns back a resulting job URL to poll. | func (client *Client) UpdateApplicationApplyManifest(appGUID string, rawManifest []byte) (JobURL, Warnings, error) | // UpdateApplicationApplyManifest applies the manifest to the given
// application. Returns back a resulting job URL to poll.
func (client *Client) UpdateApplicationApplyManifest(appGUID string, rawManifest []byte) (JobURL, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostApplicationActionApplyManifest,
URIParams: map[string]string{"app_guid": appGUID},
Body: bytes.NewReader(rawManifest),
})
if err != nil {
return "", nil, err
}
request.Header.Set("Content-Type", "application/x-yaml")
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return JobURL(response.ResourceLocationURL), response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/job_url.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/job_url.go#L60-L78 | go | train | // UpdateSpaceApplyManifest - Is there a better name for this, since ...
// -- The Space resource is not actually updated.
// -- Instead what this ApplyManifest may do is to Create or Update Applications instead.
// Applies the manifest to the given space. Returns back a resulting job URL to poll.
// For each app specified in the manifest, the server-side handles:
// (1) Finding or creating this app.
// (2) Applying manifest properties to this app. | func (client *Client) UpdateSpaceApplyManifest(spaceGUID string, rawManifest []byte, query ...Query) (JobURL, Warnings, error) | // UpdateSpaceApplyManifest - Is there a better name for this, since ...
// -- The Space resource is not actually updated.
// -- Instead what this ApplyManifest may do is to Create or Update Applications instead.
// Applies the manifest to the given space. Returns back a resulting job URL to poll.
// For each app specified in the manifest, the server-side handles:
// (1) Finding or creating this app.
// (2) Applying manifest properties to this app.
func (client *Client) UpdateSpaceApplyManifest(spaceGUID string, rawManifest []byte, query ...Query) (JobURL, Warnings, error) | {
request, requestExecuteErr := client.newHTTPRequest(requestOptions{
RequestName: internal.PostSpaceActionApplyManifestRequest,
Query: query,
URIParams: map[string]string{"space_guid": spaceGUID},
Body: bytes.NewReader(rawManifest),
})
if requestExecuteErr != nil {
return JobURL(""), nil, requestExecuteErr
}
request.Header.Set("Content-Type", "application/x-yaml")
response := cloudcontroller.Response{}
err := client.connection.Make(request, &response)
return JobURL(response.ResourceLocationURL), response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/request.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/request.go#L37-L85 | go | train | // newHTTPRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request fields are not filled in. | func (client Client) newHTTPRequest(passedRequest requestOptions) (*cloudcontroller.Request, error) | // newHTTPRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request fields are not filled in.
func (client Client) newHTTPRequest(passedRequest requestOptions) (*cloudcontroller.Request, error) | {
var request *http.Request
var err error
if passedRequest.URI != "" {
var (
path *url.URL
base *url.URL
)
path, err = url.Parse(passedRequest.URI)
if err != nil {
return nil, err
}
base, err = url.Parse(client.API())
if err != nil {
return nil, err
}
request, err = http.NewRequest(
passedRequest.Method,
base.ResolveReference(path).String(),
passedRequest.Body,
)
} else {
request, err = client.router.CreateRequest(
passedRequest.RequestName,
map[string]string(passedRequest.URIParams),
passedRequest.Body,
)
if err == nil {
request.URL.RawQuery = passedRequest.Query.Encode()
}
}
if err != nil {
return nil, err
}
request.Header = http.Header{}
request.Header.Set("Accept", "application/json")
request.Header.Set("User-Agent", client.userAgent)
if passedRequest.Body != nil {
request.Header.Set("Content-Type", "application/json")
}
// Make sure the body is the same as the one in the request
return cloudcontroller.NewRequest(request, passedRequest.Body), nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/i18n.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/i18n.go#L48-L63 | go | train | // GetTranslationFunc will return back a function that can be used to translate
// strings into the currently set locale. | func GetTranslationFunc(reader LocaleReader) (TranslateFunc, error) | // GetTranslationFunc will return back a function that can be used to translate
// strings into the currently set locale.
func GetTranslationFunc(reader LocaleReader) (TranslateFunc, error) | {
locale, err := determineLocale(reader)
if err != nil {
locale = defaultLocale
}
rawTranslation, err := loadAssetFromResources(locale)
if err != nil {
rawTranslation, err = loadAssetFromResources(defaultLocale)
if err != nil {
return nil, err
}
}
return generateTranslationFunc(rawTranslation)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/i18n.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/i18n.go#L68-L84 | go | train | // ParseLocale will return a locale formatted as "<language code>-<region
// code>" for all non-Chinese lanagues. For Chinese, it will return
// "zh-<script>", defaulting to "hant" if script is unspecified. | func ParseLocale(locale string) (string, error) | // ParseLocale will return a locale formatted as "<language code>-<region
// code>" for all non-Chinese lanagues. For Chinese, it will return
// "zh-<script>", defaulting to "hant" if script is unspecified.
func ParseLocale(locale string) (string, error) | {
lang, err := language.Parse(locale)
if err != nil {
return "", err
}
base, script, region := lang.Raw()
switch base.String() {
case chineseBase:
if script.String() == unspecifiedScript {
return "zh-hant", nil
}
return strings.ToLower(fmt.Sprintf("%s-%s", base, script)), nil
default:
return strings.ToLower(fmt.Sprintf("%s-%s", base, region)), nil
}
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | integration/helpers/user.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/integration/helpers/user.go#L18-L56 | go | train | // GetUsers returns all the users in the targeted environment | func GetUsers() []User | // GetUsers returns all the users in the targeted environment
func GetUsers() []User | {
var userPagesResponse struct {
NextURL *string `json:"next_url"`
Resources []struct {
Metadata struct {
GUID string `json:"guid"`
CreatedAt time.Time `json:"created_at"`
} `json:"metadata"`
Entity struct {
Username string `json:"username"`
} `json:"entity"`
} `json:"resources"`
}
var allUsers []User
nextURL := "/v2/users?results-per-page=50"
for {
session := CF("curl", nextURL)
Eventually(session).Should(Exit(0))
err := json.Unmarshal(session.Out.Contents(), &userPagesResponse)
Expect(err).NotTo(HaveOccurred())
for _, resource := range userPagesResponse.Resources {
allUsers = append(allUsers, User{
GUID: resource.Metadata.GUID,
CreatedAt: resource.Metadata.CreatedAt,
Username: resource.Entity.Username,
})
}
if userPagesResponse.NextURL == nil {
break
}
nextURL = *userPagesResponse.NextURL
}
return allUsers
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/composite/service_broker_summary.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/composite/service_broker_summary.go#L60-L96 | go | train | // GetServiceBrokerSummaries returns summaries for service brokers that match the arguments passed.
// An error will be returned if any of the options are invalid (i.e. there is no broker, service or
// organization with the given names). Consider the structure of Service Brokers, Services,
// and Plans as a tree (a Broker may have many Services, a Service may have many Plans) for the purpose
// of this explanation. Each of the provided arguments will act as a filtering mechanism,
// with the expectation that the caller does not want matches for "parent" concepts, if they have no
// "children" matching a filtered argument.
//
// For example, given a Broker "Foo", only containing a Service "Bar":
//
// `GetServiceBrokerSummaries("Foo", "NotBar", "")` will return a slice of broker summaries that does not
// include the Broker "Foo".
//
// Similarly, given a broker "Foo", containing a Service "Bar", that has plans available only in Organization "Baz":
//
// `GetServiceBrokerSummaries("Foo", "Bar", "NotBaz") will recurse upwards resulting in a slice of broker
// summaries that does not include the Broker "Foo" either. | func (c *ServiceBrokerSummaryCompositeActor) GetServiceBrokerSummaries(brokerName string, serviceName string, organizationName string) ([]v2action.ServiceBrokerSummary, v2action.Warnings, error) | // GetServiceBrokerSummaries returns summaries for service brokers that match the arguments passed.
// An error will be returned if any of the options are invalid (i.e. there is no broker, service or
// organization with the given names). Consider the structure of Service Brokers, Services,
// and Plans as a tree (a Broker may have many Services, a Service may have many Plans) for the purpose
// of this explanation. Each of the provided arguments will act as a filtering mechanism,
// with the expectation that the caller does not want matches for "parent" concepts, if they have no
// "children" matching a filtered argument.
//
// For example, given a Broker "Foo", only containing a Service "Bar":
//
// `GetServiceBrokerSummaries("Foo", "NotBar", "")` will return a slice of broker summaries that does not
// include the Broker "Foo".
//
// Similarly, given a broker "Foo", containing a Service "Bar", that has plans available only in Organization "Baz":
//
// `GetServiceBrokerSummaries("Foo", "Bar", "NotBaz") will recurse upwards resulting in a slice of broker
// summaries that does not include the Broker "Foo" either.
func (c *ServiceBrokerSummaryCompositeActor) GetServiceBrokerSummaries(brokerName string, serviceName string, organizationName string) ([]v2action.ServiceBrokerSummary, v2action.Warnings, error) | {
var warnings v2action.Warnings
if organizationName != "" {
orgExistsWarnings, err := c.ensureOrgExists(organizationName)
warnings = append(warnings, orgExistsWarnings...)
if err != nil {
return nil, warnings, err
}
}
if serviceName != "" {
serviceExistsWarnings, err := c.ensureServiceExists(serviceName)
warnings = append(warnings, serviceExistsWarnings...)
if err != nil {
return nil, warnings, err
}
}
brokers, brokerWarnings, err := c.getServiceBrokers(brokerName)
warnings = append(warnings, brokerWarnings...)
if err != nil {
return nil, warnings, err
}
brokerSummaries, brokerSummaryWarnings, err := c.fetchBrokerSummaries(brokers, serviceName, organizationName)
warnings = append(warnings, brokerSummaryWarnings...)
if err != nil {
return nil, warnings, err
}
if organizationName != "" || serviceName != "" {
brokerSummaries = pruneEmptyLeaves(brokerSummaries)
}
return brokerSummaries, warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/info.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/info.go#L88-L102 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller /v3 response. | func (resources ResourceLinks) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller /v3 response.
func (resources ResourceLinks) UnmarshalJSON(data []byte) error | {
var ccResourceLinks struct {
Links map[string]APILink `json:"links"`
}
err := cloudcontroller.DecodeJSON(data, &ccResourceLinks)
if err != nil {
return err
}
for key, val := range ccResourceLinks.Links {
resources[key] = val
}
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/info.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/info.go#L105-L132 | go | train | // GetInfo returns endpoint and API information from /v3. | func (client *Client) GetInfo() (Info, ResourceLinks, Warnings, error) | // GetInfo returns endpoint and API information from /v3.
func (client *Client) GetInfo() (Info, ResourceLinks, Warnings, error) | {
rootResponse, warnings, err := client.rootResponse()
if err != nil {
return Info{}, ResourceLinks{}, warnings, err
}
request, err := client.newHTTPRequest(requestOptions{
Method: http.MethodGet,
URL: rootResponse.ccV3Link(),
})
if err != nil {
return Info{}, ResourceLinks{}, warnings, err
}
info := ResourceLinks{} // Explicitly initializing
response := cloudcontroller.Response{
DecodeJSONResponseInto: &info,
}
err = client.connection.Make(request, &response)
warnings = append(warnings, response.Warnings...)
if err != nil {
return Info{}, ResourceLinks{}, warnings, err
}
return rootResponse, info, warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/info.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/info.go#L135-L155 | go | train | // rootResponse returns the CC API root document. | func (client *Client) rootResponse() (Info, Warnings, error) | // rootResponse returns the CC API root document.
func (client *Client) rootResponse() (Info, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
Method: http.MethodGet,
URL: client.cloudControllerURL,
})
if err != nil {
return Info{}, nil, err
}
var rootResponse Info
response := cloudcontroller.Response{
DecodeJSONResponseInto: &rootResponse,
}
err = client.connection.Make(request, &response)
if unknownSourceErr, ok := err.(ccerror.UnknownHTTPSourceError); ok && unknownSourceErr.StatusCode == http.StatusNotFound {
return Info{}, nil, ccerror.APINotFoundError{URL: client.cloudControllerURL}
}
return rootResponse, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v3action/zdt.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/zdt.go#L39-L56 | go | train | // TODO: add tests for get current deployment | func (actor Actor) GetCurrentDeployment(appGUID string) (string, Warnings, error) | // TODO: add tests for get current deployment
func (actor Actor) GetCurrentDeployment(appGUID string) (string, Warnings, error) | {
var collectedWarnings Warnings
deployments, warnings, err := actor.CloudControllerClient.GetDeployments(
ccv3.Query{Key: ccv3.AppGUIDFilter, Values: []string{appGUID}},
ccv3.Query{Key: ccv3.OrderBy, Values: []string{"-created_at"}},
ccv3.Query{Key: ccv3.PerPage, Values: []string{"1"}},
)
collectedWarnings = append(collectedWarnings, warnings...)
if err != nil {
return "", collectedWarnings, err
}
if len(deployments) < 1 {
return "", collectedWarnings, errors.New("failed to find a deployment for that app")
}
return deployments[0].GUID, collectedWarnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/application.go#L34-L54 | go | train | // MarshalJSON converts an Application into a Cloud Controller Application. | func (a Application) MarshalJSON() ([]byte, error) | // MarshalJSON converts an Application into a Cloud Controller Application.
func (a Application) MarshalJSON() ([]byte, error) | {
ccApp := ccApplication{
Name: a.Name,
Relationships: a.Relationships,
Metadata: a.Metadata,
}
if a.LifecycleType == constant.AppLifecycleTypeDocker {
ccApp.setDockerLifecycle()
} else if a.LifecycleType == constant.AppLifecycleTypeBuildpack {
if len(a.LifecycleBuildpacks) > 0 || a.StackName != "" {
if a.hasAutodetectedBuildpack() {
ccApp.setAutodetectedBuildpackLifecycle(a)
} else {
ccApp.setBuildpackLifecycle(a)
}
}
}
return json.Marshal(ccApp)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/application.go#L57-L78 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Application response. | func (a *Application) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Application response.
func (a *Application) UnmarshalJSON(data []byte) error | {
lifecycle := ccLifecycle{}
ccApp := ccApplication{
Lifecycle: &lifecycle,
}
err := cloudcontroller.DecodeJSON(data, &ccApp)
if err != nil {
return err
}
a.GUID = ccApp.GUID
a.StackName = lifecycle.Data.Stack
a.LifecycleBuildpacks = lifecycle.Data.Buildpacks
a.LifecycleType = lifecycle.Type
a.Name = ccApp.Name
a.Relationships = ccApp.Relationships
a.State = ccApp.State
a.Metadata = ccApp.Metadata
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/application.go#L156-L179 | go | train | // GetApplications lists applications with optional queries. | func (client *Client) GetApplications(query ...Query) ([]Application, Warnings, error) | // GetApplications lists applications with optional queries.
func (client *Client) GetApplications(query ...Query) ([]Application, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullAppsList []Application
warnings, err := client.paginate(request, Application{}, func(item interface{}) error {
if app, ok := item.(Application); ok {
fullAppsList = append(fullAppsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Application{},
Unexpected: item,
}
}
return nil
})
return fullAppsList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/application.go#L182-L204 | go | train | // UpdateApplication updates an application with the given settings. | func (client *Client) UpdateApplication(app Application) (Application, Warnings, error) | // UpdateApplication updates an application with the given settings.
func (client *Client) UpdateApplication(app Application) (Application, Warnings, error) | {
bodyBytes, err := json.Marshal(app)
if err != nil {
return Application{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PatchApplicationRequest,
Body: bytes.NewReader(bodyBytes),
URIParams: map[string]string{"app_guid": app.GUID},
})
if err != nil {
return Application{}, nil, err
}
var responseApp Application
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseApp,
}
err = client.connection.Make(request, &response)
return responseApp, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/application.go#L207-L223 | go | train | // UpdateApplicationRestart restarts the given application. | func (client *Client) UpdateApplicationRestart(appGUID string) (Application, Warnings, error) | // UpdateApplicationRestart restarts the given application.
func (client *Client) UpdateApplicationRestart(appGUID string) (Application, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostApplicationActionRestartRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return Application{}, nil, err
}
var responseApp Application
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseApp,
}
err = client.connection.Make(request, &response)
return responseApp, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v7action/application_manifest.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v7action/application_manifest.go#L17-L41 | go | train | // ApplyApplicationManifest reads in the manifest from the path and provides it
// to the cloud controller. | func (actor Actor) ApplyApplicationManifest(parser ManifestParser, spaceGUID string) (Warnings, error) | // ApplyApplicationManifest reads in the manifest from the path and provides it
// to the cloud controller.
func (actor Actor) ApplyApplicationManifest(parser ManifestParser, spaceGUID string) (Warnings, error) | {
var allWarnings Warnings
for _, appName := range parser.AppNames() {
rawManifest, err := parser.RawAppManifest(appName)
if err != nil {
return allWarnings, err
}
app, getAppWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, getAppWarnings...)
if err != nil {
return allWarnings, err
}
applyManifestWarnings, err := actor.SetApplicationManifest(app.GUID, rawManifest)
allWarnings = append(allWarnings, applyManifestWarnings...)
if err != nil {
return allWarnings, err
}
}
return allWarnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/manifest.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/manifest.go#L10-L24 | go | train | // GetApplicationManifest returns a (YAML) manifest for an application and its
// underlying processes. | func (client *Client) GetApplicationManifest(appGUID string) ([]byte, Warnings, error) | // GetApplicationManifest returns a (YAML) manifest for an application and its
// underlying processes.
func (client *Client) GetApplicationManifest(appGUID string) ([]byte, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationManifestRequest,
URIParams: internal.Params{"app_guid": appGUID},
})
if err != nil {
return nil, nil, err
}
request.Header.Set("Accept", "application/x-yaml")
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
return response.RawResponse, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L25-L31 | go | train | // CalculatedBuildpack returns the buildpack that will be used. | func (application Application) CalculatedBuildpack() string | // CalculatedBuildpack returns the buildpack that will be used.
func (application Application) CalculatedBuildpack() string | {
if application.Buildpack.IsSet {
return application.Buildpack.Value
}
return application.DetectedBuildpack.Value
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L34-L40 | go | train | // CalculatedCommand returns the command that will be used. | func (application Application) CalculatedCommand() string | // CalculatedCommand returns the command that will be used.
func (application Application) CalculatedCommand() string | {
if application.Command.IsSet {
return application.Command.Value
}
return application.DetectedStartCommand.Value
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L64-L70 | go | train | // StagingFailedMessage returns the verbose description of the failure or
// the reason if the verbose description is empty. | func (application Application) StagingFailedMessage() string | // StagingFailedMessage returns the verbose description of the failure or
// the reason if the verbose description is empty.
func (application Application) StagingFailedMessage() string | {
if application.StagingFailedDescription != "" {
return application.StagingFailedDescription
}
return application.StagingFailedReason
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L115-L118 | go | train | // CreateApplication creates an application. | func (actor Actor) CreateApplication(application Application) (Application, Warnings, error) | // CreateApplication creates an application.
func (actor Actor) CreateApplication(application Application) (Application, Warnings, error) | {
app, warnings, err := actor.CloudControllerClient.CreateApplication(ccv2.Application(application))
return Application(app), Warnings(warnings), err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L121-L129 | go | train | // GetApplication returns the application. | func (actor Actor) GetApplication(guid string) (Application, Warnings, error) | // GetApplication returns the application.
func (actor Actor) GetApplication(guid string) (Application, Warnings, error) | {
app, warnings, err := actor.CloudControllerClient.GetApplication(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Application{}, Warnings(warnings), actionerror.ApplicationNotFoundError{GUID: guid}
}
return Application(app), Warnings(warnings), err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L133-L158 | go | train | // GetApplicationByNameAndSpace returns an application with matching name in
// the space. | func (actor Actor) GetApplicationByNameAndSpace(name string, spaceGUID string) (Application, Warnings, error) | // GetApplicationByNameAndSpace returns an application with matching name in
// the space.
func (actor Actor) GetApplicationByNameAndSpace(name string, spaceGUID string) (Application, Warnings, error) | {
app, warnings, err := actor.CloudControllerClient.GetApplications(
ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{name},
},
ccv2.Filter{
Type: constant.SpaceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{spaceGUID},
},
)
if err != nil {
return Application{}, Warnings(warnings), err
}
if len(app) == 0 {
return Application{}, Warnings(warnings), actionerror.ApplicationNotFoundError{
Name: name,
}
}
return Application(app[0]), Warnings(warnings), nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L161-L180 | go | train | // GetApplicationsBySpace returns all applications in a space. | func (actor Actor) GetApplicationsBySpace(spaceGUID string) ([]Application, Warnings, error) | // GetApplicationsBySpace returns all applications in a space.
func (actor Actor) GetApplicationsBySpace(spaceGUID string) ([]Application, Warnings, error) | {
ccv2Apps, warnings, err := actor.CloudControllerClient.GetApplications(
ccv2.Filter{
Type: constant.SpaceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{spaceGUID},
},
)
if err != nil {
return []Application{}, Warnings(warnings), err
}
apps := make([]Application, len(ccv2Apps))
for i, ccv2App := range ccv2Apps {
apps[i] = Application(ccv2App)
}
return apps, Warnings(warnings), nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L184-L194 | go | train | // GetRouteApplications returns a list of apps associated with the provided
// Route GUID. | func (actor Actor) GetRouteApplications(routeGUID string) ([]Application, Warnings, error) | // GetRouteApplications returns a list of apps associated with the provided
// Route GUID.
func (actor Actor) GetRouteApplications(routeGUID string) ([]Application, Warnings, error) | {
apps, warnings, err := actor.CloudControllerClient.GetRouteApplications(routeGUID)
if err != nil {
return nil, Warnings(warnings), err
}
allApplications := []Application{}
for _, app := range apps {
allApplications = append(allApplications, Application(app))
}
return allApplications, Warnings(warnings), nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L198-L230 | go | train | // SetApplicationHealthCheckTypeByNameAndSpace updates an application's health
// check type if it is not already the desired type. | func (actor Actor) SetApplicationHealthCheckTypeByNameAndSpace(name string, spaceGUID string, healthCheckType constant.ApplicationHealthCheckType, httpEndpoint string) (Application, Warnings, error) | // SetApplicationHealthCheckTypeByNameAndSpace updates an application's health
// check type if it is not already the desired type.
func (actor Actor) SetApplicationHealthCheckTypeByNameAndSpace(name string, spaceGUID string, healthCheckType constant.ApplicationHealthCheckType, httpEndpoint string) (Application, Warnings, error) | {
if httpEndpoint != "/" && healthCheckType != constant.ApplicationHealthCheckHTTP {
return Application{}, nil, actionerror.HTTPHealthCheckInvalidError{}
}
var allWarnings Warnings
app, warnings, err := actor.GetApplicationByNameAndSpace(name, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return Application{}, allWarnings, err
}
if app.HealthCheckType != healthCheckType ||
healthCheckType == constant.ApplicationHealthCheckHTTP && app.HealthCheckHTTPEndpoint != httpEndpoint {
var healthCheckEndpoint string
if healthCheckType == constant.ApplicationHealthCheckHTTP {
healthCheckEndpoint = httpEndpoint
}
updatedApp, apiWarnings, err := actor.CloudControllerClient.UpdateApplication(ccv2.Application{
GUID: app.GUID,
HealthCheckType: healthCheckType,
HealthCheckHTTPEndpoint: healthCheckEndpoint,
})
allWarnings = append(allWarnings, Warnings(apiWarnings)...)
return Application(updatedApp), allWarnings, err
}
return app, allWarnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L234-L267 | go | train | // StartApplication restarts a given application. If already stopped, no stop
// call will be sent. | func (actor Actor) StartApplication(app Application, client NOAAClient) (<-chan *LogMessage, <-chan error, <-chan ApplicationStateChange, <-chan string, <-chan error) | // StartApplication restarts a given application. If already stopped, no stop
// call will be sent.
func (actor Actor) StartApplication(app Application, client NOAAClient) (<-chan *LogMessage, <-chan error, <-chan ApplicationStateChange, <-chan string, <-chan error) | {
messages, logErrs := actor.GetStreamingLogs(app.GUID, client)
appState := make(chan ApplicationStateChange)
allWarnings := make(chan string)
errs := make(chan error)
go func() {
defer close(appState)
defer close(allWarnings)
defer close(errs)
defer client.Close() // automatic close to prevent stale clients
if app.PackageState != constant.ApplicationPackageStaged {
appState <- ApplicationStateStaging
}
updatedApp, warnings, err := actor.CloudControllerClient.UpdateApplication(ccv2.Application{
GUID: app.GUID,
State: constant.ApplicationStarted,
})
for _, warning := range warnings {
allWarnings <- warning
}
if err != nil {
errs <- err
return
}
actor.waitForApplicationStageAndStart(Application(updatedApp), client, appState, allWarnings, errs)
}()
return messages, logErrs, appState, allWarnings, errs
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v2action/application.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/application.go#L323-L352 | go | train | // RestageApplication restarts a given application. If already stopped, no stop
// call will be sent. | func (actor Actor) RestageApplication(app Application, client NOAAClient) (<-chan *LogMessage, <-chan error, <-chan ApplicationStateChange, <-chan string, <-chan error) | // RestageApplication restarts a given application. If already stopped, no stop
// call will be sent.
func (actor Actor) RestageApplication(app Application, client NOAAClient) (<-chan *LogMessage, <-chan error, <-chan ApplicationStateChange, <-chan string, <-chan error) | {
messages, logErrs := actor.GetStreamingLogs(app.GUID, client)
appState := make(chan ApplicationStateChange)
allWarnings := make(chan string)
errs := make(chan error)
go func() {
defer close(appState)
defer close(allWarnings)
defer close(errs)
defer client.Close() // automatic close to prevent stale clients
appState <- ApplicationStateStaging
restagedApp, warnings, err := actor.CloudControllerClient.RestageApplication(ccv2.Application{
GUID: app.GUID,
})
for _, warning := range warnings {
allWarnings <- warning
}
if err != nil {
errs <- err
return
}
actor.waitForApplicationStageAndStart(Application(restagedApp), client, appState, allWarnings, errs)
}()
return messages, logErrs, appState, allWarnings, errs
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/pushaction/application_config.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/pushaction/application_config.go#L53-L137 | go | train | // ConvertToApplicationConfigs converts a set of application manifests into an
// application configs. These configs reflect the current and desired states of
// the application - providing details required by the Apply function to
// proceed.
//
// The V2 Actor is primarily used to determine all but multiple buildpack
// information. Only then is the V3 Actor used to gather the multiple
// buildpacks. | func (actor Actor) ConvertToApplicationConfigs(orgGUID string, spaceGUID string, noStart bool, apps []manifest.Application) ([]ApplicationConfig, Warnings, error) | // ConvertToApplicationConfigs converts a set of application manifests into an
// application configs. These configs reflect the current and desired states of
// the application - providing details required by the Apply function to
// proceed.
//
// The V2 Actor is primarily used to determine all but multiple buildpack
// information. Only then is the V3 Actor used to gather the multiple
// buildpacks.
func (actor Actor) ConvertToApplicationConfigs(orgGUID string, spaceGUID string, noStart bool, apps []manifest.Application) ([]ApplicationConfig, Warnings, error) | {
var configs []ApplicationConfig
var warnings Warnings
log.Infof("iterating through %d app configuration(s)", len(apps))
for _, app := range apps {
config := ApplicationConfig{
NoRoute: app.NoRoute,
}
if app.DropletPath != "" {
absPath, err := filepath.EvalSymlinks(app.DropletPath)
if err != nil {
return nil, nil, err
}
config.DropletPath = absPath
} else {
absPath, err := filepath.EvalSymlinks(app.Path)
if err != nil {
return nil, nil, err
}
config.Path = absPath
}
log.Infoln("searching for app", app.Name)
found, constructedApp, v2Warnings, err := actor.FindOrReturnPartialApp(app.Name, spaceGUID)
warnings = append(warnings, v2Warnings...)
if err != nil {
log.Errorln("app lookup:", err)
return nil, warnings, err
}
if found {
var configWarnings v2action.Warnings
config, configWarnings, err = actor.configureExistingApp(config, app, constructedApp)
warnings = append(warnings, configWarnings...)
if err != nil {
log.Errorln("configuring existing app:", err)
return nil, warnings, err
}
} else {
log.Debug("using empty app as base")
config.DesiredApplication = constructedApp
}
config.DesiredApplication = actor.overrideApplicationProperties(config.DesiredApplication, app, noStart)
var stackWarnings Warnings
config.DesiredApplication, stackWarnings, err = actor.overrideStack(config.DesiredApplication, app)
warnings = append(warnings, stackWarnings...)
if err != nil {
return nil, warnings, err
}
log.Debugln("post overriding config:", config.DesiredApplication)
var serviceWarnings Warnings
config.DesiredServices, serviceWarnings, err = actor.getDesiredServices(config.CurrentServices, app.Services, spaceGUID)
warnings = append(warnings, serviceWarnings...)
if err != nil {
log.Errorln("getting services:", err)
return nil, warnings, err
}
if !config.NoRoute {
var routeWarnings Warnings
config, routeWarnings, err = actor.configureRoutes(app, orgGUID, spaceGUID, config)
warnings = append(warnings, routeWarnings...)
if err != nil {
log.Errorln("determining routes:", err)
return nil, warnings, err
}
}
if app.DockerImage == "" && app.DropletPath == "" {
config, err = actor.configureResources(config)
if err != nil {
log.Errorln("configuring resources", err)
return nil, warnings, err
}
}
configs = append(configs, config)
}
return configs, warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/router/router_group.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/router/router_group.go#L19-L46 | go | train | // GetRouterGroupByName returns a list of RouterGroups. | func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) | // GetRouterGroupByName returns a list of RouterGroups.
func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouterGroups,
Query: url.Values{"name": []string{name}},
})
if err != nil {
return RouterGroup{}, err
}
var routerGroups []RouterGroup
var response = Response{
Result: &routerGroups,
}
err = client.connection.Make(request, &response)
if err != nil {
return RouterGroup{}, err
}
for _, routerGroup := range routerGroups {
if routerGroup.Name == name {
return routerGroup, nil
}
}
return RouterGroup{}, routererror.ResourceNotFoundError{}
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/build.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/build.go#L31-L41 | go | train | // MarshalJSON converts a Build into a Cloud Controller Application. | func (b Build) MarshalJSON() ([]byte, error) | // MarshalJSON converts a Build into a Cloud Controller Application.
func (b Build) MarshalJSON() ([]byte, error) | {
var ccBuild struct {
Package struct {
GUID string `json:"guid"`
} `json:"package"`
}
ccBuild.Package.GUID = b.PackageGUID
return json.Marshal(ccBuild)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/build.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/build.go#L44-L71 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Build response. | func (b *Build) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Build response.
func (b *Build) UnmarshalJSON(data []byte) error | {
var ccBuild struct {
CreatedAt string `json:"created_at,omitempty"`
GUID string `json:"guid,omitempty"`
Error string `json:"error"`
Package struct {
GUID string `json:"guid"`
} `json:"package"`
State constant.BuildState `json:"state,omitempty"`
Droplet struct {
GUID string `json:"guid"`
} `json:"droplet"`
}
err := cloudcontroller.DecodeJSON(data, &ccBuild)
if err != nil {
return err
}
b.GUID = ccBuild.GUID
b.CreatedAt = ccBuild.CreatedAt
b.Error = ccBuild.Error
b.PackageGUID = ccBuild.Package.GUID
b.State = ccBuild.State
b.DropletGUID = ccBuild.Droplet.GUID
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/build.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/build.go#L75-L96 | go | train | // CreateBuild creates the given build, requires Package GUID to be set on the
// build. | func (client *Client) CreateBuild(build Build) (Build, Warnings, error) | // CreateBuild creates the given build, requires Package GUID to be set on the
// build.
func (client *Client) CreateBuild(build Build) (Build, Warnings, error) | {
bodyBytes, err := json.Marshal(build)
if err != nil {
return Build{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostBuildRequest,
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return Build{}, nil, err
}
var responseBuild Build
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseBuild,
}
err = client.connection.Make(request, &response)
return responseBuild, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/build.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/build.go#L99-L115 | go | train | // GetBuild gets the build with the given GUID. | func (client *Client) GetBuild(guid string) (Build, Warnings, error) | // GetBuild gets the build with the given GUID.
func (client *Client) GetBuild(guid string) (Build, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetBuildRequest,
URIParams: internal.Params{"build_guid": guid},
})
if err != nil {
return Build{}, nil, err
}
var responseBuild Build
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseBuild,
}
err = client.connection.Make(request, &response)
return responseBuild, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v7action/ssh.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v7action/ssh.go#L18-L60 | go | train | // GetSecureShellConfigurationByApplicationNameSpaceProcessTypeAndIndex returns
// back the SSH authentication information for the SSH session. | func (actor Actor) GetSecureShellConfigurationByApplicationNameSpaceProcessTypeAndIndex(
appName string, spaceGUID string, processType string, processIndex uint,
) (SSHAuthentication, Warnings, error) | // GetSecureShellConfigurationByApplicationNameSpaceProcessTypeAndIndex returns
// back the SSH authentication information for the SSH session.
func (actor Actor) GetSecureShellConfigurationByApplicationNameSpaceProcessTypeAndIndex(
appName string, spaceGUID string, processType string, processIndex uint,
) (SSHAuthentication, Warnings, error) | {
var allWarnings Warnings
endpoint := actor.CloudControllerClient.AppSSHEndpoint()
if endpoint == "" {
return SSHAuthentication{}, nil, actionerror.SSHEndpointNotSetError{}
}
fingerprint := actor.CloudControllerClient.AppSSHHostKeyFingerprint()
if fingerprint == "" {
return SSHAuthentication{}, nil, actionerror.SSHHostKeyFingerprintNotSetError{}
}
passcode, err := actor.UAAClient.GetSSHPasscode(actor.Config.AccessToken(), actor.Config.SSHOAuthClient())
if err != nil {
return SSHAuthentication{}, Warnings{}, err
}
application, appWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, appWarnings...)
if err != nil {
return SSHAuthentication{}, allWarnings, err
}
if !application.Started() {
return SSHAuthentication{}, allWarnings, actionerror.ApplicationNotStartedError{Name: appName}
}
username, processWarnings, err := actor.getUsername(application, processType, processIndex)
allWarnings = append(allWarnings, processWarnings...)
if err != nil {
return SSHAuthentication{}, allWarnings, err
}
return SSHAuthentication{
Endpoint: endpoint,
HostKeyFingerprint: fingerprint,
Passcode: passcode,
Username: username,
}, allWarnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v3action/environment_variable.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/environment_variable.go#L20-L29 | go | train | // GetEnvironmentVariablesByApplicationNameAndSpace returns the environment
// variables for an application. | func (actor *Actor) GetEnvironmentVariablesByApplicationNameAndSpace(appName string, spaceGUID string) (EnvironmentVariableGroups, Warnings, error) | // GetEnvironmentVariablesByApplicationNameAndSpace returns the environment
// variables for an application.
func (actor *Actor) GetEnvironmentVariablesByApplicationNameAndSpace(appName string, spaceGUID string) (EnvironmentVariableGroups, Warnings, error) | {
app, warnings, appErr := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
if appErr != nil {
return EnvironmentVariableGroups{}, warnings, appErr
}
ccEnvGroups, v3Warnings, apiErr := actor.CloudControllerClient.GetApplicationEnvironment(app.GUID)
warnings = append(warnings, v3Warnings...)
return EnvironmentVariableGroups(ccEnvGroups), warnings, apiErr
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v3action/environment_variable.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/environment_variable.go#L34-L47 | go | train | // SetEnvironmentVariableByApplicationNameAndSpace adds an
// EnvironmentVariablePair to an application. It must be restarted for changes
// to take effect. | func (actor *Actor) SetEnvironmentVariableByApplicationNameAndSpace(appName string, spaceGUID string, envPair EnvironmentVariablePair) (Warnings, error) | // SetEnvironmentVariableByApplicationNameAndSpace adds an
// EnvironmentVariablePair to an application. It must be restarted for changes
// to take effect.
func (actor *Actor) SetEnvironmentVariableByApplicationNameAndSpace(appName string, spaceGUID string, envPair EnvironmentVariablePair) (Warnings, error) | {
app, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
if err != nil {
return warnings, err
}
_, v3Warnings, apiErr := actor.CloudControllerClient.UpdateApplicationEnvironmentVariables(
app.GUID,
ccv3.EnvironmentVariables{
envPair.Key: {Value: envPair.Value, IsSet: true},
})
warnings = append(warnings, v3Warnings...)
return warnings, apiErr
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v3action/environment_variable.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/environment_variable.go#L52-L74 | go | train | // UnsetEnvironmentVariableByApplicationNameAndSpace removes an enviornment
// variable from an application. It must be restarted for changes to take
// effect. | func (actor *Actor) UnsetEnvironmentVariableByApplicationNameAndSpace(appName string, spaceGUID string, environmentVariableName string) (Warnings, error) | // UnsetEnvironmentVariableByApplicationNameAndSpace removes an enviornment
// variable from an application. It must be restarted for changes to take
// effect.
func (actor *Actor) UnsetEnvironmentVariableByApplicationNameAndSpace(appName string, spaceGUID string, environmentVariableName string) (Warnings, error) | {
app, warnings, appErr := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
if appErr != nil {
return warnings, appErr
}
envGroups, getWarnings, getErr := actor.CloudControllerClient.GetApplicationEnvironment(app.GUID)
warnings = append(warnings, getWarnings...)
if getErr != nil {
return warnings, getErr
}
if _, ok := envGroups.EnvironmentVariables[environmentVariableName]; !ok {
return warnings, actionerror.EnvironmentVariableNotSetError{EnvironmentVariableName: environmentVariableName}
}
_, patchWarnings, patchErr := actor.CloudControllerClient.UpdateApplicationEnvironmentVariables(
app.GUID,
ccv3.EnvironmentVariables{
environmentVariableName: {Value: "", IsSet: false},
})
warnings = append(warnings, patchWarnings...)
return warnings, patchErr
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/prompt.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/prompt.go#L36-L49 | go | train | // DisplayBoolPrompt outputs the prompt and waits for user input. It only
// allows for a boolean response. A default boolean response can be set with
// defaultResponse. | func (ui *UI) DisplayBoolPrompt(defaultResponse bool, template string, templateValues ...map[string]interface{}) (bool, error) | // DisplayBoolPrompt outputs the prompt and waits for user input. It only
// allows for a boolean response. A default boolean response can be set with
// defaultResponse.
func (ui *UI) DisplayBoolPrompt(defaultResponse bool, template string, templateValues ...map[string]interface{}) (bool, error) | {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
response := defaultResponse
interactivePrompt := ui.Interactor.NewInteraction(ui.TranslateText(template, templateValues...))
interactivePrompt.SetIn(ui.In)
interactivePrompt.SetOut(ui.OutForInteration)
err := interactivePrompt.Resolve(&response)
if isInterrupt(err) {
ui.Exiter.Exit(sigIntExitCode)
}
return response, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/prompt.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/prompt.go#L66-L79 | go | train | // DisplayPasswordPrompt outputs the prompt and waits for user input. Hides
// user's response from the screen. | func (ui *UI) DisplayPasswordPrompt(template string, templateValues ...map[string]interface{}) (string, error) | // DisplayPasswordPrompt outputs the prompt and waits for user input. Hides
// user's response from the screen.
func (ui *UI) DisplayPasswordPrompt(template string, templateValues ...map[string]interface{}) (string, error) | {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
var password interact.Password
interactivePrompt := ui.Interactor.NewInteraction(ui.TranslateText(template, templateValues...))
interactivePrompt.SetIn(ui.In)
interactivePrompt.SetOut(ui.OutForInteration)
err := interactivePrompt.Resolve(interact.Required(&password))
if isInterrupt(err) {
ui.Exiter.Exit(sigIntExitCode)
}
return string(password), err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/prompt.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/prompt.go#L83-L123 | go | train | // DisplayTextMenu lets the user choose from a list of options, either by name
// or by number. | func (ui *UI) DisplayTextMenu(choices []string, promptTemplate string, templateValues ...map[string]interface{}) (string, error) | // DisplayTextMenu lets the user choose from a list of options, either by name
// or by number.
func (ui *UI) DisplayTextMenu(choices []string, promptTemplate string, templateValues ...map[string]interface{}) (string, error) | {
for i, c := range choices {
t := fmt.Sprintf("%d. %s", i+1, c)
ui.DisplayText(t)
}
translatedPrompt := ui.TranslateText(promptTemplate, templateValues...)
interactivePrompt := ui.Interactor.NewInteraction(translatedPrompt)
interactivePrompt.SetIn(ui.In)
interactivePrompt.SetOut(ui.OutForInteration)
var value string = "enter to skip"
err := interactivePrompt.Resolve(&value)
if isInterrupt(err) {
ui.Exiter.Exit(sigIntExitCode)
}
if err != nil {
return "", err
}
if value == "enter to skip" {
return "", nil
}
i, err := strconv.Atoi(value)
if err != nil {
if contains(choices, value) {
return value, nil
}
return "", InvalidChoiceError{Choice: value}
}
if i > len(choices) || i <= 0 {
return "", ErrInvalidIndex
}
return choices[i-1], nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/ui/prompt.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/prompt.go#L126-L136 | go | train | // DisplayTextPrompt outputs the prompt and waits for user input. | func (ui *UI) DisplayTextPrompt(template string, templateValues ...map[string]interface{}) (string, error) | // DisplayTextPrompt outputs the prompt and waits for user input.
func (ui *UI) DisplayTextPrompt(template string, templateValues ...map[string]interface{}) (string, error) | {
interactivePrompt := ui.Interactor.NewInteraction(ui.TranslateText(template, templateValues...))
var value string
interactivePrompt.SetIn(ui.In)
interactivePrompt.SetOut(ui.OutForInteration)
err := interactivePrompt.Resolve(interact.Required(&value))
if isInterrupt(err) {
ui.Exiter.Exit(sigIntExitCode)
}
return value, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | types/null_bytesize_in_mb.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/types/null_bytesize_in_mb.go#L45-L54 | go | train | // ParseUint64Value is used to parse a user provided *uint64 argument. | func (b *NullByteSizeInMb) ParseUint64Value(val *uint64) | // ParseUint64Value is used to parse a user provided *uint64 argument.
func (b *NullByteSizeInMb) ParseUint64Value(val *uint64) | {
if val == nil {
b.IsSet = false
b.Value = 0
return
}
b.Value = *val
b.IsSet = true
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L39-L62 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Route response. | func (route *Route) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Route response.
func (route *Route) UnmarshalJSON(data []byte) error | {
var ccRoute struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Host string `json:"host"`
Path string `json:"path"`
Port types.NullInt `json:"port"`
DomainGUID string `json:"domain_guid"`
SpaceGUID string `json:"space_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccRoute)
if err != nil {
return err
}
route.GUID = ccRoute.Metadata.GUID
route.Host = ccRoute.Entity.Host
route.Path = ccRoute.Entity.Path
route.Port = ccRoute.Entity.Port
route.DomainGUID = ccRoute.Entity.DomainGUID
route.SpaceGUID = ccRoute.Entity.SpaceGUID
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L65-L93 | go | train | // CheckRoute returns true if the route exists in the CF instance. | func (client *Client) CheckRoute(route Route) (bool, Warnings, error) | // CheckRoute returns true if the route exists in the CF instance.
func (client *Client) CheckRoute(route Route) (bool, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteReservedRequest,
URIParams: map[string]string{"domain_guid": route.DomainGUID},
})
if err != nil {
return false, nil, err
}
queryParams := url.Values{}
if route.Host != "" {
queryParams.Add("host", route.Host)
}
if route.Path != "" {
queryParams.Add("path", route.Path)
}
if route.Port.IsSet {
queryParams.Add("port", fmt.Sprint(route.Port.Value))
}
request.URL.RawQuery = queryParams.Encode()
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return false, response.Warnings, nil
}
return response.HTTPResponse.StatusCode == http.StatusNoContent, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L101-L128 | go | train | // CreateRoute creates the route with the given properties; SpaceGUID and
// DomainGUID are required Route properties. Additional configuration rules:
// - generatePort = true to generate a random port on the cloud controller.
// - generatePort takes precedence over the provided port. Setting the port and
// generatePort only works with CC API 2.53.0 or higher and when TCP router
// groups are enabled. | func (client *Client) CreateRoute(route Route, generatePort bool) (Route, Warnings, error) | // CreateRoute creates the route with the given properties; SpaceGUID and
// DomainGUID are required Route properties. Additional configuration rules:
// - generatePort = true to generate a random port on the cloud controller.
// - generatePort takes precedence over the provided port. Setting the port and
// generatePort only works with CC API 2.53.0 or higher and when TCP router
// groups are enabled.
func (client *Client) CreateRoute(route Route, generatePort bool) (Route, Warnings, error) | {
body, err := json.Marshal(route)
if err != nil {
return Route{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostRouteRequest,
Body: bytes.NewReader(body),
})
if err != nil {
return Route{}, nil, err
}
if generatePort {
query := url.Values{}
query.Add("generate_port", "true")
request.URL.RawQuery = query.Encode()
}
var updatedRoute Route
response := cloudcontroller.Response{
DecodeJSONResponseInto: &updatedRoute,
}
err = client.connection.Make(request, &response)
return updatedRoute, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L131-L143 | go | train | // DeleteRoute deletes the Route associated with the provided Route GUID. | func (client *Client) DeleteRoute(routeGUID string) (Warnings, error) | // DeleteRoute deletes the Route associated with the provided Route GUID.
func (client *Client) DeleteRoute(routeGUID string) (Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.DeleteRouteRequest,
URIParams: map[string]string{"route_guid": routeGUID},
})
if err != nil {
return nil, err
}
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
return response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L146-L161 | go | train | // DeleteRouteApplication removes the link between the route and application. | func (client *Client) DeleteRouteApplication(routeGUID string, appGUID string) (Warnings, error) | // DeleteRouteApplication removes the link between the route and application.
func (client *Client) DeleteRouteApplication(routeGUID string, appGUID string) (Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.DeleteRouteAppRequest,
URIParams: map[string]string{
"app_guid": appGUID,
"route_guid": routeGUID,
},
})
if err != nil {
return nil, err
}
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
return response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L165-L177 | go | train | // DeleteSpaceUnmappedRoutes deletes Routes within a specified Space not mapped
// to an Application | func (client *Client) DeleteSpaceUnmappedRoutes(spaceGUID string) (Warnings, error) | // DeleteSpaceUnmappedRoutes deletes Routes within a specified Space not mapped
// to an Application
func (client *Client) DeleteSpaceUnmappedRoutes(spaceGUID string) (Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.DeleteSpaceUnmappedRoutesRequest,
URIParams: map[string]string{"space_guid": spaceGUID},
})
if err != nil {
return nil, err
}
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
return response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L208-L224 | go | train | // GetRoute returns a route with the provided guid. | func (client *Client) GetRoute(guid string) (Route, Warnings, error) | // GetRoute returns a route with the provided guid.
func (client *Client) GetRoute(guid string) (Route, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteRequest,
URIParams: Params{"route_guid": guid},
})
if err != nil {
return Route{}, nil, err
}
var route Route
response := cloudcontroller.Response{
DecodeJSONResponseInto: &route,
}
err = client.connection.Make(request, &response)
return route, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L227-L250 | go | train | // GetRoutes returns a list of Routes based off of the provided filters. | func (client *Client) GetRoutes(filters ...Filter) ([]Route, Warnings, error) | // GetRoutes returns a list of Routes based off of the provided filters.
func (client *Client) GetRoutes(filters ...Filter) ([]Route, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRoutesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRoutesList []Route
warnings, err := client.paginate(request, Route{}, func(item interface{}) error {
if route, ok := item.(Route); ok {
fullRoutesList = append(fullRoutesList, route)
} else {
return ccerror.UnknownObjectInListError{
Expected: Route{},
Unexpected: item,
}
}
return nil
})
return fullRoutesList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L254-L278 | go | train | // GetSpaceRoutes returns a list of Routes associated with the provided Space
// GUID, and filtered by the provided filters. | func (client *Client) GetSpaceRoutes(spaceGUID string, filters ...Filter) ([]Route, Warnings, error) | // GetSpaceRoutes returns a list of Routes associated with the provided Space
// GUID, and filtered by the provided filters.
func (client *Client) GetSpaceRoutes(spaceGUID string, filters ...Filter) ([]Route, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceRoutesRequest,
URIParams: map[string]string{"space_guid": spaceGUID},
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRoutesList []Route
warnings, err := client.paginate(request, Route{}, func(item interface{}) error {
if route, ok := item.(Route); ok {
fullRoutesList = append(fullRoutesList, route)
} else {
return ccerror.UnknownObjectInListError{
Expected: Route{},
Unexpected: item,
}
}
return nil
})
return fullRoutesList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route.go#L281-L300 | go | train | // UpdateRouteApplication creates a link between the route and application. | func (client *Client) UpdateRouteApplication(routeGUID string, appGUID string) (Route, Warnings, error) | // UpdateRouteApplication creates a link between the route and application.
func (client *Client) UpdateRouteApplication(routeGUID string, appGUID string) (Route, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutRouteAppRequest,
URIParams: map[string]string{
"app_guid": appGUID,
"route_guid": routeGUID,
},
})
if err != nil {
return Route{}, nil, err
}
var route Route
response := cloudcontroller.Response{
DecodeJSONResponseInto: &route,
}
err = client.connection.Make(request, &response)
return route, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/process.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/process.go#L81-L102 | go | train | // CreateApplicationProcessScale updates process instances count, memory or disk | func (client *Client) CreateApplicationProcessScale(appGUID string, process Process) (Process, Warnings, error) | // CreateApplicationProcessScale updates process instances count, memory or disk
func (client *Client) CreateApplicationProcessScale(appGUID string, process Process) (Process, Warnings, error) | {
body, err := json.Marshal(process)
if err != nil {
return Process{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostApplicationProcessActionScaleRequest,
Body: bytes.NewReader(body),
URIParams: internal.Params{"app_guid": appGUID, "type": process.Type},
})
if err != nil {
return Process{}, nil, err
}
var responseProcess Process
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseProcess,
}
err = client.connection.Make(request, &response)
return responseProcess, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/process.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/process.go#L105-L123 | go | train | // GetApplicationProcessByType returns application process of specified type | func (client *Client) GetApplicationProcessByType(appGUID string, processType string) (Process, Warnings, error) | // GetApplicationProcessByType returns application process of specified type
func (client *Client) GetApplicationProcessByType(appGUID string, processType string) (Process, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationProcessRequest,
URIParams: map[string]string{
"app_guid": appGUID,
"type": processType,
},
})
if err != nil {
return Process{}, nil, err
}
var process Process
response := cloudcontroller.Response{
DecodeJSONResponseInto: &process,
}
err = client.connection.Make(request, &response)
return process, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/process.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/process.go#L127-L150 | go | train | // GetApplicationProcesses lists processes for a given application. **Note**:
// Due to security, the API obfuscates certain values such as `command`. | func (client *Client) GetApplicationProcesses(appGUID string) ([]Process, Warnings, error) | // GetApplicationProcesses lists processes for a given application. **Note**:
// Due to security, the API obfuscates certain values such as `command`.
func (client *Client) GetApplicationProcesses(appGUID string) ([]Process, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationProcessesRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return nil, nil, err
}
var fullProcessesList []Process
warnings, err := client.paginate(request, Process{}, func(item interface{}) error {
if process, ok := item.(Process); ok {
fullProcessesList = append(fullProcessesList, process)
} else {
return ccerror.UnknownObjectInListError{
Expected: Process{},
Unexpected: item,
}
}
return nil
})
return fullProcessesList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/process.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/process.go#L155-L182 | go | train | // UpdateProcess updates the process's command or health check settings. GUID
// is always required; HealthCheckType is only required when updating health
// check settings. | func (client *Client) UpdateProcess(process Process) (Process, Warnings, error) | // UpdateProcess updates the process's command or health check settings. GUID
// is always required; HealthCheckType is only required when updating health
// check settings.
func (client *Client) UpdateProcess(process Process) (Process, Warnings, error) | {
body, err := json.Marshal(Process{
Command: process.Command,
HealthCheckType: process.HealthCheckType,
HealthCheckEndpoint: process.HealthCheckEndpoint,
HealthCheckTimeout: process.HealthCheckTimeout,
HealthCheckInvocationTimeout: process.HealthCheckInvocationTimeout,
})
if err != nil {
return Process{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PatchProcessRequest,
Body: bytes.NewReader(body),
URIParams: internal.Params{"process_guid": process.GUID},
})
if err != nil {
return Process{}, nil, err
}
var responseProcess Process
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseProcess,
}
err = client.connection.Make(request, &response)
return responseProcess, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/service_instance_shared_to.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_instance_shared_to.go#L29-L53 | go | train | // GetServiceInstanceSharedTos returns a list of ServiceInstanceSharedTo objects. | func (client *Client) GetServiceInstanceSharedTos(serviceInstanceGUID string) ([]ServiceInstanceSharedTo, Warnings, error) | // GetServiceInstanceSharedTos returns a list of ServiceInstanceSharedTo objects.
func (client *Client) GetServiceInstanceSharedTos(serviceInstanceGUID string) ([]ServiceInstanceSharedTo, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstanceSharedToRequest,
URIParams: Params{"service_instance_guid": serviceInstanceGUID},
})
if err != nil {
return nil, nil, err
}
var fullSharedToList []ServiceInstanceSharedTo
warnings, err := client.paginate(request, ServiceInstanceSharedTo{}, func(item interface{}) error {
if instance, ok := item.(ServiceInstanceSharedTo); ok {
fullSharedToList = append(fullSharedToList, instance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstanceSharedTo{},
Unexpected: item,
}
}
return nil
})
return fullSharedToList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/uaa_connection.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/uaa_connection.go#L21-L45 | go | train | // NewConnection returns a pointer to a new UAA Connection | func NewConnection(skipSSLValidation bool, disableKeepAlives bool, dialTimeout time.Duration) *UAAConnection | // NewConnection returns a pointer to a new UAA Connection
func NewConnection(skipSSLValidation bool, disableKeepAlives bool, dialTimeout time.Duration) *UAAConnection | {
tr := &http.Transport{
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: dialTimeout,
}).DialContext,
DisableKeepAlives: disableKeepAlives,
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipSSLValidation,
},
}
return &UAAConnection{
HTTPClient: &http.Client{
Transport: tr,
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
// This prevents redirects. When making a request to /oauth/authorize,
// the client should not follow redirects in order to obtain the ssh
// passcode.
return http.ErrUseLastResponse
},
},
}
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/uaa_connection.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/uaa_connection.go#L49-L61 | go | train | // Make takes a passedRequest, converts it into an HTTP request and then
// executes it. The response is then injected into passedResponse. | func (connection *UAAConnection) Make(request *http.Request, passedResponse *Response) error | // Make takes a passedRequest, converts it into an HTTP request and then
// executes it. The response is then injected into passedResponse.
func (connection *UAAConnection) Make(request *http.Request, passedResponse *Response) error | {
// In case this function is called from a retry, passedResponse may already
// be populated with a previous response. We reset in case there's an HTTP
// error and we don't repopulate it in populateResponse.
passedResponse.reset()
response, err := connection.HTTPClient.Do(request)
if err != nil {
return connection.processRequestErrors(request, err)
}
return connection.populateResponse(response, passedResponse)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/event.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/event.go#L46-L81 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Event response. | func (event *Event) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Event response.
func (event *Event) UnmarshalJSON(data []byte) error | {
var ccEvent struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Type string `json:"type,omitempty"`
ActorGUID string `json:"actor,omitempty"`
ActorType string `json:"actor_type,omitempty"`
ActorName string `json:"actor_name,omitempty"`
ActeeGUID string `json:"actee,omitempty"`
ActeeType string `json:"actee_type,omitempty"`
ActeeName string `json:"actee_name,omitempty"`
Timestamp *time.Time `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccEvent)
if err != nil {
return err
}
event.GUID = ccEvent.Metadata.GUID
event.Type = constant.EventType(ccEvent.Entity.Type)
event.ActorGUID = ccEvent.Entity.ActorGUID
event.ActorType = ccEvent.Entity.ActorType
event.ActorName = ccEvent.Entity.ActorName
event.ActeeGUID = ccEvent.Entity.ActeeGUID
event.ActeeType = ccEvent.Entity.ActeeType
event.ActeeName = ccEvent.Entity.ActeeName
if ccEvent.Entity.Timestamp != nil {
event.Timestamp = *ccEvent.Entity.Timestamp
}
event.Metadata = ccEvent.Entity.Metadata
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/event.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/event.go#L84-L107 | go | train | // GetEvents returns back a list of Events based off of the provided queries. | func (client *Client) GetEvents(filters ...Filter) ([]Event, Warnings, error) | // GetEvents returns back a list of Events based off of the provided queries.
func (client *Client) GetEvents(filters ...Filter) ([]Event, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetEventsRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullEventsList []Event
warnings, err := client.paginate(request, Event{}, func(item interface{}) error {
if event, ok := item.(Event); ok {
fullEventsList = append(fullEventsList, event)
} else {
return ccerror.UnknownObjectInListError{
Expected: Event{},
Unexpected: item,
}
}
return nil
})
return fullEventsList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/v2_formatted_resource.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/v2_formatted_resource.go#L50-L73 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller V2FormattedResource response. | func (r *V2FormattedResource) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller V2FormattedResource response.
func (r *V2FormattedResource) UnmarshalJSON(data []byte) error | {
var ccResource struct {
Filename string `json:"fn,omitempty"`
Mode string `json:"mode,omitempty"`
SHA1 string `json:"sha1"`
Size int64 `json:"size"`
}
err := cloudcontroller.DecodeJSON(data, &ccResource)
if err != nil {
return err
}
r.Filename = ccResource.Filename
r.Size = ccResource.Size
r.SHA1 = ccResource.SHA1
mode, err := strconv.ParseUint(ccResource.Mode, 8, 32)
if err != nil {
return err
}
r.Mode = os.FileMode(mode)
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/auth.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/auth.go#L22-L72 | go | train | // Authenticate sends a username and password to UAA then returns an access
// token and a refresh token. | func (client Client) Authenticate(creds map[string]string, origin string, grantType constant.GrantType) (string, string, error) | // Authenticate sends a username and password to UAA then returns an access
// token and a refresh token.
func (client Client) Authenticate(creds map[string]string, origin string, grantType constant.GrantType) (string, string, error) | {
requestBody := url.Values{
"grant_type": {string(grantType)},
}
for k, v := range creds {
requestBody.Set(k, v)
}
type loginHint struct {
Origin string `json:"origin"`
}
originStruct := loginHint{origin}
originParam, err := json.Marshal(originStruct)
if err != nil {
return "", "", err
}
var query url.Values
if origin != "" {
query = url.Values{
"login_hint": {string(originParam)},
}
}
request, err := client.newRequest(requestOptions{
RequestName: internal.PostOAuthTokenRequest,
Header: http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
},
Body: strings.NewReader(requestBody.Encode()),
Query: query,
})
if err != nil {
return "", "", err
}
if grantType == constant.GrantTypePassword {
request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
}
responseBody := AuthResponse{}
response := Response{
Result: &responseBody,
}
err = client.connection.Make(request, &response)
return responseBody.AccessToken, responseBody.RefreshToken, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/router/request.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/router/request.go#L56-L83 | go | train | // newHTTPRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request fields are not filled in. | func (client Client) newHTTPRequest(passedRequest requestOptions) (*Request, error) | // newHTTPRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request fields are not filled in.
func (client Client) newHTTPRequest(passedRequest requestOptions) (*Request, error) | {
request, err := client.router.CreateRequest(
passedRequest.RequestName,
rata.Params(passedRequest.URIParams),
passedRequest.Body,
)
if err != nil {
return nil, err
}
if passedRequest.Query != nil {
request.URL.RawQuery = passedRequest.Query.Encode()
}
if passedRequest.Header != nil {
request.Header = passedRequest.Header
} else {
request.Header = http.Header{}
}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Connection", "close")
request.Header.Set("User-Agent", client.userAgent)
return &Request{Request: request, body: passedRequest.Body}, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/organization_quota.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/organization_quota.go#L20-L36 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller organization quota response. | func (application *OrganizationQuota) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller organization quota response.
func (application *OrganizationQuota) UnmarshalJSON(data []byte) error | {
var ccOrgQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccOrgQuota)
if err != nil {
return err
}
application.GUID = ccOrgQuota.Metadata.GUID
application.Name = ccOrgQuota.Entity.Name
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/organization_quota.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/organization_quota.go#L40-L56 | go | train | // GetOrganizationQuota returns an Organization Quota associated with the
// provided GUID. | func (client *Client) GetOrganizationQuota(guid string) (OrganizationQuota, Warnings, error) | // GetOrganizationQuota returns an Organization Quota associated with the
// provided GUID.
func (client *Client) GetOrganizationQuota(guid string) (OrganizationQuota, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationQuotaDefinitionRequest,
URIParams: Params{"organization_quota_guid": guid},
})
if err != nil {
return OrganizationQuota{}, nil, err
}
var orgQuota OrganizationQuota
response := cloudcontroller.Response{
DecodeJSONResponseInto: &orgQuota,
}
err = client.connection.Make(request, &response)
return orgQuota, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/organization_quota.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/organization_quota.go#L60-L86 | go | train | // GetOrganizationQuotas returns an Organization Quota list associated with the
// provided filters. | func (client *Client) GetOrganizationQuotas(filters ...Filter) ([]OrganizationQuota, Warnings, error) | // GetOrganizationQuotas returns an Organization Quota list associated with the
// provided filters.
func (client *Client) GetOrganizationQuotas(filters ...Filter) ([]OrganizationQuota, Warnings, error) | {
allQueries := ConvertFilterParameters(filters)
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationQuotaDefinitionsRequest,
Query: allQueries,
})
if err != nil {
return []OrganizationQuota{}, nil, err
}
var fullOrgQuotasList []OrganizationQuota
warnings, err := client.paginate(request, OrganizationQuota{}, func(item interface{}) error {
if org, ok := item.(OrganizationQuota); ok {
fullOrgQuotasList = append(fullOrgQuotasList, org)
} else {
return ccerror.UnknownObjectInListError{
Expected: OrganizationQuota{},
Unexpected: item,
}
}
return nil
})
return fullOrgQuotasList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/v7action/process.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v7action/process.go#L15-L21 | go | train | // GetProcessByTypeAndApplication returns a process for the given application
// and type. | func (actor Actor) GetProcessByTypeAndApplication(processType string, appGUID string) (Process, Warnings, error) | // GetProcessByTypeAndApplication returns a process for the given application
// and type.
func (actor Actor) GetProcessByTypeAndApplication(processType string, appGUID string) (Process, Warnings, error) | {
process, warnings, err := actor.CloudControllerClient.GetApplicationProcessByType(appGUID, processType)
if _, ok := err.(ccerror.ProcessNotFoundError); ok {
return Process{}, Warnings(warnings), actionerror.ProcessNotFoundError{ProcessType: processType}
}
return Process(process), Warnings(warnings), err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | types/filtered_string.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/types/filtered_string.go#L27-L42 | go | train | // ParseValue is used to parse a user provided flag argument. | func (n *FilteredString) ParseValue(val string) | // ParseValue is used to parse a user provided flag argument.
func (n *FilteredString) ParseValue(val string) | {
if val == "" {
n.IsSet = false
n.Value = ""
return
}
n.IsSet = true
switch val {
case "null", "default":
n.Value = ""
default:
n.Value = val
}
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | types/filtered_string.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/types/filtered_string.go#L68-L74 | go | train | // MarshalJSON marshals the value field if it's not empty, otherwise returns an
// null. | func (n FilteredString) MarshalJSON() ([]byte, error) | // MarshalJSON marshals the value field if it's not empty, otherwise returns an
// null.
func (n FilteredString) MarshalJSON() ([]byte, error) | {
if n.Value != "" {
return json.Marshal(n.Value)
}
return json.Marshal(new(json.RawMessage))
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/decode_json.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/decode_json.go#L10-L14 | go | train | // DecodeJSON unmarshals JSON into the given object with the appropriate
// settings. | func DecodeJSON(raw []byte, v interface{}) error | // DecodeJSON unmarshals JSON into the given object with the appropriate
// settings.
func DecodeJSON(raw []byte, v interface{}) error | {
decoder := json.NewDecoder(bytes.NewBuffer(raw))
decoder.UseNumber()
return decoder.Decode(v)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/deployment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/deployment.go#L23-L40 | go | train | // MarshalJSON converts a Deployment into a Cloud Controller Deployment. | func (d Deployment) MarshalJSON() ([]byte, error) | // MarshalJSON converts a Deployment into a Cloud Controller Deployment.
func (d Deployment) MarshalJSON() ([]byte, error) | {
type Droplet struct {
GUID string `json:"guid,omitempty"`
}
var ccDeployment struct {
Droplet *Droplet `json:"droplet,omitempty"`
Relationships Relationships `json:"relationships,omitempty"`
}
if d.DropletGUID != "" {
ccDeployment.Droplet = &Droplet{d.DropletGUID}
}
ccDeployment.Relationships = d.Relationships
return json.Marshal(ccDeployment)
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/deployment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/deployment.go#L43-L63 | go | train | // UnmarshalJSON helps unmarshal a Cloud Controller Deployment response. | func (d *Deployment) UnmarshalJSON(data []byte) error | // UnmarshalJSON helps unmarshal a Cloud Controller Deployment response.
func (d *Deployment) UnmarshalJSON(data []byte) error | {
var ccDeployment struct {
GUID string `json:"guid,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Relationships Relationships `json:"relationships,omitempty"`
State constant.DeploymentState `json:"state,omitempty"`
Droplet Droplet `json:"droplet,omitempty"`
}
err := cloudcontroller.DecodeJSON(data, &ccDeployment)
if err != nil {
return err
}
d.GUID = ccDeployment.GUID
d.CreatedAt = ccDeployment.CreatedAt
d.Relationships = ccDeployment.Relationships
d.State = ccDeployment.State
d.DropletGUID = ccDeployment.Droplet.GUID
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | integration/helpers/environment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/integration/helpers/environment.go#L32-L65 | go | train | // CheckEnvironmentTargetedCorrectly will confirm if the command requires an
// API to be targeted and logged in to run. It can optionally check if the
// command requires org and space to be targeted. | func CheckEnvironmentTargetedCorrectly(targetedOrganizationRequired bool, targetedSpaceRequired bool, testOrg string, command ...string) | // CheckEnvironmentTargetedCorrectly will confirm if the command requires an
// API to be targeted and logged in to run. It can optionally check if the
// command requires org and space to be targeted.
func CheckEnvironmentTargetedCorrectly(targetedOrganizationRequired bool, targetedSpaceRequired bool, testOrg string, command ...string) | {
LoginCF()
if targetedOrganizationRequired {
By("errors if org is not targeted")
session := CF(command...)
Eventually(session).Should(Say("FAILED"))
Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
Eventually(session).Should(Exit(1))
if targetedSpaceRequired {
By("errors if space is not targeted")
TargetOrg(testOrg)
session := CF(command...)
Eventually(session).Should(Say("FAILED"))
Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
Eventually(session).Should(Exit(1))
}
}
By("errors if user not logged in")
LogoutCF()
session := CF(command...)
Eventually(session).Should(Say("FAILED"))
Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
Eventually(session).Should(Exit(1))
By("errors if cli not targeted")
UnsetAPI()
session = CF(command...)
Eventually(session).Should(Say("FAILED"))
Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
Eventually(session).Should(Exit(1))
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/pushaction/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/pushaction/route.go#L194-L211 | go | train | // GenerateRandomRoute generates a random route with a specified or default domain
// If the domain is HTTP, a random hostname is generated
// If the domain is TCP, an empty port is used (to signify a random port should be generated) | func (actor Actor) GenerateRandomRoute(manifestApp manifest.Application, spaceGUID string, orgGUID string) (v2action.Route, Warnings, error) | // GenerateRandomRoute generates a random route with a specified or default domain
// If the domain is HTTP, a random hostname is generated
// If the domain is TCP, an empty port is used (to signify a random port should be generated)
func (actor Actor) GenerateRandomRoute(manifestApp manifest.Application, spaceGUID string, orgGUID string) (v2action.Route, Warnings, error) | {
domain, warnings, err := actor.calculateDomain(manifestApp, orgGUID)
if err != nil {
return v2action.Route{}, warnings, err
}
var hostname string
if domain.IsHTTP() {
hostname = fmt.Sprintf("%s-%s-%s", actor.sanitize(manifestApp.Name), actor.WordGenerator.RandomAdjective(), actor.WordGenerator.RandomNoun())
hostname = strings.Trim(hostname, "-")
}
return v2action.Route{
Host: hostname,
Domain: domain,
SpaceGUID: spaceGUID,
}, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | actor/pushaction/route.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/pushaction/route.go#L215-L253 | go | train | // GetGeneratedRoute returns a route with the host and the default org domain.
// This may be a partial route (ie no GUID) if the route does not exist. | func (actor Actor) GetGeneratedRoute(manifestApp manifest.Application, orgGUID string, spaceGUID string, knownRoutes []v2action.Route) (v2action.Route, Warnings, error) | // GetGeneratedRoute returns a route with the host and the default org domain.
// This may be a partial route (ie no GUID) if the route does not exist.
func (actor Actor) GetGeneratedRoute(manifestApp manifest.Application, orgGUID string, spaceGUID string, knownRoutes []v2action.Route) (v2action.Route, Warnings, error) | {
desiredDomain, warnings, err := actor.calculateDomain(manifestApp, orgGUID)
if err != nil {
return v2action.Route{}, warnings, err
}
desiredHostname, err := actor.calculateHostname(manifestApp, desiredDomain)
if err != nil {
return v2action.Route{}, warnings, err
}
desiredPath, err := actor.calculatePath(manifestApp, desiredDomain)
if err != nil {
return v2action.Route{}, warnings, err
}
defaultRoute := v2action.Route{
Domain: desiredDomain,
Host: desiredHostname,
SpaceGUID: spaceGUID,
Path: desiredPath,
}
// when the default desired domain is a TCP domain, always return a
// new/random route
if desiredDomain.IsTCP() {
return defaultRoute, warnings, nil
}
cachedRoute, found := actor.routeInListBySettings(defaultRoute, knownRoutes)
if !found {
route, routeWarnings, err := actor.V2Actor.FindRouteBoundToSpaceWithSettings(defaultRoute)
if _, ok := err.(actionerror.RouteNotFoundError); ok {
return defaultRoute, append(warnings, routeWarnings...), nil
}
return route, append(warnings, routeWarnings...), err
}
return cachedRoute, warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/manifest/manifest.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/manifest/manifest.go#L37-L56 | go | train | // ReadAndInterpolateManifest reads the manifest at the provided paths,
// interpolates variables if a vars file is provided, and returns a fully
// merged set of applications. | func ReadAndInterpolateManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]Application, error) | // ReadAndInterpolateManifest reads the manifest at the provided paths,
// interpolates variables if a vars file is provided, and returns a fully
// merged set of applications.
func ReadAndInterpolateManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]Application, error) | {
rawManifest, err := ReadAndInterpolateRawManifest(pathToManifest, pathsToVarsFiles, vars)
if err != nil {
return nil, err
}
var manifest Manifest
err = yaml.Unmarshal(rawManifest, &manifest)
if err != nil {
return nil, err
}
for i, app := range manifest.Applications {
if app.Path != "" && !filepath.IsAbs(app.Path) {
manifest.Applications[i].Path = filepath.Join(filepath.Dir(pathToManifest), app.Path)
}
}
return manifest.Applications, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/manifest/manifest.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/manifest/manifest.go#L61-L97 | go | train | // ReadAndInterpolateRawManifest reads the manifest at the provided paths,
// interpolates variables if a vars file is provided, and returns the
// Unmarshalled result. | func ReadAndInterpolateRawManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]byte, error) | // ReadAndInterpolateRawManifest reads the manifest at the provided paths,
// interpolates variables if a vars file is provided, and returns the
// Unmarshalled result.
func ReadAndInterpolateRawManifest(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV) ([]byte, error) | {
rawManifest, err := ioutil.ReadFile(pathToManifest)
if err != nil {
return nil, err
}
tpl := template.NewTemplate(rawManifest)
fileVars := template.StaticVariables{}
for _, path := range pathsToVarsFiles {
rawVarsFile, ioerr := ioutil.ReadFile(path)
if ioerr != nil {
return nil, ioerr
}
var sv template.StaticVariables
err = yaml.Unmarshal(rawVarsFile, &sv)
if err != nil {
return nil, InvalidYAMLError{Err: err}
}
for k, v := range sv {
fileVars[k] = v
}
}
for _, kv := range vars {
fileVars[kv.Name] = kv.Value
}
rawManifest, err = tpl.Evaluate(fileVars, nil, template.EvaluateOpts{ExpectAllKeys: true})
if err != nil {
return nil, InterpolationError{Err: err}
}
return rawManifest, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | util/manifest/manifest.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/manifest/manifest.go#L101-L114 | go | train | // WriteApplicationManifest writes the provided application to the given
// filepath. If the filepath does not exist, it will create it. | func WriteApplicationManifest(application Application, filePath string) error | // WriteApplicationManifest writes the provided application to the given
// filepath. If the filepath does not exist, it will create it.
func WriteApplicationManifest(application Application, filePath string) error | {
manifest := Manifest{Applications: []Application{application}}
manifestBytes, err := yaml.Marshal(manifest)
if err != nil {
return ManifestCreationError{Err: err}
}
err = ioutil.WriteFile(filePath, manifestBytes, 0644)
if err != nil {
return ManifestCreationError{Err: err}
}
return nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv2/target.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/target.go#L33-L59 | go | train | // TargetCF sets the client to use the Cloud Controller specified in the
// configuration. Any other configuration is also applied to the client. | func (client *Client) TargetCF(settings TargetSettings) (Warnings, error) | // TargetCF sets the client to use the Cloud Controller specified in the
// configuration. Any other configuration is also applied to the client.
func (client *Client) TargetCF(settings TargetSettings) (Warnings, error) | {
client.cloudControllerURL = settings.URL
client.router = rata.NewRequestGenerator(settings.URL, internal.APIRoutes)
client.connection = cloudcontroller.NewConnection(cloudcontroller.Config{
DialTimeout: settings.DialTimeout,
SkipSSLValidation: settings.SkipSSLValidation,
})
for _, wrapper := range client.wrappers {
client.connection = wrapper.Wrap(client.connection)
}
info, warnings, err := client.Info()
if err != nil {
return warnings, err
}
client.authorizationEndpoint = info.AuthorizationEndpoint
client.cloudControllerAPIVersion = info.APIVersion
client.dopplerEndpoint = info.DopplerEndpoint
client.minCLIVersion = info.MinCLIVersion
client.routingEndpoint = info.RoutingEndpoint
client.tokenEndpoint = info.TokenEndpoint
return warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/wrapper/retry_request.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/retry_request.go#L55-L58 | go | train | // Wrap sets the connection in the RetryRequest and returns itself. | func (retry *RetryRequest) Wrap(innerconnection uaa.Connection) uaa.Connection | // Wrap sets the connection in the RetryRequest and returns itself.
func (retry *RetryRequest) Wrap(innerconnection uaa.Connection) uaa.Connection | {
retry.connection = innerconnection
return retry
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/uaa/wrapper/retry_request.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/retry_request.go#L62-L69 | go | train | // skipRetry will skip retry if the request method is POST or contains a status
// code that is not one of following http status codes: 500, 502, 503, 504. | func (*RetryRequest) skipRetry(httpMethod string, response *http.Response) bool | // skipRetry will skip retry if the request method is POST or contains a status
// code that is not one of following http status codes: 500, 502, 503, 504.
func (*RetryRequest) skipRetry(httpMethod string, response *http.Response) bool | {
return httpMethod == http.MethodPost ||
response != nil &&
response.StatusCode != http.StatusInternalServerError &&
response.StatusCode != http.StatusBadGateway &&
response.StatusCode != http.StatusServiceUnavailable &&
response.StatusCode != http.StatusGatewayTimeout
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/isolation_segment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/isolation_segment.go#L23-L44 | go | train | // CreateIsolationSegment will create an Isolation Segment on the Cloud
// Controller. Note: This will not validate that the placement tag exists in
// the diego cluster. | func (client *Client) CreateIsolationSegment(isolationSegment IsolationSegment) (IsolationSegment, Warnings, error) | // CreateIsolationSegment will create an Isolation Segment on the Cloud
// Controller. Note: This will not validate that the placement tag exists in
// the diego cluster.
func (client *Client) CreateIsolationSegment(isolationSegment IsolationSegment) (IsolationSegment, Warnings, error) | {
body, err := json.Marshal(isolationSegment)
if err != nil {
return IsolationSegment{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostIsolationSegmentsRequest,
Body: bytes.NewReader(body),
})
if err != nil {
return IsolationSegment{}, nil, err
}
var responseIsolationSegment IsolationSegment
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseIsolationSegment,
}
err = client.connection.Make(request, &response)
return responseIsolationSegment, response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/isolation_segment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/isolation_segment.go#L49-L61 | go | train | // DeleteIsolationSegment removes an isolation segment from the cloud
// controller. Note: This will only remove it from the cloud controller
// database. It will not remove it from diego. | func (client *Client) DeleteIsolationSegment(guid string) (Warnings, error) | // DeleteIsolationSegment removes an isolation segment from the cloud
// controller. Note: This will only remove it from the cloud controller
// database. It will not remove it from diego.
func (client *Client) DeleteIsolationSegment(guid string) (Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.DeleteIsolationSegmentRequest,
URIParams: map[string]string{"isolation_segment_guid": guid},
})
if err != nil {
return nil, err
}
var response cloudcontroller.Response
err = client.connection.Make(request, &response)
return response.Warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/isolation_segment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/isolation_segment.go#L65-L84 | go | train | // GetIsolationSegment returns back the requested isolation segment that
// matches the GUID. | func (client *Client) GetIsolationSegment(guid string) (IsolationSegment, Warnings, error) | // GetIsolationSegment returns back the requested isolation segment that
// matches the GUID.
func (client *Client) GetIsolationSegment(guid string) (IsolationSegment, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentRequest,
URIParams: map[string]string{"isolation_segment_guid": guid},
})
if err != nil {
return IsolationSegment{}, nil, err
}
var isolationSegment IsolationSegment
response := cloudcontroller.Response{
DecodeJSONResponseInto: &isolationSegment,
}
err = client.connection.Make(request, &response)
if err != nil {
return IsolationSegment{}, response.Warnings, err
}
return isolationSegment, response.Warnings, nil
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/ccv3/isolation_segment.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/isolation_segment.go#L87-L110 | go | train | // GetIsolationSegments lists isolation segments with optional filters. | func (client *Client) GetIsolationSegments(query ...Query) ([]IsolationSegment, Warnings, error) | // GetIsolationSegments lists isolation segments with optional filters.
func (client *Client) GetIsolationSegments(query ...Query) ([]IsolationSegment, Warnings, error) | {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullIsolationSegmentsList []IsolationSegment
warnings, err := client.paginate(request, IsolationSegment{}, func(item interface{}) error {
if isolationSegment, ok := item.(IsolationSegment); ok {
fullIsolationSegmentsList = append(fullIsolationSegmentsList, isolationSegment)
} else {
return ccerror.UnknownObjectInListError{
Expected: IsolationSegment{},
Unexpected: item,
}
}
return nil
})
return fullIsolationSegmentsList, warnings, err
} |
cloudfoundry/cli | 5010c000047f246b870475e2c299556078cdad30 | api/cloudcontroller/buildpacks/upload.go | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/buildpacks/upload.go#L14-L31 | go | train | // tested via the ccv2.buildpack_test.go file at this point | func CalculateRequestSize(buildpackSize int64, bpPath string, fieldName string) (int64, error) | // tested via the ccv2.buildpack_test.go file at this point
func CalculateRequestSize(buildpackSize int64, bpPath string, fieldName string) (int64, error) | {
body := &bytes.Buffer{}
form := multipart.NewWriter(body)
bpFileName := filepath.Base(bpPath)
_, err := form.CreateFormFile(fieldName, bpFileName)
if err != nil {
return 0, err
}
err = form.Close()
if err != nil {
return 0, err
}
return int64(body.Len()) + buildpackSize, nil
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.