repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
cloudfoundry/cli | api/cloudcontroller/ccv2/service_plan.go | GetServicePlan | func (client *Client) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanRequest,
URIParams: Params{"service_plan_guid": servicePlanGUID},
})
if err != nil {
return ServicePlan{}, nil, err
}
var servicePlan ServicePlan
response := cloudcontroller.Response{
DecodeJSONResponseInto: &servicePlan,
}
err = client.connection.Make(request, &response)
return servicePlan, response.Warnings, err
} | go | func (client *Client) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanRequest,
URIParams: Params{"service_plan_guid": servicePlanGUID},
})
if err != nil {
return ServicePlan{}, nil, err
}
var servicePlan ServicePlan
response := cloudcontroller.Response{
DecodeJSONResponseInto: &servicePlan,
}
err = client.connection.Make(request, &response)
return servicePlan, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServicePlan",
"(",
"servicePlanGUID",
"string",
")",
"(",
"ServicePlan",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServicePlanRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"service_plan_guid\"",
":",
"servicePlanGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ServicePlan",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"servicePlan",
"ServicePlan",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"servicePlan",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"servicePlan",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetServicePlan returns the service plan with the given GUID. | [
"GetServicePlan",
"returns",
"the",
"service",
"plan",
"with",
"the",
"given",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_plan.go#L62-L78 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | CreateIsolationSegmentByName | func (actor Actor) CreateIsolationSegmentByName(isolationSegment IsolationSegment) (Warnings, error) {
_, warnings, err := actor.CloudControllerClient.CreateIsolationSegment(ccv3.IsolationSegment(isolationSegment))
if _, ok := err.(ccerror.UnprocessableEntityError); ok {
return Warnings(warnings), actionerror.IsolationSegmentAlreadyExistsError{Name: isolationSegment.Name}
}
return Warnings(warnings), err
} | go | func (actor Actor) CreateIsolationSegmentByName(isolationSegment IsolationSegment) (Warnings, error) {
_, warnings, err := actor.CloudControllerClient.CreateIsolationSegment(ccv3.IsolationSegment(isolationSegment))
if _, ok := err.(ccerror.UnprocessableEntityError); ok {
return Warnings(warnings), actionerror.IsolationSegmentAlreadyExistsError{Name: isolationSegment.Name}
}
return Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"CreateIsolationSegmentByName",
"(",
"isolationSegment",
"IsolationSegment",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"_",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateIsolationSegment",
"(",
"ccv3",
".",
"IsolationSegment",
"(",
"isolationSegment",
")",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"UnprocessableEntityError",
")",
";",
"ok",
"{",
"return",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"IsolationSegmentAlreadyExistsError",
"{",
"Name",
":",
"isolationSegment",
".",
"Name",
"}",
"\n",
"}",
"\n",
"return",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // CreateIsolationSegmentByName creates a given isolation segment. | [
"CreateIsolationSegmentByName",
"creates",
"a",
"given",
"isolation",
"segment",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L53-L59 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | DeleteIsolationSegmentByName | func (actor Actor) DeleteIsolationSegmentByName(name string) (Warnings, error) {
isolationSegment, warnings, err := actor.GetIsolationSegmentByName(name)
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return allWarnings, err
}
apiWarnings, err := actor.CloudControllerClient.DeleteIsolationSegment(isolationSegment.GUID)
return append(allWarnings, apiWarnings...), err
} | go | func (actor Actor) DeleteIsolationSegmentByName(name string) (Warnings, error) {
isolationSegment, warnings, err := actor.GetIsolationSegmentByName(name)
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return allWarnings, err
}
apiWarnings, err := actor.CloudControllerClient.DeleteIsolationSegment(isolationSegment.GUID)
return append(allWarnings, apiWarnings...), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"DeleteIsolationSegmentByName",
"(",
"name",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"isolationSegment",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetIsolationSegmentByName",
"(",
"name",
")",
"\n",
"allWarnings",
":=",
"append",
"(",
"Warnings",
"{",
"}",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"DeleteIsolationSegment",
"(",
"isolationSegment",
".",
"GUID",
")",
"\n",
"return",
"append",
"(",
"allWarnings",
",",
"apiWarnings",
"...",
")",
",",
"err",
"\n",
"}"
] | // DeleteIsolationSegmentByName deletes the given isolation segment. | [
"DeleteIsolationSegmentByName",
"deletes",
"the",
"given",
"isolation",
"segment",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L62-L71 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | EntitleIsolationSegmentToOrganizationByName | func (actor Actor) EntitleIsolationSegmentToOrganizationByName(isolationSegmentName string, orgName string) (Warnings, error) {
isolationSegment, warnings, err := actor.GetIsolationSegmentByName(isolationSegmentName)
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return allWarnings, err
}
organization, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
_, apiWarnings, err := actor.CloudControllerClient.EntitleIsolationSegmentToOrganizations(isolationSegment.GUID, []string{organization.GUID})
return append(allWarnings, apiWarnings...), err
} | go | func (actor Actor) EntitleIsolationSegmentToOrganizationByName(isolationSegmentName string, orgName string) (Warnings, error) {
isolationSegment, warnings, err := actor.GetIsolationSegmentByName(isolationSegmentName)
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return allWarnings, err
}
organization, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
_, apiWarnings, err := actor.CloudControllerClient.EntitleIsolationSegmentToOrganizations(isolationSegment.GUID, []string{organization.GUID})
return append(allWarnings, apiWarnings...), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"EntitleIsolationSegmentToOrganizationByName",
"(",
"isolationSegmentName",
"string",
",",
"orgName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"isolationSegment",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetIsolationSegmentByName",
"(",
"isolationSegmentName",
")",
"\n",
"allWarnings",
":=",
"append",
"(",
"Warnings",
"{",
"}",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"organization",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"EntitleIsolationSegmentToOrganizations",
"(",
"isolationSegment",
".",
"GUID",
",",
"[",
"]",
"string",
"{",
"organization",
".",
"GUID",
"}",
")",
"\n",
"return",
"append",
"(",
"allWarnings",
",",
"apiWarnings",
"...",
")",
",",
"err",
"\n",
"}"
] | // EntitleIsolationSegmentToOrganizationByName entitles the given organization
// to use the specified isolation segment | [
"EntitleIsolationSegmentToOrganizationByName",
"entitles",
"the",
"given",
"organization",
"to",
"use",
"the",
"specified",
"isolation",
"segment"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L75-L90 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | GetIsolationSegmentByName | func (actor Actor) GetIsolationSegmentByName(name string) (IsolationSegment, Warnings, error) {
isolationSegments, warnings, err := actor.CloudControllerClient.GetIsolationSegments(
ccv3.Query{Key: ccv3.NameFilter, Values: []string{name}},
)
if err != nil {
return IsolationSegment{}, Warnings(warnings), err
}
if len(isolationSegments) == 0 {
return IsolationSegment{}, Warnings(warnings), actionerror.IsolationSegmentNotFoundError{Name: name}
}
return IsolationSegment(isolationSegments[0]), Warnings(warnings), nil
} | go | func (actor Actor) GetIsolationSegmentByName(name string) (IsolationSegment, Warnings, error) {
isolationSegments, warnings, err := actor.CloudControllerClient.GetIsolationSegments(
ccv3.Query{Key: ccv3.NameFilter, Values: []string{name}},
)
if err != nil {
return IsolationSegment{}, Warnings(warnings), err
}
if len(isolationSegments) == 0 {
return IsolationSegment{}, Warnings(warnings), actionerror.IsolationSegmentNotFoundError{Name: name}
}
return IsolationSegment(isolationSegments[0]), Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetIsolationSegmentByName",
"(",
"name",
"string",
")",
"(",
"IsolationSegment",
",",
"Warnings",
",",
"error",
")",
"{",
"isolationSegments",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetIsolationSegments",
"(",
"ccv3",
".",
"Query",
"{",
"Key",
":",
"ccv3",
".",
"NameFilter",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"name",
"}",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"IsolationSegment",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"isolationSegments",
")",
"==",
"0",
"{",
"return",
"IsolationSegment",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"IsolationSegmentNotFoundError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}",
"\n",
"return",
"IsolationSegment",
"(",
"isolationSegments",
"[",
"0",
"]",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // GetIsolationSegmentByName returns the requested isolation segment. | [
"GetIsolationSegmentByName",
"returns",
"the",
"requested",
"isolation",
"segment",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L103-L116 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | GetIsolationSegmentSummaries | func (actor Actor) GetIsolationSegmentSummaries() ([]IsolationSegmentSummary, Warnings, error) {
isolationSegments, warnings, err := actor.CloudControllerClient.GetIsolationSegments()
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return nil, allWarnings, err
}
var isolationSegmentSummaries []IsolationSegmentSummary
for _, isolationSegment := range isolationSegments {
isolationSegmentSummary := IsolationSegmentSummary{
Name: isolationSegment.Name,
EntitledOrgs: []string{},
}
orgs, warnings, err := actor.CloudControllerClient.GetIsolationSegmentOrganizations(isolationSegment.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return nil, allWarnings, err
}
for _, org := range orgs {
isolationSegmentSummary.EntitledOrgs = append(isolationSegmentSummary.EntitledOrgs, org.Name)
}
isolationSegmentSummaries = append(isolationSegmentSummaries, isolationSegmentSummary)
}
return isolationSegmentSummaries, allWarnings, nil
} | go | func (actor Actor) GetIsolationSegmentSummaries() ([]IsolationSegmentSummary, Warnings, error) {
isolationSegments, warnings, err := actor.CloudControllerClient.GetIsolationSegments()
allWarnings := append(Warnings{}, warnings...)
if err != nil {
return nil, allWarnings, err
}
var isolationSegmentSummaries []IsolationSegmentSummary
for _, isolationSegment := range isolationSegments {
isolationSegmentSummary := IsolationSegmentSummary{
Name: isolationSegment.Name,
EntitledOrgs: []string{},
}
orgs, warnings, err := actor.CloudControllerClient.GetIsolationSegmentOrganizations(isolationSegment.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return nil, allWarnings, err
}
for _, org := range orgs {
isolationSegmentSummary.EntitledOrgs = append(isolationSegmentSummary.EntitledOrgs, org.Name)
}
isolationSegmentSummaries = append(isolationSegmentSummaries, isolationSegmentSummary)
}
return isolationSegmentSummaries, allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetIsolationSegmentSummaries",
"(",
")",
"(",
"[",
"]",
"IsolationSegmentSummary",
",",
"Warnings",
",",
"error",
")",
"{",
"isolationSegments",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetIsolationSegments",
"(",
")",
"\n",
"allWarnings",
":=",
"append",
"(",
"Warnings",
"{",
"}",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"var",
"isolationSegmentSummaries",
"[",
"]",
"IsolationSegmentSummary",
"\n",
"for",
"_",
",",
"isolationSegment",
":=",
"range",
"isolationSegments",
"{",
"isolationSegmentSummary",
":=",
"IsolationSegmentSummary",
"{",
"Name",
":",
"isolationSegment",
".",
"Name",
",",
"EntitledOrgs",
":",
"[",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetIsolationSegmentOrganizations",
"(",
"isolationSegment",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"isolationSegmentSummary",
".",
"EntitledOrgs",
"=",
"append",
"(",
"isolationSegmentSummary",
".",
"EntitledOrgs",
",",
"org",
".",
"Name",
")",
"\n",
"}",
"\n",
"isolationSegmentSummaries",
"=",
"append",
"(",
"isolationSegmentSummaries",
",",
"isolationSegmentSummary",
")",
"\n",
"}",
"\n",
"return",
"isolationSegmentSummaries",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // GetIsolationSegmentSummaries returns all isolation segments and their entitled orgs | [
"GetIsolationSegmentSummaries",
"returns",
"all",
"isolation",
"segments",
"and",
"their",
"entitled",
"orgs"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L119-L147 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | SetOrganizationDefaultIsolationSegment | func (actor Actor) SetOrganizationDefaultIsolationSegment(orgGUID string, isoSegGUID string) (Warnings, error) {
_, apiWarnings, err := actor.CloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationship(orgGUID, isoSegGUID)
return Warnings(apiWarnings), err
} | go | func (actor Actor) SetOrganizationDefaultIsolationSegment(orgGUID string, isoSegGUID string) (Warnings, error) {
_, apiWarnings, err := actor.CloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationship(orgGUID, isoSegGUID)
return Warnings(apiWarnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"SetOrganizationDefaultIsolationSegment",
"(",
"orgGUID",
"string",
",",
"isoSegGUID",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"_",
",",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationDefaultIsolationSegmentRelationship",
"(",
"orgGUID",
",",
"isoSegGUID",
")",
"\n",
"return",
"Warnings",
"(",
"apiWarnings",
")",
",",
"err",
"\n",
"}"
] | // SetOrganizationDefaultIsolationSegment sets a default isolation segment on
// an organization. | [
"SetOrganizationDefaultIsolationSegment",
"sets",
"a",
"default",
"isolation",
"segment",
"on",
"an",
"organization",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L188-L191 | train |
cloudfoundry/cli | actor/v3action/isolation_segment.go | ResetOrganizationDefaultIsolationSegment | func (actor Actor) ResetOrganizationDefaultIsolationSegment(orgGUID string) (Warnings, error) {
_, apiWarnings, err := actor.CloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationship(orgGUID, "")
return Warnings(apiWarnings), err
} | go | func (actor Actor) ResetOrganizationDefaultIsolationSegment(orgGUID string) (Warnings, error) {
_, apiWarnings, err := actor.CloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationship(orgGUID, "")
return Warnings(apiWarnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"ResetOrganizationDefaultIsolationSegment",
"(",
"orgGUID",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"_",
",",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationDefaultIsolationSegmentRelationship",
"(",
"orgGUID",
",",
"\"\"",
")",
"\n",
"return",
"Warnings",
"(",
"apiWarnings",
")",
",",
"err",
"\n",
"}"
] | // ResetOrganizationDefaultIsolationSegment resets the default isolation segment fon
// an organization. | [
"ResetOrganizationDefaultIsolationSegment",
"resets",
"the",
"default",
"isolation",
"segment",
"fon",
"an",
"organization",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/isolation_segment.go#L195-L198 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/package.go | UnmarshalJSON | func (p *Package) UnmarshalJSON(data []byte) error {
var ccPackage struct {
GUID string `json:"guid,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Links APILinks `json:"links,omitempty"`
Relationships Relationships `json:"relationships,omitempty"`
State constant.PackageState `json:"state,omitempty"`
Type constant.PackageType `json:"type,omitempty"`
Data struct {
Image string `json:"image"`
Username string `json:"username"`
Password string `json:"password"`
} `json:"data"`
}
err := cloudcontroller.DecodeJSON(data, &ccPackage)
if err != nil {
return err
}
p.GUID = ccPackage.GUID
p.CreatedAt = ccPackage.CreatedAt
p.Links = ccPackage.Links
p.Relationships = ccPackage.Relationships
p.State = ccPackage.State
p.Type = ccPackage.Type
p.DockerImage = ccPackage.Data.Image
p.DockerUsername = ccPackage.Data.Username
p.DockerPassword = ccPackage.Data.Password
return nil
} | go | func (p *Package) UnmarshalJSON(data []byte) error {
var ccPackage struct {
GUID string `json:"guid,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Links APILinks `json:"links,omitempty"`
Relationships Relationships `json:"relationships,omitempty"`
State constant.PackageState `json:"state,omitempty"`
Type constant.PackageType `json:"type,omitempty"`
Data struct {
Image string `json:"image"`
Username string `json:"username"`
Password string `json:"password"`
} `json:"data"`
}
err := cloudcontroller.DecodeJSON(data, &ccPackage)
if err != nil {
return err
}
p.GUID = ccPackage.GUID
p.CreatedAt = ccPackage.CreatedAt
p.Links = ccPackage.Links
p.Relationships = ccPackage.Relationships
p.State = ccPackage.State
p.Type = ccPackage.Type
p.DockerImage = ccPackage.Data.Image
p.DockerUsername = ccPackage.Data.Username
p.DockerPassword = ccPackage.Data.Password
return nil
} | [
"func",
"(",
"p",
"*",
"Package",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccPackage",
"struct",
"{",
"GUID",
"string",
"`json:\"guid,omitempty\"`",
"\n",
"CreatedAt",
"string",
"`json:\"created_at,omitempty\"`",
"\n",
"Links",
"APILinks",
"`json:\"links,omitempty\"`",
"\n",
"Relationships",
"Relationships",
"`json:\"relationships,omitempty\"`",
"\n",
"State",
"constant",
".",
"PackageState",
"`json:\"state,omitempty\"`",
"\n",
"Type",
"constant",
".",
"PackageType",
"`json:\"type,omitempty\"`",
"\n",
"Data",
"struct",
"{",
"Image",
"string",
"`json:\"image\"`",
"\n",
"Username",
"string",
"`json:\"username\"`",
"\n",
"Password",
"string",
"`json:\"password\"`",
"\n",
"}",
"`json:\"data\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccPackage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"p",
".",
"GUID",
"=",
"ccPackage",
".",
"GUID",
"\n",
"p",
".",
"CreatedAt",
"=",
"ccPackage",
".",
"CreatedAt",
"\n",
"p",
".",
"Links",
"=",
"ccPackage",
".",
"Links",
"\n",
"p",
".",
"Relationships",
"=",
"ccPackage",
".",
"Relationships",
"\n",
"p",
".",
"State",
"=",
"ccPackage",
".",
"State",
"\n",
"p",
".",
"Type",
"=",
"ccPackage",
".",
"Type",
"\n",
"p",
".",
"DockerImage",
"=",
"ccPackage",
".",
"Data",
".",
"Image",
"\n",
"p",
".",
"DockerUsername",
"=",
"ccPackage",
".",
"Data",
".",
"Username",
"\n",
"p",
".",
"DockerPassword",
"=",
"ccPackage",
".",
"Data",
".",
"Password",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Package response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Package",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/package.go#L84-L114 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/package.go | CreatePackage | func (client *Client) CreatePackage(pkg Package) (Package, Warnings, error) {
bodyBytes, err := json.Marshal(pkg)
if err != nil {
return Package{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostPackageRequest,
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return Package{}, nil, err
}
var responsePackage Package
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responsePackage,
}
err = client.connection.Make(request, &response)
return responsePackage, response.Warnings, err
} | go | func (client *Client) CreatePackage(pkg Package) (Package, Warnings, error) {
bodyBytes, err := json.Marshal(pkg)
if err != nil {
return Package{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostPackageRequest,
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return Package{}, nil, err
}
var responsePackage Package
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responsePackage,
}
err = client.connection.Make(request, &response)
return responsePackage, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"CreatePackage",
"(",
"pkg",
"Package",
")",
"(",
"Package",
",",
"Warnings",
",",
"error",
")",
"{",
"bodyBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"pkg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Package",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PostPackageRequest",
",",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"bodyBytes",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Package",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"responsePackage",
"Package",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responsePackage",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"responsePackage",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // CreatePackage creates a package with the given settings, Type and the
// ApplicationRelationship must be set. | [
"CreatePackage",
"creates",
"a",
"package",
"with",
"the",
"given",
"settings",
"Type",
"and",
"the",
"ApplicationRelationship",
"must",
"be",
"set",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/package.go#L118-L139 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/package.go | GetPackage | func (client *Client) GetPackage(packageGUID string) (Package, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetPackageRequest,
URIParams: internal.Params{"package_guid": packageGUID},
})
if err != nil {
return Package{}, nil, err
}
var responsePackage Package
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responsePackage,
}
err = client.connection.Make(request, &response)
return responsePackage, response.Warnings, err
} | go | func (client *Client) GetPackage(packageGUID string) (Package, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetPackageRequest,
URIParams: internal.Params{"package_guid": packageGUID},
})
if err != nil {
return Package{}, nil, err
}
var responsePackage Package
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responsePackage,
}
err = client.connection.Make(request, &response)
return responsePackage, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetPackage",
"(",
"packageGUID",
"string",
")",
"(",
"Package",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetPackageRequest",
",",
"URIParams",
":",
"internal",
".",
"Params",
"{",
"\"package_guid\"",
":",
"packageGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Package",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"responsePackage",
"Package",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responsePackage",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"responsePackage",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetPackage returns the package with the given GUID. | [
"GetPackage",
"returns",
"the",
"package",
"with",
"the",
"given",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/package.go#L142-L158 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/package.go | GetPackages | func (client *Client) GetPackages(query ...Query) ([]Package, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetPackagesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullPackagesList []Package
warnings, err := client.paginate(request, Package{}, func(item interface{}) error {
if pkg, ok := item.(Package); ok {
fullPackagesList = append(fullPackagesList, pkg)
} else {
return ccerror.UnknownObjectInListError{
Expected: Package{},
Unexpected: item,
}
}
return nil
})
return fullPackagesList, warnings, err
} | go | func (client *Client) GetPackages(query ...Query) ([]Package, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetPackagesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullPackagesList []Package
warnings, err := client.paginate(request, Package{}, func(item interface{}) error {
if pkg, ok := item.(Package); ok {
fullPackagesList = append(fullPackagesList, pkg)
} else {
return ccerror.UnknownObjectInListError{
Expected: Package{},
Unexpected: item,
}
}
return nil
})
return fullPackagesList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetPackages",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"Package",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetPackagesRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullPackagesList",
"[",
"]",
"Package",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Package",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"pkg",
",",
"ok",
":=",
"item",
".",
"(",
"Package",
")",
";",
"ok",
"{",
"fullPackagesList",
"=",
"append",
"(",
"fullPackagesList",
",",
"pkg",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Package",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullPackagesList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetPackages returns the list of packages. | [
"GetPackages",
"returns",
"the",
"list",
"of",
"packages",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/package.go#L161-L184 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_broker.go | UnmarshalJSON | func (serviceBroker *ServiceBroker) UnmarshalJSON(data []byte) error {
var ccServiceBroker struct {
Metadata internal.Metadata
Entity struct {
Name string `json:"name"`
BrokerURL string `json:"broker_url"`
AuthUsername string `json:"auth_username"`
SpaceGUID string `json:"space_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServiceBroker)
if err != nil {
return err
}
serviceBroker.Name = ccServiceBroker.Entity.Name
serviceBroker.GUID = ccServiceBroker.Metadata.GUID
serviceBroker.BrokerURL = ccServiceBroker.Entity.BrokerURL
serviceBroker.AuthUsername = ccServiceBroker.Entity.AuthUsername
serviceBroker.SpaceGUID = ccServiceBroker.Entity.SpaceGUID
return nil
} | go | func (serviceBroker *ServiceBroker) UnmarshalJSON(data []byte) error {
var ccServiceBroker struct {
Metadata internal.Metadata
Entity struct {
Name string `json:"name"`
BrokerURL string `json:"broker_url"`
AuthUsername string `json:"auth_username"`
SpaceGUID string `json:"space_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServiceBroker)
if err != nil {
return err
}
serviceBroker.Name = ccServiceBroker.Entity.Name
serviceBroker.GUID = ccServiceBroker.Metadata.GUID
serviceBroker.BrokerURL = ccServiceBroker.Entity.BrokerURL
serviceBroker.AuthUsername = ccServiceBroker.Entity.AuthUsername
serviceBroker.SpaceGUID = ccServiceBroker.Entity.SpaceGUID
return nil
} | [
"func",
"(",
"serviceBroker",
"*",
"ServiceBroker",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccServiceBroker",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"\n",
"Entity",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"BrokerURL",
"string",
"`json:\"broker_url\"`",
"\n",
"AuthUsername",
"string",
"`json:\"auth_username\"`",
"\n",
"SpaceGUID",
"string",
"`json:\"space_guid\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccServiceBroker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"serviceBroker",
".",
"Name",
"=",
"ccServiceBroker",
".",
"Entity",
".",
"Name",
"\n",
"serviceBroker",
".",
"GUID",
"=",
"ccServiceBroker",
".",
"Metadata",
".",
"GUID",
"\n",
"serviceBroker",
".",
"BrokerURL",
"=",
"ccServiceBroker",
".",
"Entity",
".",
"BrokerURL",
"\n",
"serviceBroker",
".",
"AuthUsername",
"=",
"ccServiceBroker",
".",
"Entity",
".",
"AuthUsername",
"\n",
"serviceBroker",
".",
"SpaceGUID",
"=",
"ccServiceBroker",
".",
"Entity",
".",
"SpaceGUID",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Service Broker response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Service",
"Broker",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_broker.go#L27-L48 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_broker.go | CreateServiceBroker | func (client *Client) CreateServiceBroker(brokerName, username, password, url, spaceGUID string) (ServiceBroker, Warnings, error) {
requestBody := createServiceBrokerRequestBody{
Name: brokerName,
BrokerURL: url,
AuthUsername: username,
AuthPassword: password,
SpaceGUID: spaceGUID,
}
bodyBytes, err := json.Marshal(requestBody)
if err != nil {
return ServiceBroker{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostServiceBrokerRequest,
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return ServiceBroker{}, nil, err
}
var serviceBroker ServiceBroker
response := cloudcontroller.Response{
DecodeJSONResponseInto: &serviceBroker,
}
err = client.connection.Make(request, &response)
return serviceBroker, response.Warnings, err
} | go | func (client *Client) CreateServiceBroker(brokerName, username, password, url, spaceGUID string) (ServiceBroker, Warnings, error) {
requestBody := createServiceBrokerRequestBody{
Name: brokerName,
BrokerURL: url,
AuthUsername: username,
AuthPassword: password,
SpaceGUID: spaceGUID,
}
bodyBytes, err := json.Marshal(requestBody)
if err != nil {
return ServiceBroker{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostServiceBrokerRequest,
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return ServiceBroker{}, nil, err
}
var serviceBroker ServiceBroker
response := cloudcontroller.Response{
DecodeJSONResponseInto: &serviceBroker,
}
err = client.connection.Make(request, &response)
return serviceBroker, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"CreateServiceBroker",
"(",
"brokerName",
",",
"username",
",",
"password",
",",
"url",
",",
"spaceGUID",
"string",
")",
"(",
"ServiceBroker",
",",
"Warnings",
",",
"error",
")",
"{",
"requestBody",
":=",
"createServiceBrokerRequestBody",
"{",
"Name",
":",
"brokerName",
",",
"BrokerURL",
":",
"url",
",",
"AuthUsername",
":",
"username",
",",
"AuthPassword",
":",
"password",
",",
"SpaceGUID",
":",
"spaceGUID",
",",
"}",
"\n",
"bodyBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"requestBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ServiceBroker",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PostServiceBrokerRequest",
",",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"bodyBytes",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ServiceBroker",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"serviceBroker",
"ServiceBroker",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"serviceBroker",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"serviceBroker",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // CreateServiceBroker posts a service broker resource with the provided
// attributes to the api and returns the result. | [
"CreateServiceBroker",
"posts",
"a",
"service",
"broker",
"resource",
"with",
"the",
"provided",
"attributes",
"to",
"the",
"api",
"and",
"returns",
"the",
"result",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_broker.go#L60-L91 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_broker.go | GetServiceBrokers | func (client *Client) GetServiceBrokers(filters ...Filter) ([]ServiceBroker, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceBrokersRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullBrokersList []ServiceBroker
warnings, err := client.paginate(request, ServiceBroker{}, func(item interface{}) error {
if broker, ok := item.(ServiceBroker); ok {
fullBrokersList = append(fullBrokersList, broker)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceBroker{},
Unexpected: item,
}
}
return nil
})
return fullBrokersList, warnings, err
} | go | func (client *Client) GetServiceBrokers(filters ...Filter) ([]ServiceBroker, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceBrokersRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullBrokersList []ServiceBroker
warnings, err := client.paginate(request, ServiceBroker{}, func(item interface{}) error {
if broker, ok := item.(ServiceBroker); ok {
fullBrokersList = append(fullBrokersList, broker)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceBroker{},
Unexpected: item,
}
}
return nil
})
return fullBrokersList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServiceBrokers",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"ServiceBroker",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServiceBrokersRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullBrokersList",
"[",
"]",
"ServiceBroker",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"ServiceBroker",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"broker",
",",
"ok",
":=",
"item",
".",
"(",
"ServiceBroker",
")",
";",
"ok",
"{",
"fullBrokersList",
"=",
"append",
"(",
"fullBrokersList",
",",
"broker",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"ServiceBroker",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullBrokersList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetServiceBrokers returns back a list of Service Brokers given the provided
// filters. | [
"GetServiceBrokers",
"returns",
"back",
"a",
"list",
"of",
"Service",
"Brokers",
"given",
"the",
"provided",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_broker.go#L95-L119 | train |
cloudfoundry/cli | cf/util/glob/glob.go | MustCompileGlob | func MustCompileGlob(pat string) Glob {
g, err := CompileGlob(pat)
if err != nil {
panic(err)
}
return g
} | go | func MustCompileGlob(pat string) Glob {
g, err := CompileGlob(pat)
if err != nil {
panic(err)
}
return g
} | [
"func",
"MustCompileGlob",
"(",
"pat",
"string",
")",
"Glob",
"{",
"g",
",",
"err",
":=",
"CompileGlob",
"(",
"pat",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"g",
"\n",
"}"
] | // MustCompileGlob is like CompileGlob, but it panics if an error occurs,
// simplifying safe initialization of global variables holding glob patterns. | [
"MustCompileGlob",
"is",
"like",
"CompileGlob",
"but",
"it",
"panics",
"if",
"an",
"error",
"occurs",
"simplifying",
"safe",
"initialization",
"of",
"global",
"variables",
"holding",
"glob",
"patterns",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/cf/util/glob/glob.go#L84-L90 | train |
cloudfoundry/cli | actor/v7action/buildpack.go | GetBuildpackByNameAndStack | func (actor Actor) GetBuildpackByNameAndStack(buildpackName string, buildpackStack string) (Buildpack, Warnings, error) {
var (
ccv3Buildpacks []ccv3.Buildpack
warnings ccv3.Warnings
err error
)
if buildpackStack == "" {
ccv3Buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
})
} else {
ccv3Buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(
ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
},
ccv3.Query{
Key: ccv3.StackFilter,
Values: []string{buildpackStack},
},
)
}
if err != nil {
return Buildpack{}, Warnings(warnings), err
}
if len(ccv3Buildpacks) == 0 {
return Buildpack{}, Warnings(warnings), actionerror.BuildpackNotFoundError{BuildpackName: buildpackName, StackName: buildpackStack}
}
if len(ccv3Buildpacks) > 1 {
for _, buildpack := range ccv3Buildpacks {
if buildpack.Stack == "" {
return Buildpack(buildpack), Warnings(warnings), nil
}
}
return Buildpack{}, Warnings(warnings), actionerror.MultipleBuildpacksFoundError{BuildpackName: buildpackName}
}
return Buildpack(ccv3Buildpacks[0]), Warnings(warnings), err
} | go | func (actor Actor) GetBuildpackByNameAndStack(buildpackName string, buildpackStack string) (Buildpack, Warnings, error) {
var (
ccv3Buildpacks []ccv3.Buildpack
warnings ccv3.Warnings
err error
)
if buildpackStack == "" {
ccv3Buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
})
} else {
ccv3Buildpacks, warnings, err = actor.CloudControllerClient.GetBuildpacks(
ccv3.Query{
Key: ccv3.NameFilter,
Values: []string{buildpackName},
},
ccv3.Query{
Key: ccv3.StackFilter,
Values: []string{buildpackStack},
},
)
}
if err != nil {
return Buildpack{}, Warnings(warnings), err
}
if len(ccv3Buildpacks) == 0 {
return Buildpack{}, Warnings(warnings), actionerror.BuildpackNotFoundError{BuildpackName: buildpackName, StackName: buildpackStack}
}
if len(ccv3Buildpacks) > 1 {
for _, buildpack := range ccv3Buildpacks {
if buildpack.Stack == "" {
return Buildpack(buildpack), Warnings(warnings), nil
}
}
return Buildpack{}, Warnings(warnings), actionerror.MultipleBuildpacksFoundError{BuildpackName: buildpackName}
}
return Buildpack(ccv3Buildpacks[0]), Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetBuildpackByNameAndStack",
"(",
"buildpackName",
"string",
",",
"buildpackStack",
"string",
")",
"(",
"Buildpack",
",",
"Warnings",
",",
"error",
")",
"{",
"var",
"(",
"ccv3Buildpacks",
"[",
"]",
"ccv3",
".",
"Buildpack",
"\n",
"warnings",
"ccv3",
".",
"Warnings",
"\n",
"err",
"error",
"\n",
")",
"\n",
"if",
"buildpackStack",
"==",
"\"\"",
"{",
"ccv3Buildpacks",
",",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"GetBuildpacks",
"(",
"ccv3",
".",
"Query",
"{",
"Key",
":",
"ccv3",
".",
"NameFilter",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"buildpackName",
"}",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"ccv3Buildpacks",
",",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"GetBuildpacks",
"(",
"ccv3",
".",
"Query",
"{",
"Key",
":",
"ccv3",
".",
"NameFilter",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"buildpackName",
"}",
",",
"}",
",",
"ccv3",
".",
"Query",
"{",
"Key",
":",
"ccv3",
".",
"StackFilter",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"buildpackStack",
"}",
",",
"}",
",",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Buildpack",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ccv3Buildpacks",
")",
"==",
"0",
"{",
"return",
"Buildpack",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"BuildpackNotFoundError",
"{",
"BuildpackName",
":",
"buildpackName",
",",
"StackName",
":",
"buildpackStack",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ccv3Buildpacks",
")",
">",
"1",
"{",
"for",
"_",
",",
"buildpack",
":=",
"range",
"ccv3Buildpacks",
"{",
"if",
"buildpack",
".",
"Stack",
"==",
"\"\"",
"{",
"return",
"Buildpack",
"(",
"buildpack",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"Buildpack",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"MultipleBuildpacksFoundError",
"{",
"BuildpackName",
":",
"buildpackName",
"}",
"\n",
"}",
"\n",
"return",
"Buildpack",
"(",
"ccv3Buildpacks",
"[",
"0",
"]",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetBuildpackByNameAndStack returns a buildpack with the provided name and
// stack. If `buildpackStack` is not specified, and there are multiple
// buildpacks with the same name, it will return the one with no stack, if
// present. | [
"GetBuildpackByNameAndStack",
"returns",
"a",
"buildpack",
"with",
"the",
"provided",
"name",
"and",
"stack",
".",
"If",
"buildpackStack",
"is",
"not",
"specified",
"and",
"there",
"are",
"multiple",
"buildpacks",
"with",
"the",
"same",
"name",
"it",
"will",
"return",
"the",
"one",
"with",
"no",
"stack",
"if",
"present",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v7action/buildpack.go#L42-L85 | train |
cloudfoundry/cli | actor/v3action/droplet.go | SetApplicationDropletByApplicationNameAndSpace | func (actor Actor) SetApplicationDropletByApplicationNameAndSpace(appName string, spaceGUID string, dropletGUID string) (Warnings, error) {
allWarnings := Warnings{}
application, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
_, apiWarnings, err := actor.CloudControllerClient.SetApplicationDroplet(application.GUID, dropletGUID)
actorWarnings := Warnings(apiWarnings)
allWarnings = append(allWarnings, actorWarnings...)
if newErr, ok := err.(ccerror.UnprocessableEntityError); ok {
return allWarnings, actionerror.AssignDropletError{Message: newErr.Message}
}
return allWarnings, err
} | go | func (actor Actor) SetApplicationDropletByApplicationNameAndSpace(appName string, spaceGUID string, dropletGUID string) (Warnings, error) {
allWarnings := Warnings{}
application, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
_, apiWarnings, err := actor.CloudControllerClient.SetApplicationDroplet(application.GUID, dropletGUID)
actorWarnings := Warnings(apiWarnings)
allWarnings = append(allWarnings, actorWarnings...)
if newErr, ok := err.(ccerror.UnprocessableEntityError); ok {
return allWarnings, actionerror.AssignDropletError{Message: newErr.Message}
}
return allWarnings, err
} | [
"func",
"(",
"actor",
"Actor",
")",
"SetApplicationDropletByApplicationNameAndSpace",
"(",
"appName",
"string",
",",
"spaceGUID",
"string",
",",
"dropletGUID",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"allWarnings",
":=",
"Warnings",
"{",
"}",
"\n",
"application",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetApplicationByNameAndSpace",
"(",
"appName",
",",
"spaceGUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"SetApplicationDroplet",
"(",
"application",
".",
"GUID",
",",
"dropletGUID",
")",
"\n",
"actorWarnings",
":=",
"Warnings",
"(",
"apiWarnings",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"actorWarnings",
"...",
")",
"\n",
"if",
"newErr",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"UnprocessableEntityError",
")",
";",
"ok",
"{",
"return",
"allWarnings",
",",
"actionerror",
".",
"AssignDropletError",
"{",
"Message",
":",
"newErr",
".",
"Message",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}"
] | // SetApplicationDropletByApplicationNameAndSpace sets the droplet for an application. | [
"SetApplicationDropletByApplicationNameAndSpace",
"sets",
"the",
"droplet",
"for",
"an",
"application",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/droplet.go#L23-L39 | train |
cloudfoundry/cli | actor/v3action/droplet.go | GetApplicationDroplets | func (actor Actor) GetApplicationDroplets(appName string, spaceGUID string) ([]Droplet, Warnings, error) {
allWarnings := Warnings{}
application, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return nil, allWarnings, err
}
ccv3Droplets, apiWarnings, err := actor.CloudControllerClient.GetDroplets(
ccv3.Query{Key: ccv3.AppGUIDFilter, Values: []string{application.GUID}},
)
actorWarnings := Warnings(apiWarnings)
allWarnings = append(allWarnings, actorWarnings...)
if err != nil {
return nil, allWarnings, err
}
var droplets []Droplet
for _, ccv3Droplet := range ccv3Droplets {
droplets = append(droplets, actor.convertCCToActorDroplet(ccv3Droplet))
}
return droplets, allWarnings, err
} | go | func (actor Actor) GetApplicationDroplets(appName string, spaceGUID string) ([]Droplet, Warnings, error) {
allWarnings := Warnings{}
application, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return nil, allWarnings, err
}
ccv3Droplets, apiWarnings, err := actor.CloudControllerClient.GetDroplets(
ccv3.Query{Key: ccv3.AppGUIDFilter, Values: []string{application.GUID}},
)
actorWarnings := Warnings(apiWarnings)
allWarnings = append(allWarnings, actorWarnings...)
if err != nil {
return nil, allWarnings, err
}
var droplets []Droplet
for _, ccv3Droplet := range ccv3Droplets {
droplets = append(droplets, actor.convertCCToActorDroplet(ccv3Droplet))
}
return droplets, allWarnings, err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetApplicationDroplets",
"(",
"appName",
"string",
",",
"spaceGUID",
"string",
")",
"(",
"[",
"]",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"allWarnings",
":=",
"Warnings",
"{",
"}",
"\n",
"application",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetApplicationByNameAndSpace",
"(",
"appName",
",",
"spaceGUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"ccv3Droplets",
",",
"apiWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetDroplets",
"(",
"ccv3",
".",
"Query",
"{",
"Key",
":",
"ccv3",
".",
"AppGUIDFilter",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"application",
".",
"GUID",
"}",
"}",
",",
")",
"\n",
"actorWarnings",
":=",
"Warnings",
"(",
"apiWarnings",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"actorWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"var",
"droplets",
"[",
"]",
"Droplet",
"\n",
"for",
"_",
",",
"ccv3Droplet",
":=",
"range",
"ccv3Droplets",
"{",
"droplets",
"=",
"append",
"(",
"droplets",
",",
"actor",
".",
"convertCCToActorDroplet",
"(",
"ccv3Droplet",
")",
")",
"\n",
"}",
"\n",
"return",
"droplets",
",",
"allWarnings",
",",
"err",
"\n",
"}"
] | // GetApplicationDroplets returns the list of droplets that belong to applicaiton. | [
"GetApplicationDroplets",
"returns",
"the",
"list",
"of",
"droplets",
"that",
"belong",
"to",
"applicaiton",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v3action/droplet.go#L52-L75 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/resource.go | UpdateResourceMatch | func (client *Client) UpdateResourceMatch(resourcesToMatch []Resource) ([]Resource, Warnings, error) {
body, err := json.Marshal(resourcesToMatch)
if err != nil {
return nil, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutResourceMatchRequest,
Body: bytes.NewReader(body),
})
if err != nil {
return nil, nil, err
}
request.Header.Set("Content-Type", "application/json")
var matchedResources []Resource
response := cloudcontroller.Response{
DecodeJSONResponseInto: &matchedResources,
}
err = client.connection.Make(request, &response)
return matchedResources, response.Warnings, err
} | go | func (client *Client) UpdateResourceMatch(resourcesToMatch []Resource) ([]Resource, Warnings, error) {
body, err := json.Marshal(resourcesToMatch)
if err != nil {
return nil, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutResourceMatchRequest,
Body: bytes.NewReader(body),
})
if err != nil {
return nil, nil, err
}
request.Header.Set("Content-Type", "application/json")
var matchedResources []Resource
response := cloudcontroller.Response{
DecodeJSONResponseInto: &matchedResources,
}
err = client.connection.Make(request, &response)
return matchedResources, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"UpdateResourceMatch",
"(",
"resourcesToMatch",
"[",
"]",
"Resource",
")",
"(",
"[",
"]",
"Resource",
",",
"Warnings",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"resourcesToMatch",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PutResourceMatchRequest",
",",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"body",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"Content-Type\"",
",",
"\"application/json\"",
")",
"\n",
"var",
"matchedResources",
"[",
"]",
"Resource",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"matchedResources",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"matchedResources",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // UpdateResourceMatch returns the resources that exist on the cloud foundry instance
// from the set of resources given. | [
"UpdateResourceMatch",
"returns",
"the",
"resources",
"that",
"exist",
"on",
"the",
"cloud",
"foundry",
"instance",
"from",
"the",
"set",
"of",
"resources",
"given",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/resource.go#L74-L97 | train |
cloudfoundry/cli | api/uaa/user.go | CreateUser | func (client *Client) CreateUser(user string, password string, origin string) (User, error) {
userRequest := newUserRequestBody{
Username: user,
Password: password,
Origin: origin,
Name: userName{
FamilyName: user,
GivenName: user,
},
Emails: []email{
{
Value: user,
Primary: true,
},
},
}
bodyBytes, err := json.Marshal(userRequest)
if err != nil {
return User{}, err
}
request, err := client.newRequest(requestOptions{
RequestName: internal.PostUserRequest,
Header: http.Header{
"Content-Type": {"application/json"},
},
Body: bytes.NewBuffer(bodyBytes),
})
if err != nil {
return User{}, err
}
var userResponse newUserResponse
response := Response{
Result: &userResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return User{}, err
}
return User(userResponse), nil
} | go | func (client *Client) CreateUser(user string, password string, origin string) (User, error) {
userRequest := newUserRequestBody{
Username: user,
Password: password,
Origin: origin,
Name: userName{
FamilyName: user,
GivenName: user,
},
Emails: []email{
{
Value: user,
Primary: true,
},
},
}
bodyBytes, err := json.Marshal(userRequest)
if err != nil {
return User{}, err
}
request, err := client.newRequest(requestOptions{
RequestName: internal.PostUserRequest,
Header: http.Header{
"Content-Type": {"application/json"},
},
Body: bytes.NewBuffer(bodyBytes),
})
if err != nil {
return User{}, err
}
var userResponse newUserResponse
response := Response{
Result: &userResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return User{}, err
}
return User(userResponse), nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"CreateUser",
"(",
"user",
"string",
",",
"password",
"string",
",",
"origin",
"string",
")",
"(",
"User",
",",
"error",
")",
"{",
"userRequest",
":=",
"newUserRequestBody",
"{",
"Username",
":",
"user",
",",
"Password",
":",
"password",
",",
"Origin",
":",
"origin",
",",
"Name",
":",
"userName",
"{",
"FamilyName",
":",
"user",
",",
"GivenName",
":",
"user",
",",
"}",
",",
"Emails",
":",
"[",
"]",
"email",
"{",
"{",
"Value",
":",
"user",
",",
"Primary",
":",
"true",
",",
"}",
",",
"}",
",",
"}",
"\n",
"bodyBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"userRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"User",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"request",
",",
"err",
":=",
"client",
".",
"newRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PostUserRequest",
",",
"Header",
":",
"http",
".",
"Header",
"{",
"\"Content-Type\"",
":",
"{",
"\"application/json\"",
"}",
",",
"}",
",",
"Body",
":",
"bytes",
".",
"NewBuffer",
"(",
"bodyBytes",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"User",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"var",
"userResponse",
"newUserResponse",
"\n",
"response",
":=",
"Response",
"{",
"Result",
":",
"&",
"userResponse",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"User",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"User",
"(",
"userResponse",
")",
",",
"nil",
"\n",
"}"
] | // CreateUser creates a new UAA user account with the provided password. | [
"CreateUser",
"creates",
"a",
"new",
"UAA",
"user",
"account",
"with",
"the",
"provided",
"password",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/user.go#L41-L85 | train |
cloudfoundry/cli | actor/v2action/resource.go | ResourceMatch | func (actor Actor) ResourceMatch(allResources []Resource) ([]Resource, []Resource, Warnings, error) {
resourcesToSend := [][]ccv2.Resource{{}}
var currentList, sendCount int
for _, resource := range allResources {
// Skip if resource is a directory, symlink, or empty file.
if resource.Size == 0 {
continue
}
resourcesToSend[currentList] = append(
resourcesToSend[currentList],
ccv2.Resource(resource),
)
sendCount++
if len(resourcesToSend[currentList]) == MaxResourceMatchChunkSize {
currentList++
resourcesToSend = append(resourcesToSend, []ccv2.Resource{})
}
}
log.WithFields(log.Fields{
"total_resources": len(allResources),
"resources_to_match": sendCount,
"chunks": len(resourcesToSend),
}).Debug("sending resource match stats")
matchedCCResources := map[string]ccv2.Resource{}
var allWarnings Warnings
for _, chunk := range resourcesToSend {
if len(chunk) == 0 {
log.Debug("chunk size 0, stopping resource match requests")
break
}
returnedResources, warnings, err := actor.CloudControllerClient.UpdateResourceMatch(chunk)
allWarnings = append(allWarnings, warnings...)
if err != nil {
log.Errorln("during resource matching", err)
return nil, nil, allWarnings, err
}
for _, resource := range returnedResources {
matchedCCResources[resource.SHA1] = resource
}
}
log.WithField("matched_resource_count", len(matchedCCResources)).Debug("total number of matched resources")
var matchedResources, unmatchedResources []Resource
for _, resource := range allResources {
if _, ok := matchedCCResources[resource.SHA1]; ok {
matchedResources = append(matchedResources, resource)
} else {
unmatchedResources = append(unmatchedResources, resource)
}
}
return matchedResources, unmatchedResources, allWarnings, nil
} | go | func (actor Actor) ResourceMatch(allResources []Resource) ([]Resource, []Resource, Warnings, error) {
resourcesToSend := [][]ccv2.Resource{{}}
var currentList, sendCount int
for _, resource := range allResources {
// Skip if resource is a directory, symlink, or empty file.
if resource.Size == 0 {
continue
}
resourcesToSend[currentList] = append(
resourcesToSend[currentList],
ccv2.Resource(resource),
)
sendCount++
if len(resourcesToSend[currentList]) == MaxResourceMatchChunkSize {
currentList++
resourcesToSend = append(resourcesToSend, []ccv2.Resource{})
}
}
log.WithFields(log.Fields{
"total_resources": len(allResources),
"resources_to_match": sendCount,
"chunks": len(resourcesToSend),
}).Debug("sending resource match stats")
matchedCCResources := map[string]ccv2.Resource{}
var allWarnings Warnings
for _, chunk := range resourcesToSend {
if len(chunk) == 0 {
log.Debug("chunk size 0, stopping resource match requests")
break
}
returnedResources, warnings, err := actor.CloudControllerClient.UpdateResourceMatch(chunk)
allWarnings = append(allWarnings, warnings...)
if err != nil {
log.Errorln("during resource matching", err)
return nil, nil, allWarnings, err
}
for _, resource := range returnedResources {
matchedCCResources[resource.SHA1] = resource
}
}
log.WithField("matched_resource_count", len(matchedCCResources)).Debug("total number of matched resources")
var matchedResources, unmatchedResources []Resource
for _, resource := range allResources {
if _, ok := matchedCCResources[resource.SHA1]; ok {
matchedResources = append(matchedResources, resource)
} else {
unmatchedResources = append(unmatchedResources, resource)
}
}
return matchedResources, unmatchedResources, allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"ResourceMatch",
"(",
"allResources",
"[",
"]",
"Resource",
")",
"(",
"[",
"]",
"Resource",
",",
"[",
"]",
"Resource",
",",
"Warnings",
",",
"error",
")",
"{",
"resourcesToSend",
":=",
"[",
"]",
"[",
"]",
"ccv2",
".",
"Resource",
"{",
"{",
"}",
"}",
"\n",
"var",
"currentList",
",",
"sendCount",
"int",
"\n",
"for",
"_",
",",
"resource",
":=",
"range",
"allResources",
"{",
"if",
"resource",
".",
"Size",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"resourcesToSend",
"[",
"currentList",
"]",
"=",
"append",
"(",
"resourcesToSend",
"[",
"currentList",
"]",
",",
"ccv2",
".",
"Resource",
"(",
"resource",
")",
",",
")",
"\n",
"sendCount",
"++",
"\n",
"if",
"len",
"(",
"resourcesToSend",
"[",
"currentList",
"]",
")",
"==",
"MaxResourceMatchChunkSize",
"{",
"currentList",
"++",
"\n",
"resourcesToSend",
"=",
"append",
"(",
"resourcesToSend",
",",
"[",
"]",
"ccv2",
".",
"Resource",
"{",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"total_resources\"",
":",
"len",
"(",
"allResources",
")",
",",
"\"resources_to_match\"",
":",
"sendCount",
",",
"\"chunks\"",
":",
"len",
"(",
"resourcesToSend",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"sending resource match stats\"",
")",
"\n",
"matchedCCResources",
":=",
"map",
"[",
"string",
"]",
"ccv2",
".",
"Resource",
"{",
"}",
"\n",
"var",
"allWarnings",
"Warnings",
"\n",
"for",
"_",
",",
"chunk",
":=",
"range",
"resourcesToSend",
"{",
"if",
"len",
"(",
"chunk",
")",
"==",
"0",
"{",
"log",
".",
"Debug",
"(",
"\"chunk size 0, stopping resource match requests\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"returnedResources",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateResourceMatch",
"(",
"chunk",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorln",
"(",
"\"during resource matching\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"resource",
":=",
"range",
"returnedResources",
"{",
"matchedCCResources",
"[",
"resource",
".",
"SHA1",
"]",
"=",
"resource",
"\n",
"}",
"\n",
"}",
"\n",
"log",
".",
"WithField",
"(",
"\"matched_resource_count\"",
",",
"len",
"(",
"matchedCCResources",
")",
")",
".",
"Debug",
"(",
"\"total number of matched resources\"",
")",
"\n",
"var",
"matchedResources",
",",
"unmatchedResources",
"[",
"]",
"Resource",
"\n",
"for",
"_",
",",
"resource",
":=",
"range",
"allResources",
"{",
"if",
"_",
",",
"ok",
":=",
"matchedCCResources",
"[",
"resource",
".",
"SHA1",
"]",
";",
"ok",
"{",
"matchedResources",
"=",
"append",
"(",
"matchedResources",
",",
"resource",
")",
"\n",
"}",
"else",
"{",
"unmatchedResources",
"=",
"append",
"(",
"unmatchedResources",
",",
"resource",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"matchedResources",
",",
"unmatchedResources",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // ResourceMatch returns a set of matched resources and unmatched resources in
// the order they were given in allResources. | [
"ResourceMatch",
"returns",
"a",
"set",
"of",
"matched",
"resources",
"and",
"unmatched",
"resources",
"in",
"the",
"order",
"they",
"were",
"given",
"in",
"allResources",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/resource.go#L30-L89 | train |
cloudfoundry/cli | api/cloudcontroller/cloud_controller_connection.go | NewConnection | func NewConnection(config Config) *CloudControllerConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.SkipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: config.DialTimeout,
}).DialContext,
}
return &CloudControllerConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | go | func NewConnection(config Config) *CloudControllerConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.SkipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: config.DialTimeout,
}).DialContext,
}
return &CloudControllerConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | [
"func",
"NewConnection",
"(",
"config",
"Config",
")",
"*",
"CloudControllerConnection",
"{",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"config",
".",
"SkipSSLValidation",
",",
"}",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"DialContext",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"config",
".",
"DialTimeout",
",",
"}",
")",
".",
"DialContext",
",",
"}",
"\n",
"return",
"&",
"CloudControllerConnection",
"{",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
"}",
",",
"}",
"\n",
"}"
] | // NewConnection returns a new CloudControllerConnection with provided
// configuration. | [
"NewConnection",
"returns",
"a",
"new",
"CloudControllerConnection",
"with",
"provided",
"configuration",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/cloud_controller_connection.go#L31-L46 | train |
cloudfoundry/cli | api/cloudcontroller/cloud_controller_connection.go | handleWarnings | func (*CloudControllerConnection) handleWarnings(response *http.Response) ([]string, error) {
rawWarnings := response.Header.Get("X-Cf-Warnings")
if len(rawWarnings) == 0 {
return nil, nil
}
var warnings []string
for _, rawWarning := range strings.Split(rawWarnings, ",") {
warning, err := url.QueryUnescape(rawWarning)
if err != nil {
return nil, err
}
warnings = append(warnings, strings.Trim(warning, " "))
}
return warnings, nil
} | go | func (*CloudControllerConnection) handleWarnings(response *http.Response) ([]string, error) {
rawWarnings := response.Header.Get("X-Cf-Warnings")
if len(rawWarnings) == 0 {
return nil, nil
}
var warnings []string
for _, rawWarning := range strings.Split(rawWarnings, ",") {
warning, err := url.QueryUnescape(rawWarning)
if err != nil {
return nil, err
}
warnings = append(warnings, strings.Trim(warning, " "))
}
return warnings, nil
} | [
"func",
"(",
"*",
"CloudControllerConnection",
")",
"handleWarnings",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"rawWarnings",
":=",
"response",
".",
"Header",
".",
"Get",
"(",
"\"X-Cf-Warnings\"",
")",
"\n",
"if",
"len",
"(",
"rawWarnings",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"var",
"warnings",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"rawWarning",
":=",
"range",
"strings",
".",
"Split",
"(",
"rawWarnings",
",",
"\",\"",
")",
"{",
"warning",
",",
"err",
":=",
"url",
".",
"QueryUnescape",
"(",
"rawWarning",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"warnings",
"=",
"append",
"(",
"warnings",
",",
"strings",
".",
"Trim",
"(",
"warning",
",",
"\" \"",
")",
")",
"\n",
"}",
"\n",
"return",
"warnings",
",",
"nil",
"\n",
"}"
] | // handleWarnings looks for the "X-Cf-Warnings" header in the cloud controller
// response and URI decodes them. The value can contain multiple warnings that
// are comma separated. | [
"handleWarnings",
"looks",
"for",
"the",
"X",
"-",
"Cf",
"-",
"Warnings",
"header",
"in",
"the",
"cloud",
"controller",
"response",
"and",
"URI",
"decodes",
"them",
".",
"The",
"value",
"can",
"contain",
"multiple",
"warnings",
"that",
"are",
"comma",
"separated",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/cloud_controller_connection.go#L90-L106 | train |
cloudfoundry/cli | cf/actors/push.go | ProcessPath | func (actor PushActorImpl) ProcessPath(dirOrZipFile string, f func(string) error) error {
if !actor.zipper.IsZipFile(dirOrZipFile) {
if filepath.IsAbs(dirOrZipFile) {
appDir, err := filepath.EvalSymlinks(dirOrZipFile)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
} else {
absPath, err := filepath.Abs(dirOrZipFile)
if err != nil {
return err
}
appDir, err := filepath.EvalSymlinks(absPath)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
}
return nil
}
tempDir, err := ioutil.TempDir("", "unzipped-app")
if err != nil {
return err
}
err = actor.zipper.Unzip(dirOrZipFile, tempDir)
if err != nil {
return err
}
err = f(tempDir)
if err != nil {
return err
}
err = os.RemoveAll(tempDir)
if err != nil {
return err
}
return nil
} | go | func (actor PushActorImpl) ProcessPath(dirOrZipFile string, f func(string) error) error {
if !actor.zipper.IsZipFile(dirOrZipFile) {
if filepath.IsAbs(dirOrZipFile) {
appDir, err := filepath.EvalSymlinks(dirOrZipFile)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
} else {
absPath, err := filepath.Abs(dirOrZipFile)
if err != nil {
return err
}
appDir, err := filepath.EvalSymlinks(absPath)
if err != nil {
return err
}
err = f(appDir)
if err != nil {
return err
}
}
return nil
}
tempDir, err := ioutil.TempDir("", "unzipped-app")
if err != nil {
return err
}
err = actor.zipper.Unzip(dirOrZipFile, tempDir)
if err != nil {
return err
}
err = f(tempDir)
if err != nil {
return err
}
err = os.RemoveAll(tempDir)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"actor",
"PushActorImpl",
")",
"ProcessPath",
"(",
"dirOrZipFile",
"string",
",",
"f",
"func",
"(",
"string",
")",
"error",
")",
"error",
"{",
"if",
"!",
"actor",
".",
"zipper",
".",
"IsZipFile",
"(",
"dirOrZipFile",
")",
"{",
"if",
"filepath",
".",
"IsAbs",
"(",
"dirOrZipFile",
")",
"{",
"appDir",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"dirOrZipFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"f",
"(",
"appDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dirOrZipFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"appDir",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"absPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"f",
"(",
"appDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"tempDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"\"",
",",
"\"unzipped-app\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"actor",
".",
"zipper",
".",
"Unzip",
"(",
"dirOrZipFile",
",",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"f",
"(",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"os",
".",
"RemoveAll",
"(",
"tempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ProcessPath takes in a director of app files or a zip file which contains
// the app files. If given a zip file, it will extract the zip to a temporary
// location, call the provided callback with that location, and then clean up
// the location after the callback has been executed.
//
// This was done so that the caller of ProcessPath wouldn't need to know if it
// was a zip file or an app dir that it was given, and the caller would not be
// responsible for cleaning up the temporary directory ProcessPath creates when
// given a zip. | [
"ProcessPath",
"takes",
"in",
"a",
"director",
"of",
"app",
"files",
"or",
"a",
"zip",
"file",
"which",
"contains",
"the",
"app",
"files",
".",
"If",
"given",
"a",
"zip",
"file",
"it",
"will",
"extract",
"the",
"zip",
"to",
"a",
"temporary",
"location",
"call",
"the",
"provided",
"callback",
"with",
"that",
"location",
"and",
"then",
"clean",
"up",
"the",
"location",
"after",
"the",
"callback",
"has",
"been",
"executed",
".",
"This",
"was",
"done",
"so",
"that",
"the",
"caller",
"of",
"ProcessPath",
"wouldn",
"t",
"need",
"to",
"know",
"if",
"it",
"was",
"a",
"zip",
"file",
"or",
"an",
"app",
"dir",
"that",
"it",
"was",
"given",
"and",
"the",
"caller",
"would",
"not",
"be",
"responsible",
"for",
"cleaning",
"up",
"the",
"temporary",
"directory",
"ProcessPath",
"creates",
"when",
"given",
"a",
"zip",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/cf/actors/push.go#L55-L106 | train |
cloudfoundry/cli | actor/sharedaction/is_logged_in.go | IsLoggedIn | func (actor Actor) IsLoggedIn() bool {
return actor.Config.AccessToken() != "" || actor.Config.RefreshToken() != ""
} | go | func (actor Actor) IsLoggedIn() bool {
return actor.Config.AccessToken() != "" || actor.Config.RefreshToken() != ""
} | [
"func",
"(",
"actor",
"Actor",
")",
"IsLoggedIn",
"(",
")",
"bool",
"{",
"return",
"actor",
".",
"Config",
".",
"AccessToken",
"(",
")",
"!=",
"\"\"",
"||",
"actor",
".",
"Config",
".",
"RefreshToken",
"(",
")",
"!=",
"\"\"",
"\n",
"}"
] | // IsLoggedIn checks whether a user has authenticated with CF | [
"IsLoggedIn",
"checks",
"whether",
"a",
"user",
"has",
"authenticated",
"with",
"CF"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/sharedaction/is_logged_in.go#L4-L6 | train |
cloudfoundry/cli | api/plugin/request.go | newGETRequest | func (client *Client) newGETRequest(url string) (*http.Request, error) {
request, err := http.NewRequest(
http.MethodGet,
url,
nil,
)
if err != nil {
return nil, err
}
request.Header = http.Header{}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", client.userAgent)
return request, nil
} | go | func (client *Client) newGETRequest(url string) (*http.Request, error) {
request, err := http.NewRequest(
http.MethodGet,
url,
nil,
)
if err != nil {
return nil, err
}
request.Header = http.Header{}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("User-Agent", client.userAgent)
return request, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"newGETRequest",
"(",
"url",
"string",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"url",
",",
"nil",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"request",
".",
"Header",
"=",
"http",
".",
"Header",
"{",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"Accept\"",
",",
"\"application/json\"",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"Content-Type\"",
",",
"\"application/json\"",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"User-Agent\"",
",",
"client",
".",
"userAgent",
")",
"\n",
"return",
"request",
",",
"nil",
"\n",
"}"
] | // newGETRequest returns a constructed HTTP.Request with some defaults.
// Defaults are applied when Request options are not filled in. | [
"newGETRequest",
"returns",
"a",
"constructed",
"HTTP",
".",
"Request",
"with",
"some",
"defaults",
".",
"Defaults",
"are",
"applied",
"when",
"Request",
"options",
"are",
"not",
"filled",
"in",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/plugin/request.go#L7-L23 | train |
cloudfoundry/cli | api/cloudcontroller/minimum_version_check.go | MinimumAPIVersionCheck | func MinimumAPIVersionCheck(current string, minimum string) error {
if minimum == "" {
return nil
}
currentSemver, err := semver.Make(current)
if err != nil {
return err
}
minimumSemver, err := semver.Make(minimum)
if err != nil {
return err
}
if currentSemver.Compare(minimumSemver) == -1 {
return ccerror.MinimumAPIVersionNotMetError{
CurrentVersion: current,
MinimumVersion: minimum,
}
}
return nil
} | go | func MinimumAPIVersionCheck(current string, minimum string) error {
if minimum == "" {
return nil
}
currentSemver, err := semver.Make(current)
if err != nil {
return err
}
minimumSemver, err := semver.Make(minimum)
if err != nil {
return err
}
if currentSemver.Compare(minimumSemver) == -1 {
return ccerror.MinimumAPIVersionNotMetError{
CurrentVersion: current,
MinimumVersion: minimum,
}
}
return nil
} | [
"func",
"MinimumAPIVersionCheck",
"(",
"current",
"string",
",",
"minimum",
"string",
")",
"error",
"{",
"if",
"minimum",
"==",
"\"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"currentSemver",
",",
"err",
":=",
"semver",
".",
"Make",
"(",
"current",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"minimumSemver",
",",
"err",
":=",
"semver",
".",
"Make",
"(",
"minimum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"currentSemver",
".",
"Compare",
"(",
"minimumSemver",
")",
"==",
"-",
"1",
"{",
"return",
"ccerror",
".",
"MinimumAPIVersionNotMetError",
"{",
"CurrentVersion",
":",
"current",
",",
"MinimumVersion",
":",
"minimum",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // MinimumAPIVersionCheck compares `current` to `minimum`. If `current` is
// older than `minimum` then an error is returned; otherwise, nil is returned. | [
"MinimumAPIVersionCheck",
"compares",
"current",
"to",
"minimum",
".",
"If",
"current",
"is",
"older",
"than",
"minimum",
"then",
"an",
"error",
"is",
"returned",
";",
"otherwise",
"nil",
"is",
"returned",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/minimum_version_check.go#L10-L33 | train |
cloudfoundry/cli | util/ui/request_logger_file_writer.go | RequestLoggerFileWriter | func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter {
return newRequestLoggerFileWriter(ui, ui.fileLock, filePaths)
} | go | func (ui *UI) RequestLoggerFileWriter(filePaths []string) *RequestLoggerFileWriter {
return newRequestLoggerFileWriter(ui, ui.fileLock, filePaths)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"RequestLoggerFileWriter",
"(",
"filePaths",
"[",
"]",
"string",
")",
"*",
"RequestLoggerFileWriter",
"{",
"return",
"newRequestLoggerFileWriter",
"(",
"ui",
",",
"ui",
".",
"fileLock",
",",
"filePaths",
")",
"\n",
"}"
] | // RequestLoggerFileWriter returns a RequestLoggerFileWriter that cannot
// overwrite another RequestLoggerFileWriter. | [
"RequestLoggerFileWriter",
"returns",
"a",
"RequestLoggerFileWriter",
"that",
"cannot",
"overwrite",
"another",
"RequestLoggerFileWriter",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/request_logger_file_writer.go#L142-L144 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | UnmarshalJSON | func (stack *Stack) UnmarshalJSON(data []byte) error {
var ccStack struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccStack)
if err != nil {
return err
}
stack.GUID = ccStack.Metadata.GUID
stack.Name = ccStack.Entity.Name
stack.Description = ccStack.Entity.Description
return nil
} | go | func (stack *Stack) UnmarshalJSON(data []byte) error {
var ccStack struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccStack)
if err != nil {
return err
}
stack.GUID = ccStack.Metadata.GUID
stack.Name = ccStack.Entity.Name
stack.Description = ccStack.Entity.Description
return nil
} | [
"func",
"(",
"stack",
"*",
"Stack",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccStack",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"Description",
"string",
"`json:\"description\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccStack",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"stack",
".",
"GUID",
"=",
"ccStack",
".",
"Metadata",
".",
"GUID",
"\n",
"stack",
".",
"Name",
"=",
"ccStack",
".",
"Entity",
".",
"Name",
"\n",
"stack",
".",
"Description",
"=",
"ccStack",
".",
"Entity",
".",
"Description",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Stack response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Stack",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L22-L39 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | GetStack | func (client *Client) GetStack(guid string) (Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStackRequest,
URIParams: Params{"stack_guid": guid},
})
if err != nil {
return Stack{}, nil, err
}
var stack Stack
response := cloudcontroller.Response{
DecodeJSONResponseInto: &stack,
}
err = client.connection.Make(request, &response)
return stack, response.Warnings, err
} | go | func (client *Client) GetStack(guid string) (Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStackRequest,
URIParams: Params{"stack_guid": guid},
})
if err != nil {
return Stack{}, nil, err
}
var stack Stack
response := cloudcontroller.Response{
DecodeJSONResponseInto: &stack,
}
err = client.connection.Make(request, &response)
return stack, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetStack",
"(",
"guid",
"string",
")",
"(",
"Stack",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetStackRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"stack_guid\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Stack",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"stack",
"Stack",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"stack",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"stack",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetStack returns the requested stack. | [
"GetStack",
"returns",
"the",
"requested",
"stack",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L42-L58 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/stack.go | GetStacks | func (client *Client) GetStacks(filters ...Filter) ([]Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStacksRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullStacksList []Stack
warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
if space, ok := item.(Stack); ok {
fullStacksList = append(fullStacksList, space)
} else {
return ccerror.UnknownObjectInListError{
Expected: Stack{},
Unexpected: item,
}
}
return nil
})
return fullStacksList, warnings, err
} | go | func (client *Client) GetStacks(filters ...Filter) ([]Stack, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetStacksRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullStacksList []Stack
warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
if space, ok := item.(Stack); ok {
fullStacksList = append(fullStacksList, space)
} else {
return ccerror.UnknownObjectInListError{
Expected: Stack{},
Unexpected: item,
}
}
return nil
})
return fullStacksList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetStacks",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"Stack",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetStacksRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullStacksList",
"[",
"]",
"Stack",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Stack",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"space",
",",
"ok",
":=",
"item",
".",
"(",
"Stack",
")",
";",
"ok",
"{",
"fullStacksList",
"=",
"append",
"(",
"fullStacksList",
",",
"space",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Stack",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullStacksList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetStacks returns a list of Stacks based off of the provided filters. | [
"GetStacks",
"returns",
"a",
"list",
"of",
"Stacks",
"based",
"off",
"of",
"the",
"provided",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/stack.go#L61-L84 | train |
cloudfoundry/cli | api/cloudcontroller/wrapper/uaa_authentication.go | refreshToken | func (t *UAAAuthentication) refreshToken() error {
var expiresIn time.Duration
tokenStr := strings.TrimPrefix(t.cache.AccessToken(), "bearer ")
token, err := jws.ParseJWT([]byte(tokenStr))
if err != nil {
// if the JWT could not be parsed, force a refresh
expiresIn = 0
} else {
expiration, _ := token.Claims().Expiration()
expiresIn = time.Until(expiration)
}
if expiresIn < accessTokenExpirationMargin {
tokens, err := t.client.RefreshAccessToken(t.cache.RefreshToken())
if err != nil {
return err
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
}
return nil
} | go | func (t *UAAAuthentication) refreshToken() error {
var expiresIn time.Duration
tokenStr := strings.TrimPrefix(t.cache.AccessToken(), "bearer ")
token, err := jws.ParseJWT([]byte(tokenStr))
if err != nil {
// if the JWT could not be parsed, force a refresh
expiresIn = 0
} else {
expiration, _ := token.Claims().Expiration()
expiresIn = time.Until(expiration)
}
if expiresIn < accessTokenExpirationMargin {
tokens, err := t.client.RefreshAccessToken(t.cache.RefreshToken())
if err != nil {
return err
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
}
return nil
} | [
"func",
"(",
"t",
"*",
"UAAAuthentication",
")",
"refreshToken",
"(",
")",
"error",
"{",
"var",
"expiresIn",
"time",
".",
"Duration",
"\n",
"tokenStr",
":=",
"strings",
".",
"TrimPrefix",
"(",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
",",
"\"bearer \"",
")",
"\n",
"token",
",",
"err",
":=",
"jws",
".",
"ParseJWT",
"(",
"[",
"]",
"byte",
"(",
"tokenStr",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"expiresIn",
"=",
"0",
"\n",
"}",
"else",
"{",
"expiration",
",",
"_",
":=",
"token",
".",
"Claims",
"(",
")",
".",
"Expiration",
"(",
")",
"\n",
"expiresIn",
"=",
"time",
".",
"Until",
"(",
"expiration",
")",
"\n",
"}",
"\n",
"if",
"expiresIn",
"<",
"accessTokenExpirationMargin",
"{",
"tokens",
",",
"err",
":=",
"t",
".",
"client",
".",
"RefreshAccessToken",
"(",
"t",
".",
"cache",
".",
"RefreshToken",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"t",
".",
"cache",
".",
"SetAccessToken",
"(",
"tokens",
".",
"AuthorizationToken",
"(",
")",
")",
"\n",
"t",
".",
"cache",
".",
"SetRefreshToken",
"(",
"tokens",
".",
"RefreshToken",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // refreshToken refreshes the JWT access token if it is expired or about to expire.
// If the access token is not yet expired, no action is performed. | [
"refreshToken",
"refreshes",
"the",
"JWT",
"access",
"token",
"if",
"it",
"is",
"expired",
"or",
"about",
"to",
"expire",
".",
"If",
"the",
"access",
"token",
"is",
"not",
"yet",
"expired",
"no",
"action",
"is",
"performed",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/wrapper/uaa_authentication.go#L83-L105 | train |
cloudfoundry/cli | actor/v2action/service_access.go | EnableServiceForOrg | func (actor Actor) EnableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Public != true {
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | go | func (actor Actor) EnableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Public != true {
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"EnableServiceForOrg",
"(",
"serviceName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Public",
"!=",
"true",
"{",
"_",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateServicePlanVisibility",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"alreadyExistsError",
":=",
"err",
".",
"(",
"ccerror",
".",
"ServicePlanVisibilityExistsError",
")",
";",
"alreadyExistsError",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // EnableServiceForOrg enables access for the given service in a specific org. | [
"EnableServiceForOrg",
"enables",
"access",
"for",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L63-L89 | train |
cloudfoundry/cli | actor/v2action/service_access.go | EnablePlanForOrg | func (actor Actor) EnablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
if plan.Public {
return allWarnings, nil
}
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
return allWarnings, err
}
}
return nil, fmt.Errorf("Service plan '%s' not found", servicePlanName)
} | go | func (actor Actor) EnablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
if plan.Public {
return allWarnings, nil
}
_, warnings, err := actor.CloudControllerClient.CreateServicePlanVisibility(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if _, alreadyExistsError := err.(ccerror.ServicePlanVisibilityExistsError); alreadyExistsError {
return allWarnings, nil
}
return allWarnings, err
}
}
return nil, fmt.Errorf("Service plan '%s' not found", servicePlanName)
} | [
"func",
"(",
"actor",
"Actor",
")",
"EnablePlanForOrg",
"(",
"serviceName",
",",
"servicePlanName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"if",
"plan",
".",
"Public",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"_",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateServicePlanVisibility",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"alreadyExistsError",
":=",
"err",
".",
"(",
"ccerror",
".",
"ServicePlanVisibilityExistsError",
")",
";",
"alreadyExistsError",
"{",
"return",
"allWarnings",
",",
"nil",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Service plan '%s' not found\"",
",",
"servicePlanName",
")",
"\n",
"}"
] | // EnablePlanForOrg enables access to a specific plan of the given service in a specific org. | [
"EnablePlanForOrg",
"enables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L92-L119 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisableServiceForAllOrgs | func (actor Actor) DisableServiceForAllOrgs(serviceName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | go | func (actor Actor) DisableServiceForAllOrgs(serviceName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisableServiceForAllOrgs",
"(",
"serviceName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"\"\"",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"if",
"plan",
".",
"Public",
"==",
"true",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateServicePlan",
"(",
"plan",
".",
"GUID",
",",
"false",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisableServiceForAllOrgs disables access for the given service in all orgs. | [
"DisableServiceForAllOrgs",
"disables",
"access",
"for",
"the",
"given",
"service",
"in",
"all",
"orgs",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L122-L144 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisablePlanForAllOrgs | func (actor Actor) DisablePlanForAllOrgs(serviceName, servicePlanName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
ccv2Warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, ccv2Warnings...)
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | go | func (actor Actor) DisablePlanForAllOrgs(serviceName, servicePlanName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, "")
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
if plan.Public == true {
ccv2Warnings, err := actor.CloudControllerClient.UpdateServicePlan(plan.GUID, false)
allWarnings = append(allWarnings, ccv2Warnings...)
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisablePlanForAllOrgs",
"(",
"serviceName",
",",
"servicePlanName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
":=",
"false",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"\"\"",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"if",
"plan",
".",
"Public",
"==",
"true",
"{",
"ccv2Warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateServicePlan",
"(",
"plan",
".",
"GUID",
",",
"false",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"ccv2Warnings",
"...",
")",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"planFound",
"==",
"false",
"{",
"return",
"allWarnings",
",",
"actionerror",
".",
"ServicePlanNotFoundError",
"{",
"PlanName",
":",
"servicePlanName",
",",
"ServiceName",
":",
"serviceName",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisablePlanForAllOrgs disables access to a specific plan of the given service, from the given broker in all orgs. | [
"DisablePlanForAllOrgs",
"disables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"from",
"the",
"given",
"broker",
"in",
"all",
"orgs",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L147-L176 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisableServiceForOrg | func (actor Actor) DisableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
return allWarnings, nil
} | go | func (actor Actor) DisableServiceForOrg(serviceName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
for _, plan := range servicePlans {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisableServiceForOrg",
"(",
"serviceName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisableServiceForOrg disables access for the given service in a specific org. | [
"DisableServiceForOrg",
"disables",
"access",
"for",
"the",
"given",
"service",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L179-L199 | train |
cloudfoundry/cli | actor/v2action/service_access.go | DisablePlanForOrg | func (actor Actor) DisablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | go | func (actor Actor) DisablePlanForOrg(serviceName, servicePlanName, orgName, brokerName string) (Warnings, error) {
servicePlans, allWarnings, err := actor.GetServicePlansForService(serviceName, brokerName)
if err != nil {
return allWarnings, err
}
org, orgWarnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, orgWarnings...)
if err != nil {
return allWarnings, err
}
planFound := false
for _, plan := range servicePlans {
if plan.Name == servicePlanName {
warnings, err := actor.removeOrgLevelServicePlanVisibilities(plan.GUID, org.GUID)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
planFound = true
break
}
}
if planFound == false {
return allWarnings, actionerror.ServicePlanNotFoundError{PlanName: servicePlanName, ServiceName: serviceName}
}
return allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"DisablePlanForOrg",
"(",
"serviceName",
",",
"servicePlanName",
",",
"orgName",
",",
"brokerName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"servicePlans",
",",
"allWarnings",
",",
"err",
":=",
"actor",
".",
"GetServicePlansForService",
"(",
"serviceName",
",",
"brokerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"org",
",",
"orgWarnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"orgWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
":=",
"false",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"if",
"plan",
".",
"Name",
"==",
"servicePlanName",
"{",
"warnings",
",",
"err",
":=",
"actor",
".",
"removeOrgLevelServicePlanVisibilities",
"(",
"plan",
".",
"GUID",
",",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"planFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"planFound",
"==",
"false",
"{",
"return",
"allWarnings",
",",
"actionerror",
".",
"ServicePlanNotFoundError",
"{",
"PlanName",
":",
"servicePlanName",
",",
"ServiceName",
":",
"serviceName",
"}",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // DisablePlanForOrg disables access to a specific plan of the given service from the given broker in a specific org. | [
"DisablePlanForOrg",
"disables",
"access",
"to",
"a",
"specific",
"plan",
"of",
"the",
"given",
"service",
"from",
"the",
"given",
"broker",
"in",
"a",
"specific",
"org",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service_access.go#L202-L231 | train |
cloudfoundry/cli | integration/helpers/service_instance.go | ManagedServiceInstanceGUID | func ManagedServiceInstanceGUID(managedServiceInstanceName string) string {
session := CF("curl", fmt.Sprintf("/v2/service_instances?q=name:%s", managedServiceInstanceName))
Eventually(session).Should(Exit(0))
rawJSON := strings.TrimSpace(string(session.Out.Contents()))
var serviceInstanceGUID ServiceInstanceGUID
err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID)
Expect(err).NotTo(HaveOccurred())
Expect(serviceInstanceGUID.Resources).To(HaveLen(1))
return serviceInstanceGUID.Resources[0].Metadata.GUID
} | go | func ManagedServiceInstanceGUID(managedServiceInstanceName string) string {
session := CF("curl", fmt.Sprintf("/v2/service_instances?q=name:%s", managedServiceInstanceName))
Eventually(session).Should(Exit(0))
rawJSON := strings.TrimSpace(string(session.Out.Contents()))
var serviceInstanceGUID ServiceInstanceGUID
err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID)
Expect(err).NotTo(HaveOccurred())
Expect(serviceInstanceGUID.Resources).To(HaveLen(1))
return serviceInstanceGUID.Resources[0].Metadata.GUID
} | [
"func",
"ManagedServiceInstanceGUID",
"(",
"managedServiceInstanceName",
"string",
")",
"string",
"{",
"session",
":=",
"CF",
"(",
"\"curl\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"/v2/service_instances?q=name:%s\"",
",",
"managedServiceInstanceName",
")",
")",
"\n",
"Eventually",
"(",
"session",
")",
".",
"Should",
"(",
"Exit",
"(",
"0",
")",
")",
"\n",
"rawJSON",
":=",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"session",
".",
"Out",
".",
"Contents",
"(",
")",
")",
")",
"\n",
"var",
"serviceInstanceGUID",
"ServiceInstanceGUID",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"rawJSON",
")",
",",
"&",
"serviceInstanceGUID",
")",
"\n",
"Expect",
"(",
"err",
")",
".",
"NotTo",
"(",
"HaveOccurred",
"(",
")",
")",
"\n",
"Expect",
"(",
"serviceInstanceGUID",
".",
"Resources",
")",
".",
"To",
"(",
"HaveLen",
"(",
"1",
")",
")",
"\n",
"return",
"serviceInstanceGUID",
".",
"Resources",
"[",
"0",
"]",
".",
"Metadata",
".",
"GUID",
"\n",
"}"
] | // ManagedServiceInstanceGUID returns the GUID for a managed service instance. | [
"ManagedServiceInstanceGUID",
"returns",
"the",
"GUID",
"for",
"a",
"managed",
"service",
"instance",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/integration/helpers/service_instance.go#L21-L33 | train |
cloudfoundry/cli | api/uaa/wrapper/uaa_authentication.go | Make | func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Response) error {
if t.client == nil {
return t.connection.Make(request, passedResponse)
}
var err error
var rawRequestBody []byte
if request.Body != nil {
rawRequestBody, err = ioutil.ReadAll(request.Body)
defer request.Body.Close()
if err != nil {
return err
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
if skipAuthenticationHeader(request, rawRequestBody) {
return t.connection.Make(request, passedResponse)
}
}
request.Header.Set("Authorization", t.cache.AccessToken())
err = t.connection.Make(request, passedResponse)
if _, ok := err.(uaa.InvalidAuthTokenError); ok {
tokens, refreshErr := t.client.RefreshAccessToken(t.cache.RefreshToken())
if refreshErr != nil {
return refreshErr
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
if rawRequestBody != nil {
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
}
request.Header.Set("Authorization", t.cache.AccessToken())
return t.connection.Make(request, passedResponse)
}
return err
} | go | func (t *UAAAuthentication) Make(request *http.Request, passedResponse *uaa.Response) error {
if t.client == nil {
return t.connection.Make(request, passedResponse)
}
var err error
var rawRequestBody []byte
if request.Body != nil {
rawRequestBody, err = ioutil.ReadAll(request.Body)
defer request.Body.Close()
if err != nil {
return err
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
if skipAuthenticationHeader(request, rawRequestBody) {
return t.connection.Make(request, passedResponse)
}
}
request.Header.Set("Authorization", t.cache.AccessToken())
err = t.connection.Make(request, passedResponse)
if _, ok := err.(uaa.InvalidAuthTokenError); ok {
tokens, refreshErr := t.client.RefreshAccessToken(t.cache.RefreshToken())
if refreshErr != nil {
return refreshErr
}
t.cache.SetAccessToken(tokens.AuthorizationToken())
t.cache.SetRefreshToken(tokens.RefreshToken)
if rawRequestBody != nil {
request.Body = ioutil.NopCloser(bytes.NewBuffer(rawRequestBody))
}
request.Header.Set("Authorization", t.cache.AccessToken())
return t.connection.Make(request, passedResponse)
}
return err
} | [
"func",
"(",
"t",
"*",
"UAAAuthentication",
")",
"Make",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"passedResponse",
"*",
"uaa",
".",
"Response",
")",
"error",
"{",
"if",
"t",
".",
"client",
"==",
"nil",
"{",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"var",
"rawRequestBody",
"[",
"]",
"byte",
"\n",
"if",
"request",
".",
"Body",
"!=",
"nil",
"{",
"rawRequestBody",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"request",
".",
"Body",
")",
"\n",
"defer",
"request",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"request",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"rawRequestBody",
")",
")",
"\n",
"if",
"skipAuthenticationHeader",
"(",
"request",
",",
"rawRequestBody",
")",
"{",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"Authorization\"",
",",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
")",
"\n",
"err",
"=",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"uaa",
".",
"InvalidAuthTokenError",
")",
";",
"ok",
"{",
"tokens",
",",
"refreshErr",
":=",
"t",
".",
"client",
".",
"RefreshAccessToken",
"(",
"t",
".",
"cache",
".",
"RefreshToken",
"(",
")",
")",
"\n",
"if",
"refreshErr",
"!=",
"nil",
"{",
"return",
"refreshErr",
"\n",
"}",
"\n",
"t",
".",
"cache",
".",
"SetAccessToken",
"(",
"tokens",
".",
"AuthorizationToken",
"(",
")",
")",
"\n",
"t",
".",
"cache",
".",
"SetRefreshToken",
"(",
"tokens",
".",
"RefreshToken",
")",
"\n",
"if",
"rawRequestBody",
"!=",
"nil",
"{",
"request",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"rawRequestBody",
")",
")",
"\n",
"}",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"Authorization\"",
",",
"t",
".",
"cache",
".",
"AccessToken",
"(",
")",
")",
"\n",
"return",
"t",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Make adds authentication headers to the passed in request and then calls the
// wrapped connection's Make | [
"Make",
"adds",
"authentication",
"headers",
"to",
"the",
"passed",
"in",
"request",
"and",
"then",
"calls",
"the",
"wrapped",
"connection",
"s",
"Make"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/uaa_authentication.go#L48-L90 | train |
cloudfoundry/cli | api/uaa/wrapper/uaa_authentication.go | skipAuthenticationHeader | func skipAuthenticationHeader(request *http.Request, body []byte) bool {
stringBody := string(body)
return strings.Contains(request.URL.String(), "/oauth/token") &&
request.Method == http.MethodPost &&
(strings.Contains(stringBody, "grant_type=refresh_token") ||
strings.Contains(stringBody, "grant_type=password") ||
strings.Contains(stringBody, "grant_type=client_credentials"))
} | go | func skipAuthenticationHeader(request *http.Request, body []byte) bool {
stringBody := string(body)
return strings.Contains(request.URL.String(), "/oauth/token") &&
request.Method == http.MethodPost &&
(strings.Contains(stringBody, "grant_type=refresh_token") ||
strings.Contains(stringBody, "grant_type=password") ||
strings.Contains(stringBody, "grant_type=client_credentials"))
} | [
"func",
"skipAuthenticationHeader",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"body",
"[",
"]",
"byte",
")",
"bool",
"{",
"stringBody",
":=",
"string",
"(",
"body",
")",
"\n",
"return",
"strings",
".",
"Contains",
"(",
"request",
".",
"URL",
".",
"String",
"(",
")",
",",
"\"/oauth/token\"",
")",
"&&",
"request",
".",
"Method",
"==",
"http",
".",
"MethodPost",
"&&",
"(",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"grant_type=refresh_token\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"grant_type=password\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"stringBody",
",",
"\"grant_type=client_credentials\"",
")",
")",
"\n",
"}"
] | // The authentication header is not added to token refresh requests or login
// requests. | [
"The",
"authentication",
"header",
"is",
"not",
"added",
"to",
"token",
"refresh",
"requests",
"or",
"login",
"requests",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/uaa_authentication.go#L105-L113 | train |
cloudfoundry/cli | api/plugin/plugin_connection.go | NewConnection | func NewConnection(skipSSLValidation bool, dialTimeout time.Duration) *PluginConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: dialTimeout,
}).DialContext,
}
return &PluginConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | go | func NewConnection(skipSSLValidation bool, dialTimeout time.Duration) *PluginConnection {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipSSLValidation,
},
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: dialTimeout,
}).DialContext,
}
return &PluginConnection{
HTTPClient: &http.Client{Transport: tr},
}
} | [
"func",
"NewConnection",
"(",
"skipSSLValidation",
"bool",
",",
"dialTimeout",
"time",
".",
"Duration",
")",
"*",
"PluginConnection",
"{",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"skipSSLValidation",
",",
"}",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"DialContext",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"dialTimeout",
",",
"}",
")",
".",
"DialContext",
",",
"}",
"\n",
"return",
"&",
"PluginConnection",
"{",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
"}",
",",
"}",
"\n",
"}"
] | // NewConnection returns a new PluginConnection | [
"NewConnection",
"returns",
"a",
"new",
"PluginConnection"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/plugin/plugin_connection.go#L25-L40 | train |
cloudfoundry/cli | actor/v2action/service.go | GetService | func (actor Actor) GetService(serviceGUID string) (Service, Warnings, error) {
service, warnings, err := actor.CloudControllerClient.GetService(serviceGUID)
return Service(service), Warnings(warnings), err
} | go | func (actor Actor) GetService(serviceGUID string) (Service, Warnings, error) {
service, warnings, err := actor.CloudControllerClient.GetService(serviceGUID)
return Service(service), Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetService",
"(",
"serviceGUID",
"string",
")",
"(",
"Service",
",",
"Warnings",
",",
"error",
")",
"{",
"service",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetService",
"(",
"serviceGUID",
")",
"\n",
"return",
"Service",
"(",
"service",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetService fetches a service by GUID. | [
"GetService",
"fetches",
"a",
"service",
"by",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L19-L22 | train |
cloudfoundry/cli | actor/v2action/service.go | GetServicesWithPlans | func (actor Actor) GetServicesWithPlans(filters ...Filter) (ServicesWithPlans, Warnings, error) {
ccv2Filters := []ccv2.Filter{}
for _, f := range filters {
ccv2Filters = append(ccv2Filters, ccv2.Filter(f))
}
var allWarnings Warnings
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2Filters...)
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
servicesWithPlans := ServicesWithPlans{}
for _, service := range services {
servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
Type: constant.ServiceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{service.GUID},
})
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
plansToReturn := []ServicePlan{}
for _, plan := range servicePlans {
plansToReturn = append(plansToReturn, ServicePlan(plan))
}
servicesWithPlans[Service(service)] = plansToReturn
}
return servicesWithPlans, allWarnings, nil
} | go | func (actor Actor) GetServicesWithPlans(filters ...Filter) (ServicesWithPlans, Warnings, error) {
ccv2Filters := []ccv2.Filter{}
for _, f := range filters {
ccv2Filters = append(ccv2Filters, ccv2.Filter(f))
}
var allWarnings Warnings
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2Filters...)
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
servicesWithPlans := ServicesWithPlans{}
for _, service := range services {
servicePlans, warnings, err := actor.CloudControllerClient.GetServicePlans(ccv2.Filter{
Type: constant.ServiceGUIDFilter,
Operator: constant.EqualOperator,
Values: []string{service.GUID},
})
allWarnings = append(allWarnings, Warnings(warnings)...)
if err != nil {
return nil, allWarnings, err
}
plansToReturn := []ServicePlan{}
for _, plan := range servicePlans {
plansToReturn = append(plansToReturn, ServicePlan(plan))
}
servicesWithPlans[Service(service)] = plansToReturn
}
return servicesWithPlans, allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetServicesWithPlans",
"(",
"filters",
"...",
"Filter",
")",
"(",
"ServicesWithPlans",
",",
"Warnings",
",",
"error",
")",
"{",
"ccv2Filters",
":=",
"[",
"]",
"ccv2",
".",
"Filter",
"{",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"filters",
"{",
"ccv2Filters",
"=",
"append",
"(",
"ccv2Filters",
",",
"ccv2",
".",
"Filter",
"(",
"f",
")",
")",
"\n",
"}",
"\n",
"var",
"allWarnings",
"Warnings",
"\n",
"services",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServices",
"(",
"ccv2Filters",
"...",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"Warnings",
"(",
"warnings",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"servicesWithPlans",
":=",
"ServicesWithPlans",
"{",
"}",
"\n",
"for",
"_",
",",
"service",
":=",
"range",
"services",
"{",
"servicePlans",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServicePlans",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"ServiceGUIDFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"service",
".",
"GUID",
"}",
",",
"}",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"Warnings",
"(",
"warnings",
")",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"plansToReturn",
":=",
"[",
"]",
"ServicePlan",
"{",
"}",
"\n",
"for",
"_",
",",
"plan",
":=",
"range",
"servicePlans",
"{",
"plansToReturn",
"=",
"append",
"(",
"plansToReturn",
",",
"ServicePlan",
"(",
"plan",
")",
")",
"\n",
"}",
"\n",
"servicesWithPlans",
"[",
"Service",
"(",
"service",
")",
"]",
"=",
"plansToReturn",
"\n",
"}",
"\n",
"return",
"servicesWithPlans",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // GetServicesWithPlans returns a map of Services to ServicePlans for a particular broker.
// A particular service with associated plans from a broker can be fetched by additionally providing
// a service label filter. | [
"GetServicesWithPlans",
"returns",
"a",
"map",
"of",
"Services",
"to",
"ServicePlans",
"for",
"a",
"particular",
"broker",
".",
"A",
"particular",
"service",
"with",
"associated",
"plans",
"from",
"a",
"broker",
"can",
"be",
"fetched",
"by",
"additionally",
"providing",
"a",
"service",
"label",
"filter",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L93-L128 | train |
cloudfoundry/cli | actor/v2action/service.go | ServiceExistsWithName | func (actor Actor) ServiceExistsWithName(serviceName string) (bool, Warnings, error) {
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
Type: constant.LabelFilter,
Operator: constant.EqualOperator,
Values: []string{serviceName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(services) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | go | func (actor Actor) ServiceExistsWithName(serviceName string) (bool, Warnings, error) {
services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
Type: constant.LabelFilter,
Operator: constant.EqualOperator,
Values: []string{serviceName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(services) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"ServiceExistsWithName",
"(",
"serviceName",
"string",
")",
"(",
"bool",
",",
"Warnings",
",",
"error",
")",
"{",
"services",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetServices",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"LabelFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"serviceName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"services",
")",
"==",
"0",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // ServiceExistsWithName returns true if there is an Organization with the
// provided name, otherwise false. | [
"ServiceExistsWithName",
"returns",
"true",
"if",
"there",
"is",
"an",
"Organization",
"with",
"the",
"provided",
"name",
"otherwise",
"false",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/service.go#L132-L147 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/organization.go | GetIsolationSegmentOrganizations | func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentOrganizationsRequest,
URIParams: map[string]string{"isolation_segment_guid": isolationSegmentGUID},
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | go | func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetIsolationSegmentOrganizationsRequest,
URIParams: map[string]string{"isolation_segment_guid": isolationSegmentGUID},
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetIsolationSegmentOrganizations",
"(",
"isolationSegmentGUID",
"string",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetIsolationSegmentOrganizationsRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"isolation_segment_guid\"",
":",
"isolationSegmentGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullOrgsList",
"[",
"]",
"Organization",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Organization",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"app",
",",
"ok",
":=",
"item",
".",
"(",
"Organization",
")",
";",
"ok",
"{",
"fullOrgsList",
"=",
"append",
"(",
"fullOrgsList",
",",
"app",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Organization",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullOrgsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetIsolationSegmentOrganizations lists organizations
// entitled to an isolation segment. | [
"GetIsolationSegmentOrganizations",
"lists",
"organizations",
"entitled",
"to",
"an",
"isolation",
"segment",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/organization.go#L25-L48 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/organization.go | GetOrganizations | func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | go | func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullOrgsList []Organization
warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
if app, ok := item.(Organization); ok {
fullOrgsList = append(fullOrgsList, app)
} else {
return ccerror.UnknownObjectInListError{
Expected: Organization{},
Unexpected: item,
}
}
return nil
})
return fullOrgsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetOrganizations",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetOrganizationsRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullOrgsList",
"[",
"]",
"Organization",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Organization",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"app",
",",
"ok",
":=",
"item",
".",
"(",
"Organization",
")",
";",
"ok",
"{",
"fullOrgsList",
"=",
"append",
"(",
"fullOrgsList",
",",
"app",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Organization",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullOrgsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetOrganizations lists organizations with optional filters. | [
"GetOrganizations",
"lists",
"organizations",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/organization.go#L51-L74 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetApplicationDropletCurrent | func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationDropletCurrentRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | go | func (client *Client) GetApplicationDropletCurrent(appGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetApplicationDropletCurrentRequest,
URIParams: map[string]string{"app_guid": appGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetApplicationDropletCurrent",
"(",
"appGUID",
"string",
")",
"(",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetApplicationDropletCurrentRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"app_guid\"",
":",
"appGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Droplet",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"responseDroplet",
"Droplet",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responseDroplet",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"responseDroplet",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetApplicationDropletCurrent returns the current droplet for a given
// application. | [
"GetApplicationDropletCurrent",
"returns",
"the",
"current",
"droplet",
"for",
"a",
"given",
"application",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L38-L53 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetDroplet | func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletRequest,
URIParams: map[string]string{"droplet_guid": dropletGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | go | func (client *Client) GetDroplet(dropletGUID string) (Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletRequest,
URIParams: map[string]string{"droplet_guid": dropletGUID},
})
if err != nil {
return Droplet{}, nil, err
}
var responseDroplet Droplet
response := cloudcontroller.Response{
DecodeJSONResponseInto: &responseDroplet,
}
err = client.connection.Make(request, &response)
return responseDroplet, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetDroplet",
"(",
"dropletGUID",
"string",
")",
"(",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetDropletRequest",
",",
"URIParams",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"droplet_guid\"",
":",
"dropletGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Droplet",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"responseDroplet",
"Droplet",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"responseDroplet",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"responseDroplet",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetDroplet returns a droplet with the given GUID. | [
"GetDroplet",
"returns",
"a",
"droplet",
"with",
"the",
"given",
"GUID",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L56-L72 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/droplet.go | GetDroplets | func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var responseDroplets []Droplet
warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
if droplet, ok := item.(Droplet); ok {
responseDroplets = append(responseDroplets, droplet)
} else {
return ccerror.UnknownObjectInListError{
Expected: Droplet{},
Unexpected: item,
}
}
return nil
})
return responseDroplets, warnings, err
} | go | func (client *Client) GetDroplets(query ...Query) ([]Droplet, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetDropletsRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var responseDroplets []Droplet
warnings, err := client.paginate(request, Droplet{}, func(item interface{}) error {
if droplet, ok := item.(Droplet); ok {
responseDroplets = append(responseDroplets, droplet)
} else {
return ccerror.UnknownObjectInListError{
Expected: Droplet{},
Unexpected: item,
}
}
return nil
})
return responseDroplets, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetDroplets",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"Droplet",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetDropletsRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"responseDroplets",
"[",
"]",
"Droplet",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"Droplet",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"droplet",
",",
"ok",
":=",
"item",
".",
"(",
"Droplet",
")",
";",
"ok",
"{",
"responseDroplets",
"=",
"append",
"(",
"responseDroplets",
",",
"droplet",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"Droplet",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"responseDroplets",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetDroplets lists droplets with optional filters. | [
"GetDroplets",
"lists",
"droplets",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/droplet.go#L75-L98 | train |
cloudfoundry/cli | types/null_int.go | IsValidValue | func (n *NullInt) IsValidValue(val string) error {
_, err := strconv.Atoi(val)
return err
} | go | func (n *NullInt) IsValidValue(val string) error {
_, err := strconv.Atoi(val)
return err
} | [
"func",
"(",
"n",
"*",
"NullInt",
")",
"IsValidValue",
"(",
"val",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // IsValidValue returns an error if the input value is not an integer. | [
"IsValidValue",
"returns",
"an",
"error",
"if",
"the",
"input",
"value",
"is",
"not",
"an",
"integer",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/types/null_int.go#L34-L37 | train |
cloudfoundry/cli | api/cloudcontroller/ccv3/service_instance.go | GetServiceInstances | func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstancesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullServiceInstanceList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if serviceInstance, ok := item.(ServiceInstance); ok {
fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullServiceInstanceList, warnings, err
} | go | func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstancesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullServiceInstanceList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if serviceInstance, ok := item.(ServiceInstance); ok {
fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullServiceInstanceList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServiceInstances",
"(",
"query",
"...",
"Query",
")",
"(",
"[",
"]",
"ServiceInstance",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServiceInstancesRequest",
",",
"Query",
":",
"query",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullServiceInstanceList",
"[",
"]",
"ServiceInstance",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"ServiceInstance",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"serviceInstance",
",",
"ok",
":=",
"item",
".",
"(",
"ServiceInstance",
")",
";",
"ok",
"{",
"fullServiceInstanceList",
"=",
"append",
"(",
"fullServiceInstanceList",
",",
"serviceInstance",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"ServiceInstance",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullServiceInstanceList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetServiceInstances lists service instances with optional filters. | [
"GetServiceInstances",
"lists",
"service",
"instances",
"with",
"optional",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv3/service_instance.go#L17-L40 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | UnmarshalJSON | func (routeMapping *RouteMapping) UnmarshalJSON(data []byte) error {
var ccRouteMapping struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
AppGUID string `json:"app_guid"`
RouteGUID string `json:"route_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccRouteMapping)
if err != nil {
return err
}
routeMapping.GUID = ccRouteMapping.Metadata.GUID
routeMapping.AppGUID = ccRouteMapping.Entity.AppGUID
routeMapping.RouteGUID = ccRouteMapping.Entity.RouteGUID
return nil
} | go | func (routeMapping *RouteMapping) UnmarshalJSON(data []byte) error {
var ccRouteMapping struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
AppGUID string `json:"app_guid"`
RouteGUID string `json:"route_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccRouteMapping)
if err != nil {
return err
}
routeMapping.GUID = ccRouteMapping.Metadata.GUID
routeMapping.AppGUID = ccRouteMapping.Entity.AppGUID
routeMapping.RouteGUID = ccRouteMapping.Entity.RouteGUID
return nil
} | [
"func",
"(",
"routeMapping",
"*",
"RouteMapping",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccRouteMapping",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"AppGUID",
"string",
"`json:\"app_guid\"`",
"\n",
"RouteGUID",
"string",
"`json:\"route_guid\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccRouteMapping",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"routeMapping",
".",
"GUID",
"=",
"ccRouteMapping",
".",
"Metadata",
".",
"GUID",
"\n",
"routeMapping",
".",
"AppGUID",
"=",
"ccRouteMapping",
".",
"Entity",
".",
"AppGUID",
"\n",
"routeMapping",
".",
"RouteGUID",
"=",
"ccRouteMapping",
".",
"Entity",
".",
"RouteGUID",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Route Mapping | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Route",
"Mapping"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L22-L40 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | GetRouteMapping | func (client *Client) GetRouteMapping(guid string) (RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingRequest,
URIParams: Params{"route_mapping_guid": guid},
})
if err != nil {
return RouteMapping{}, nil, err
}
var routeMapping RouteMapping
response := cloudcontroller.Response{
DecodeJSONResponseInto: &routeMapping,
}
err = client.connection.Make(request, &response)
return routeMapping, response.Warnings, err
} | go | func (client *Client) GetRouteMapping(guid string) (RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingRequest,
URIParams: Params{"route_mapping_guid": guid},
})
if err != nil {
return RouteMapping{}, nil, err
}
var routeMapping RouteMapping
response := cloudcontroller.Response{
DecodeJSONResponseInto: &routeMapping,
}
err = client.connection.Make(request, &response)
return routeMapping, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetRouteMapping",
"(",
"guid",
"string",
")",
"(",
"RouteMapping",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetRouteMappingRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"route_mapping_guid\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RouteMapping",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"routeMapping",
"RouteMapping",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"routeMapping",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"routeMapping",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetRouteMapping returns a route mapping with the provided guid. | [
"GetRouteMapping",
"returns",
"a",
"route",
"mapping",
"with",
"the",
"provided",
"guid",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L43-L59 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/route_mapping.go | GetRouteMappings | func (client *Client) GetRouteMappings(filters ...Filter) ([]RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingsRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRouteMappingsList []RouteMapping
warnings, err := client.paginate(request, RouteMapping{}, func(item interface{}) error {
if routeMapping, ok := item.(RouteMapping); ok {
fullRouteMappingsList = append(fullRouteMappingsList, routeMapping)
} else {
return ccerror.UnknownObjectInListError{
Expected: RouteMapping{},
Unexpected: item,
}
}
return nil
})
return fullRouteMappingsList, warnings, err
} | go | func (client *Client) GetRouteMappings(filters ...Filter) ([]RouteMapping, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetRouteMappingsRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullRouteMappingsList []RouteMapping
warnings, err := client.paginate(request, RouteMapping{}, func(item interface{}) error {
if routeMapping, ok := item.(RouteMapping); ok {
fullRouteMappingsList = append(fullRouteMappingsList, routeMapping)
} else {
return ccerror.UnknownObjectInListError{
Expected: RouteMapping{},
Unexpected: item,
}
}
return nil
})
return fullRouteMappingsList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetRouteMappings",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"RouteMapping",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetRouteMappingsRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullRouteMappingsList",
"[",
"]",
"RouteMapping",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"RouteMapping",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"routeMapping",
",",
"ok",
":=",
"item",
".",
"(",
"RouteMapping",
")",
";",
"ok",
"{",
"fullRouteMappingsList",
"=",
"append",
"(",
"fullRouteMappingsList",
",",
"routeMapping",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"RouteMapping",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullRouteMappingsList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetRouteMappings returns a list of RouteMappings based off of the provided queries. | [
"GetRouteMappings",
"returns",
"a",
"list",
"of",
"RouteMappings",
"based",
"off",
"of",
"the",
"provided",
"queries",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/route_mapping.go#L62-L85 | train |
cloudfoundry/cli | api/uaa/refresh_token.go | AuthorizationToken | func (refreshTokenResponse RefreshedTokens) AuthorizationToken() string {
return fmt.Sprintf("%s %s", refreshTokenResponse.Type, refreshTokenResponse.AccessToken)
} | go | func (refreshTokenResponse RefreshedTokens) AuthorizationToken() string {
return fmt.Sprintf("%s %s", refreshTokenResponse.Type, refreshTokenResponse.AccessToken)
} | [
"func",
"(",
"refreshTokenResponse",
"RefreshedTokens",
")",
"AuthorizationToken",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s %s\"",
",",
"refreshTokenResponse",
".",
"Type",
",",
"refreshTokenResponse",
".",
"AccessToken",
")",
"\n",
"}"
] | // AuthorizationToken returns formatted authorization header. | [
"AuthorizationToken",
"returns",
"formatted",
"authorization",
"header",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/refresh_token.go#L21-L23 | train |
cloudfoundry/cli | api/uaa/refresh_token.go | RefreshAccessToken | func (client *Client) RefreshAccessToken(refreshToken string) (RefreshedTokens, error) {
var values url.Values
switch client.config.UAAGrantType() {
case string(constant.GrantTypeClientCredentials):
values = client.clientCredentialRefreshBody()
case "", string(constant.GrantTypePassword): // CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files
values = client.refreshTokenBody(refreshToken)
}
body := strings.NewReader(values.Encode())
request, err := client.newRequest(requestOptions{
RequestName: internal.PostOAuthTokenRequest,
Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
Body: body,
})
if err != nil {
return RefreshedTokens{}, err
}
if client.config.UAAGrantType() != string(constant.GrantTypeClientCredentials) {
request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
}
var refreshResponse RefreshedTokens
response := Response{
Result: &refreshResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return RefreshedTokens{}, err
}
return refreshResponse, nil
} | go | func (client *Client) RefreshAccessToken(refreshToken string) (RefreshedTokens, error) {
var values url.Values
switch client.config.UAAGrantType() {
case string(constant.GrantTypeClientCredentials):
values = client.clientCredentialRefreshBody()
case "", string(constant.GrantTypePassword): // CLI used to write empty string for grant type in the case of password; preserve compatibility with old config.json files
values = client.refreshTokenBody(refreshToken)
}
body := strings.NewReader(values.Encode())
request, err := client.newRequest(requestOptions{
RequestName: internal.PostOAuthTokenRequest,
Header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
Body: body,
})
if err != nil {
return RefreshedTokens{}, err
}
if client.config.UAAGrantType() != string(constant.GrantTypeClientCredentials) {
request.SetBasicAuth(client.config.UAAOAuthClient(), client.config.UAAOAuthClientSecret())
}
var refreshResponse RefreshedTokens
response := Response{
Result: &refreshResponse,
}
err = client.connection.Make(request, &response)
if err != nil {
return RefreshedTokens{}, err
}
return refreshResponse, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"RefreshAccessToken",
"(",
"refreshToken",
"string",
")",
"(",
"RefreshedTokens",
",",
"error",
")",
"{",
"var",
"values",
"url",
".",
"Values",
"\n",
"switch",
"client",
".",
"config",
".",
"UAAGrantType",
"(",
")",
"{",
"case",
"string",
"(",
"constant",
".",
"GrantTypeClientCredentials",
")",
":",
"values",
"=",
"client",
".",
"clientCredentialRefreshBody",
"(",
")",
"\n",
"case",
"\"\"",
",",
"string",
"(",
"constant",
".",
"GrantTypePassword",
")",
":",
"values",
"=",
"client",
".",
"refreshTokenBody",
"(",
"refreshToken",
")",
"\n",
"}",
"\n",
"body",
":=",
"strings",
".",
"NewReader",
"(",
"values",
".",
"Encode",
"(",
")",
")",
"\n",
"request",
",",
"err",
":=",
"client",
".",
"newRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PostOAuthTokenRequest",
",",
"Header",
":",
"http",
".",
"Header",
"{",
"\"Content-Type\"",
":",
"{",
"\"application/x-www-form-urlencoded\"",
"}",
"}",
",",
"Body",
":",
"body",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RefreshedTokens",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"client",
".",
"config",
".",
"UAAGrantType",
"(",
")",
"!=",
"string",
"(",
"constant",
".",
"GrantTypeClientCredentials",
")",
"{",
"request",
".",
"SetBasicAuth",
"(",
"client",
".",
"config",
".",
"UAAOAuthClient",
"(",
")",
",",
"client",
".",
"config",
".",
"UAAOAuthClientSecret",
"(",
")",
")",
"\n",
"}",
"\n",
"var",
"refreshResponse",
"RefreshedTokens",
"\n",
"response",
":=",
"Response",
"{",
"Result",
":",
"&",
"refreshResponse",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RefreshedTokens",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"refreshResponse",
",",
"nil",
"\n",
"}"
] | // RefreshAccessToken refreshes the current access token. | [
"RefreshAccessToken",
"refreshes",
"the",
"current",
"access",
"token",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/refresh_token.go#L26-L62 | train |
cloudfoundry/cli | util/ui/table.go | DisplayKeyValueTable | func (ui *UI) DisplayKeyValueTable(prefix string, table [][]string, padding int) {
rows := len(table)
if rows == 0 {
return
}
var displayTable [][]string
for _, row := range table {
if len(row) > 0 {
displayTable = append(displayTable, row)
}
}
columns := len(displayTable[0])
if columns < 2 || !ui.IsTTY {
ui.DisplayNonWrappingTable(prefix, displayTable, padding)
return
}
ui.displayWrappingTableWithWidth(prefix, displayTable, padding)
} | go | func (ui *UI) DisplayKeyValueTable(prefix string, table [][]string, padding int) {
rows := len(table)
if rows == 0 {
return
}
var displayTable [][]string
for _, row := range table {
if len(row) > 0 {
displayTable = append(displayTable, row)
}
}
columns := len(displayTable[0])
if columns < 2 || !ui.IsTTY {
ui.DisplayNonWrappingTable(prefix, displayTable, padding)
return
}
ui.displayWrappingTableWithWidth(prefix, displayTable, padding)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayKeyValueTable",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"rows",
":=",
"len",
"(",
"table",
")",
"\n",
"if",
"rows",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"var",
"displayTable",
"[",
"]",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"table",
"{",
"if",
"len",
"(",
"row",
")",
">",
"0",
"{",
"displayTable",
"=",
"append",
"(",
"displayTable",
",",
"row",
")",
"\n",
"}",
"\n",
"}",
"\n",
"columns",
":=",
"len",
"(",
"displayTable",
"[",
"0",
"]",
")",
"\n",
"if",
"columns",
"<",
"2",
"||",
"!",
"ui",
".",
"IsTTY",
"{",
"ui",
".",
"DisplayNonWrappingTable",
"(",
"prefix",
",",
"displayTable",
",",
"padding",
")",
"\n",
"return",
"\n",
"}",
"\n",
"ui",
".",
"displayWrappingTableWithWidth",
"(",
"prefix",
",",
"displayTable",
",",
"padding",
")",
"\n",
"}"
] | // DisplayKeyValueTable outputs a matrix of strings as a table to UI.Out.
// Prefix will be prepended to each row and padding adds the specified number
// of spaces between columns. The final columns may wrap to multiple lines but
// will still be confined to the last column. Wrapping will occur on word
// boundaries. | [
"DisplayKeyValueTable",
"outputs",
"a",
"matrix",
"of",
"strings",
"as",
"a",
"table",
"to",
"UI",
".",
"Out",
".",
"Prefix",
"will",
"be",
"prepended",
"to",
"each",
"row",
"and",
"padding",
"adds",
"the",
"specified",
"number",
"of",
"spaces",
"between",
"columns",
".",
"The",
"final",
"columns",
"may",
"wrap",
"to",
"multiple",
"lines",
"but",
"will",
"still",
"be",
"confined",
"to",
"the",
"last",
"column",
".",
"Wrapping",
"will",
"occur",
"on",
"word",
"boundaries",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L20-L40 | train |
cloudfoundry/cli | util/ui/table.go | DisplayNonWrappingTable | func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int) {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
if len(table) == 0 {
return
}
var columnPadding []int
rows := len(table)
columns := len(table[0])
for col := 0; col < columns; col++ {
var max int
for row := 0; row < rows; row++ {
if strLen := wordSize(table[row][col]); max < strLen {
max = strLen
}
}
columnPadding = append(columnPadding, max+padding)
}
for row := 0; row < rows; row++ {
fmt.Fprint(ui.Out, prefix)
for col := 0; col < columns; col++ {
data := table[row][col]
var addedPadding int
if col+1 != columns {
addedPadding = columnPadding[col] - wordSize(data)
}
fmt.Fprintf(ui.Out, "%s%s", data, strings.Repeat(" ", addedPadding))
}
fmt.Fprintf(ui.Out, "\n")
}
} | go | func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int) {
ui.terminalLock.Lock()
defer ui.terminalLock.Unlock()
if len(table) == 0 {
return
}
var columnPadding []int
rows := len(table)
columns := len(table[0])
for col := 0; col < columns; col++ {
var max int
for row := 0; row < rows; row++ {
if strLen := wordSize(table[row][col]); max < strLen {
max = strLen
}
}
columnPadding = append(columnPadding, max+padding)
}
for row := 0; row < rows; row++ {
fmt.Fprint(ui.Out, prefix)
for col := 0; col < columns; col++ {
data := table[row][col]
var addedPadding int
if col+1 != columns {
addedPadding = columnPadding[col] - wordSize(data)
}
fmt.Fprintf(ui.Out, "%s%s", data, strings.Repeat(" ", addedPadding))
}
fmt.Fprintf(ui.Out, "\n")
}
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayNonWrappingTable",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"ui",
".",
"terminalLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ui",
".",
"terminalLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"len",
"(",
"table",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"var",
"columnPadding",
"[",
"]",
"int",
"\n",
"rows",
":=",
"len",
"(",
"table",
")",
"\n",
"columns",
":=",
"len",
"(",
"table",
"[",
"0",
"]",
")",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"columns",
";",
"col",
"++",
"{",
"var",
"max",
"int",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"if",
"strLen",
":=",
"wordSize",
"(",
"table",
"[",
"row",
"]",
"[",
"col",
"]",
")",
";",
"max",
"<",
"strLen",
"{",
"max",
"=",
"strLen",
"\n",
"}",
"\n",
"}",
"\n",
"columnPadding",
"=",
"append",
"(",
"columnPadding",
",",
"max",
"+",
"padding",
")",
"\n",
"}",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"fmt",
".",
"Fprint",
"(",
"ui",
".",
"Out",
",",
"prefix",
")",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"columns",
";",
"col",
"++",
"{",
"data",
":=",
"table",
"[",
"row",
"]",
"[",
"col",
"]",
"\n",
"var",
"addedPadding",
"int",
"\n",
"if",
"col",
"+",
"1",
"!=",
"columns",
"{",
"addedPadding",
"=",
"columnPadding",
"[",
"col",
"]",
"-",
"wordSize",
"(",
"data",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"ui",
".",
"Out",
",",
"\"%s%s\"",
",",
"data",
",",
"strings",
".",
"Repeat",
"(",
"\" \"",
",",
"addedPadding",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"ui",
".",
"Out",
",",
"\"\\n\"",
")",
"\n",
"}",
"\n",
"}"
] | // DisplayNonWrappingTable outputs a matrix of strings as a table to UI.Out.
// Prefix will be prepended to each row and padding adds the specified number
// of spaces between columns. | [
"DisplayNonWrappingTable",
"outputs",
"a",
"matrix",
"of",
"strings",
"as",
"a",
"table",
"to",
"UI",
".",
"Out",
".",
"Prefix",
"will",
"be",
"prepended",
"to",
"each",
"row",
"and",
"padding",
"adds",
"the",
"specified",
"number",
"of",
"spaces",
"between",
"columns",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L45-L79 | train |
cloudfoundry/cli | util/ui/table.go | DisplayTableWithHeader | func (ui *UI) DisplayTableWithHeader(prefix string, table [][]string, padding int) {
if len(table) == 0 {
return
}
for i, str := range table[0] {
table[0][i] = ui.modifyColor(str, color.New(color.Bold))
}
ui.DisplayNonWrappingTable(prefix, table, padding)
} | go | func (ui *UI) DisplayTableWithHeader(prefix string, table [][]string, padding int) {
if len(table) == 0 {
return
}
for i, str := range table[0] {
table[0][i] = ui.modifyColor(str, color.New(color.Bold))
}
ui.DisplayNonWrappingTable(prefix, table, padding)
} | [
"func",
"(",
"ui",
"*",
"UI",
")",
"DisplayTableWithHeader",
"(",
"prefix",
"string",
",",
"table",
"[",
"]",
"[",
"]",
"string",
",",
"padding",
"int",
")",
"{",
"if",
"len",
"(",
"table",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"for",
"i",
",",
"str",
":=",
"range",
"table",
"[",
"0",
"]",
"{",
"table",
"[",
"0",
"]",
"[",
"i",
"]",
"=",
"ui",
".",
"modifyColor",
"(",
"str",
",",
"color",
".",
"New",
"(",
"color",
".",
"Bold",
")",
")",
"\n",
"}",
"\n",
"ui",
".",
"DisplayNonWrappingTable",
"(",
"prefix",
",",
"table",
",",
"padding",
")",
"\n",
"}"
] | // DisplayTableWithHeader outputs a simple non-wrapping table with bolded
// headers. | [
"DisplayTableWithHeader",
"outputs",
"a",
"simple",
"non",
"-",
"wrapping",
"table",
"with",
"bolded",
"headers",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/util/ui/table.go#L83-L92 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/application_instance.go | GetApplicationApplicationInstances | func (client *Client) GetApplicationApplicationInstances(guid string) (map[int]ApplicationInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetAppInstancesRequest,
URIParams: Params{"app_guid": guid},
})
if err != nil {
return nil, nil, err
}
var instances map[string]ApplicationInstance
response := cloudcontroller.Response{
DecodeJSONResponseInto: &instances,
}
err = client.connection.Make(request, &response)
if err != nil {
return nil, response.Warnings, err
}
returnedInstances := map[int]ApplicationInstance{}
for instanceID, instance := range instances {
id, convertErr := strconv.Atoi(instanceID)
if convertErr != nil {
return nil, response.Warnings, convertErr
}
instance.ID = id
returnedInstances[id] = instance
}
return returnedInstances, response.Warnings, nil
} | go | func (client *Client) GetApplicationApplicationInstances(guid string) (map[int]ApplicationInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetAppInstancesRequest,
URIParams: Params{"app_guid": guid},
})
if err != nil {
return nil, nil, err
}
var instances map[string]ApplicationInstance
response := cloudcontroller.Response{
DecodeJSONResponseInto: &instances,
}
err = client.connection.Make(request, &response)
if err != nil {
return nil, response.Warnings, err
}
returnedInstances := map[int]ApplicationInstance{}
for instanceID, instance := range instances {
id, convertErr := strconv.Atoi(instanceID)
if convertErr != nil {
return nil, response.Warnings, convertErr
}
instance.ID = id
returnedInstances[id] = instance
}
return returnedInstances, response.Warnings, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetApplicationApplicationInstances",
"(",
"guid",
"string",
")",
"(",
"map",
"[",
"int",
"]",
"ApplicationInstance",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetAppInstancesRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"app_guid\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"instances",
"map",
"[",
"string",
"]",
"ApplicationInstance",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"instances",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}",
"\n",
"returnedInstances",
":=",
"map",
"[",
"int",
"]",
"ApplicationInstance",
"{",
"}",
"\n",
"for",
"instanceID",
",",
"instance",
":=",
"range",
"instances",
"{",
"id",
",",
"convertErr",
":=",
"strconv",
".",
"Atoi",
"(",
"instanceID",
")",
"\n",
"if",
"convertErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"Warnings",
",",
"convertErr",
"\n",
"}",
"\n",
"instance",
".",
"ID",
"=",
"id",
"\n",
"returnedInstances",
"[",
"id",
"]",
"=",
"instance",
"\n",
"}",
"\n",
"return",
"returnedInstances",
",",
"response",
".",
"Warnings",
",",
"nil",
"\n",
"}"
] | // GetApplicationApplicationInstances returns a list of ApplicationInstance for
// a given application. Depending on the state of an application, it might skip
// some application instances. | [
"GetApplicationApplicationInstances",
"returns",
"a",
"list",
"of",
"ApplicationInstance",
"for",
"a",
"given",
"application",
".",
"Depending",
"on",
"the",
"state",
"of",
"an",
"application",
"it",
"might",
"skip",
"some",
"application",
"instances",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/application_instance.go#L50-L80 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_plan_visibility.go | UnmarshalJSON | func (servicePlanVisibility *ServicePlanVisibility) UnmarshalJSON(data []byte) error {
var ccServicePlanVisibility struct {
Metadata internal.Metadata
Entity struct {
ServicePlanGUID string `json:"service_plan_guid"`
OrganizationGUID string `json:"organization_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServicePlanVisibility)
if err != nil {
return err
}
servicePlanVisibility.GUID = ccServicePlanVisibility.Metadata.GUID
servicePlanVisibility.ServicePlanGUID = ccServicePlanVisibility.Entity.ServicePlanGUID
servicePlanVisibility.OrganizationGUID = ccServicePlanVisibility.Entity.OrganizationGUID
return nil
} | go | func (servicePlanVisibility *ServicePlanVisibility) UnmarshalJSON(data []byte) error {
var ccServicePlanVisibility struct {
Metadata internal.Metadata
Entity struct {
ServicePlanGUID string `json:"service_plan_guid"`
OrganizationGUID string `json:"organization_guid"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccServicePlanVisibility)
if err != nil {
return err
}
servicePlanVisibility.GUID = ccServicePlanVisibility.Metadata.GUID
servicePlanVisibility.ServicePlanGUID = ccServicePlanVisibility.Entity.ServicePlanGUID
servicePlanVisibility.OrganizationGUID = ccServicePlanVisibility.Entity.OrganizationGUID
return nil
} | [
"func",
"(",
"servicePlanVisibility",
"*",
"ServicePlanVisibility",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccServicePlanVisibility",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"\n",
"Entity",
"struct",
"{",
"ServicePlanGUID",
"string",
"`json:\"service_plan_guid\"`",
"\n",
"OrganizationGUID",
"string",
"`json:\"organization_guid\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccServicePlanVisibility",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"servicePlanVisibility",
".",
"GUID",
"=",
"ccServicePlanVisibility",
".",
"Metadata",
".",
"GUID",
"\n",
"servicePlanVisibility",
".",
"ServicePlanGUID",
"=",
"ccServicePlanVisibility",
".",
"Entity",
".",
"ServicePlanGUID",
"\n",
"servicePlanVisibility",
".",
"OrganizationGUID",
"=",
"ccServicePlanVisibility",
".",
"Entity",
".",
"OrganizationGUID",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Service Plan Visibilities
// response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Service",
"Plan",
"Visibilities",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_plan_visibility.go#L24-L41 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/service_plan_visibility.go | GetServicePlanVisibilities | func (client *Client) GetServicePlanVisibilities(filters ...Filter) ([]ServicePlanVisibility, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanVisibilitiesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullVisibilityList []ServicePlanVisibility
warnings, err := client.paginate(request, ServicePlanVisibility{}, func(item interface{}) error {
if vis, ok := item.(ServicePlanVisibility); ok {
fullVisibilityList = append(fullVisibilityList, vis)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServicePlanVisibility{},
Unexpected: item,
}
}
return nil
})
return fullVisibilityList, warnings, err
} | go | func (client *Client) GetServicePlanVisibilities(filters ...Filter) ([]ServicePlanVisibility, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServicePlanVisibilitiesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullVisibilityList []ServicePlanVisibility
warnings, err := client.paginate(request, ServicePlanVisibility{}, func(item interface{}) error {
if vis, ok := item.(ServicePlanVisibility); ok {
fullVisibilityList = append(fullVisibilityList, vis)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServicePlanVisibility{},
Unexpected: item,
}
}
return nil
})
return fullVisibilityList, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetServicePlanVisibilities",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"ServicePlanVisibility",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetServicePlanVisibilitiesRequest",
",",
"Query",
":",
"ConvertFilterParameters",
"(",
"filters",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"fullVisibilityList",
"[",
"]",
"ServicePlanVisibility",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"ServicePlanVisibility",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"vis",
",",
"ok",
":=",
"item",
".",
"(",
"ServicePlanVisibility",
")",
";",
"ok",
"{",
"fullVisibilityList",
"=",
"append",
"(",
"fullVisibilityList",
",",
"vis",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"ServicePlanVisibility",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"fullVisibilityList",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetServicePlanVisibilities returns back a list of Service Plan Visibilities
// given the provided filters. | [
"GetServicePlanVisibilities",
"returns",
"back",
"a",
"list",
"of",
"Service",
"Plan",
"Visibilities",
"given",
"the",
"provided",
"filters",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/service_plan_visibility.go#L93-L117 | train |
cloudfoundry/cli | api/uaa/wrapper/request_logger.go | Make | func (logger *RequestLogger) Make(request *http.Request, passedResponse *uaa.Response) error {
err := logger.displayRequest(request)
if err != nil {
logger.output.HandleInternalError(err)
}
err = logger.connection.Make(request, passedResponse)
if passedResponse.HTTPResponse != nil {
displayErr := logger.displayResponse(passedResponse)
if displayErr != nil {
logger.output.HandleInternalError(displayErr)
}
}
return err
} | go | func (logger *RequestLogger) Make(request *http.Request, passedResponse *uaa.Response) error {
err := logger.displayRequest(request)
if err != nil {
logger.output.HandleInternalError(err)
}
err = logger.connection.Make(request, passedResponse)
if passedResponse.HTTPResponse != nil {
displayErr := logger.displayResponse(passedResponse)
if displayErr != nil {
logger.output.HandleInternalError(displayErr)
}
}
return err
} | [
"func",
"(",
"logger",
"*",
"RequestLogger",
")",
"Make",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"passedResponse",
"*",
"uaa",
".",
"Response",
")",
"error",
"{",
"err",
":=",
"logger",
".",
"displayRequest",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"output",
".",
"HandleInternalError",
"(",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"logger",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"passedResponse",
")",
"\n",
"if",
"passedResponse",
".",
"HTTPResponse",
"!=",
"nil",
"{",
"displayErr",
":=",
"logger",
".",
"displayResponse",
"(",
"passedResponse",
")",
"\n",
"if",
"displayErr",
"!=",
"nil",
"{",
"logger",
".",
"output",
".",
"HandleInternalError",
"(",
"displayErr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Make records the request and the response to UI | [
"Make",
"records",
"the",
"request",
"and",
"the",
"response",
"to",
"UI"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/uaa/wrapper/request_logger.go#L44-L60 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | UnmarshalJSON | func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
var ccSpaceQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota)
if err != nil {
return err
}
spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
spaceQuota.Name = ccSpaceQuota.Entity.Name
return nil
} | go | func (spaceQuota *SpaceQuota) UnmarshalJSON(data []byte) error {
var ccSpaceQuota struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
} `json:"entity"`
}
err := cloudcontroller.DecodeJSON(data, &ccSpaceQuota)
if err != nil {
return err
}
spaceQuota.GUID = ccSpaceQuota.Metadata.GUID
spaceQuota.Name = ccSpaceQuota.Entity.Name
return nil
} | [
"func",
"(",
"spaceQuota",
"*",
"SpaceQuota",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ccSpaceQuota",
"struct",
"{",
"Metadata",
"internal",
".",
"Metadata",
"`json:\"metadata\"`",
"\n",
"Entity",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"}",
"`json:\"entity\"`",
"\n",
"}",
"\n",
"err",
":=",
"cloudcontroller",
".",
"DecodeJSON",
"(",
"data",
",",
"&",
"ccSpaceQuota",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"spaceQuota",
".",
"GUID",
"=",
"ccSpaceQuota",
".",
"Metadata",
".",
"GUID",
"\n",
"spaceQuota",
".",
"Name",
"=",
"ccSpaceQuota",
".",
"Entity",
".",
"Name",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON helps unmarshal a Cloud Controller Space Quota response. | [
"UnmarshalJSON",
"helps",
"unmarshal",
"a",
"Cloud",
"Controller",
"Space",
"Quota",
"response",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L21-L36 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | GetSpaceQuotaDefinition | func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceQuotaDefinitionRequest,
URIParams: Params{"space_quota_guid": guid},
})
if err != nil {
return SpaceQuota{}, nil, err
}
var spaceQuota SpaceQuota
response := cloudcontroller.Response{
DecodeJSONResponseInto: &spaceQuota,
}
err = client.connection.Make(request, &response)
return spaceQuota, response.Warnings, err
} | go | func (client *Client) GetSpaceQuotaDefinition(guid string) (SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceQuotaDefinitionRequest,
URIParams: Params{"space_quota_guid": guid},
})
if err != nil {
return SpaceQuota{}, nil, err
}
var spaceQuota SpaceQuota
response := cloudcontroller.Response{
DecodeJSONResponseInto: &spaceQuota,
}
err = client.connection.Make(request, &response)
return spaceQuota, response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetSpaceQuotaDefinition",
"(",
"guid",
"string",
")",
"(",
"SpaceQuota",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetSpaceQuotaDefinitionRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"space_quota_guid\"",
":",
"guid",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SpaceQuota",
"{",
"}",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"spaceQuota",
"SpaceQuota",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"DecodeJSONResponseInto",
":",
"&",
"spaceQuota",
",",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"spaceQuota",
",",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // GetSpaceQuotaDefinition returns a Space Quota. | [
"GetSpaceQuotaDefinition",
"returns",
"a",
"Space",
"Quota",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L39-L55 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | GetSpaceQuotas | func (client *Client) GetSpaceQuotas(orgGUID string) ([]SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationSpaceQuotasRequest,
URIParams: Params{"organization_guid": orgGUID},
})
if err != nil {
return nil, nil, err
}
var spaceQuotas []SpaceQuota
warnings, err := client.paginate(request, SpaceQuota{}, func(item interface{}) error {
if spaceQuota, ok := item.(SpaceQuota); ok {
spaceQuotas = append(spaceQuotas, spaceQuota)
} else {
return ccerror.UnknownObjectInListError{
Expected: SpaceQuota{},
Unexpected: item,
}
}
return nil
})
return spaceQuotas, warnings, err
} | go | func (client *Client) GetSpaceQuotas(orgGUID string) ([]SpaceQuota, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetOrganizationSpaceQuotasRequest,
URIParams: Params{"organization_guid": orgGUID},
})
if err != nil {
return nil, nil, err
}
var spaceQuotas []SpaceQuota
warnings, err := client.paginate(request, SpaceQuota{}, func(item interface{}) error {
if spaceQuota, ok := item.(SpaceQuota); ok {
spaceQuotas = append(spaceQuotas, spaceQuota)
} else {
return ccerror.UnknownObjectInListError{
Expected: SpaceQuota{},
Unexpected: item,
}
}
return nil
})
return spaceQuotas, warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetSpaceQuotas",
"(",
"orgGUID",
"string",
")",
"(",
"[",
"]",
"SpaceQuota",
",",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"GetOrganizationSpaceQuotasRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"organization_guid\"",
":",
"orgGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"spaceQuotas",
"[",
"]",
"SpaceQuota",
"\n",
"warnings",
",",
"err",
":=",
"client",
".",
"paginate",
"(",
"request",
",",
"SpaceQuota",
"{",
"}",
",",
"func",
"(",
"item",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"spaceQuota",
",",
"ok",
":=",
"item",
".",
"(",
"SpaceQuota",
")",
";",
"ok",
"{",
"spaceQuotas",
"=",
"append",
"(",
"spaceQuotas",
",",
"spaceQuota",
")",
"\n",
"}",
"else",
"{",
"return",
"ccerror",
".",
"UnknownObjectInListError",
"{",
"Expected",
":",
"SpaceQuota",
"{",
"}",
",",
"Unexpected",
":",
"item",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"spaceQuotas",
",",
"warnings",
",",
"err",
"\n",
"}"
] | // GetSpaceQuotas returns all the space quotas for the org | [
"GetSpaceQuotas",
"returns",
"all",
"the",
"space",
"quotas",
"for",
"the",
"org"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L58-L82 | train |
cloudfoundry/cli | api/cloudcontroller/ccv2/space_quota.go | SetSpaceQuota | func (client *Client) SetSpaceQuota(spaceGUID string, quotaGUID string) (Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutSpaceQuotaRequest,
URIParams: Params{"space_quota_guid": quotaGUID, "space_guid": spaceGUID},
})
if err != nil {
return nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return response.Warnings, err
} | go | func (client *Client) SetSpaceQuota(spaceGUID string, quotaGUID string) (Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutSpaceQuotaRequest,
URIParams: Params{"space_quota_guid": quotaGUID, "space_guid": spaceGUID},
})
if err != nil {
return nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return response.Warnings, err
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetSpaceQuota",
"(",
"spaceGUID",
"string",
",",
"quotaGUID",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"client",
".",
"newHTTPRequest",
"(",
"requestOptions",
"{",
"RequestName",
":",
"internal",
".",
"PutSpaceQuotaRequest",
",",
"URIParams",
":",
"Params",
"{",
"\"space_quota_guid\"",
":",
"quotaGUID",
",",
"\"space_guid\"",
":",
"spaceGUID",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"response",
":=",
"cloudcontroller",
".",
"Response",
"{",
"}",
"\n",
"err",
"=",
"client",
".",
"connection",
".",
"Make",
"(",
"request",
",",
"&",
"response",
")",
"\n",
"return",
"response",
".",
"Warnings",
",",
"err",
"\n",
"}"
] | // SetSpaceQuota should set the quota for the space and returns the warnings | [
"SetSpaceQuota",
"should",
"set",
"the",
"quota",
"for",
"the",
"space",
"and",
"returns",
"the",
"warnings"
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/api/cloudcontroller/ccv2/space_quota.go#L85-L99 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganization | func (actor Actor) GetOrganization(guid string) (Organization, Warnings, error) {
org, warnings, err := actor.CloudControllerClient.GetOrganization(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{GUID: guid}
}
return Organization(org), Warnings(warnings), err
} | go | func (actor Actor) GetOrganization(guid string) (Organization, Warnings, error) {
org, warnings, err := actor.CloudControllerClient.GetOrganization(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{GUID: guid}
}
return Organization(org), Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganization",
"(",
"guid",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganization",
"(",
"guid",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"ResourceNotFoundError",
")",
";",
"ok",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"OrganizationNotFoundError",
"{",
"GUID",
":",
"guid",
"}",
"\n",
"}",
"\n",
"return",
"Organization",
"(",
"org",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetOrganization returns an Organization based on the provided guid. | [
"GetOrganization",
"returns",
"an",
"Organization",
"based",
"on",
"the",
"provided",
"guid",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L15-L23 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganizationByName | func (actor Actor) GetOrganizationByName(orgName string) (Organization, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return Organization{}, Warnings(warnings), err
}
if len(orgs) == 0 {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{Name: orgName}
}
if len(orgs) > 1 {
var guids []string
for _, org := range orgs {
guids = append(guids, org.GUID)
}
return Organization{}, Warnings(warnings), actionerror.MultipleOrganizationsFoundError{Name: orgName, GUIDs: guids}
}
return Organization(orgs[0]), Warnings(warnings), nil
} | go | func (actor Actor) GetOrganizationByName(orgName string) (Organization, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return Organization{}, Warnings(warnings), err
}
if len(orgs) == 0 {
return Organization{}, Warnings(warnings), actionerror.OrganizationNotFoundError{Name: orgName}
}
if len(orgs) > 1 {
var guids []string
for _, org := range orgs {
guids = append(guids, org.GUID)
}
return Organization{}, Warnings(warnings), actionerror.MultipleOrganizationsFoundError{Name: orgName, GUIDs: guids}
}
return Organization(orgs[0]), Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganizationByName",
"(",
"orgName",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"NameFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"orgName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"orgs",
")",
"==",
"0",
"{",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"OrganizationNotFoundError",
"{",
"Name",
":",
"orgName",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"orgs",
")",
">",
"1",
"{",
"var",
"guids",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"guids",
"=",
"append",
"(",
"guids",
",",
"org",
".",
"GUID",
")",
"\n",
"}",
"\n",
"return",
"Organization",
"{",
"}",
",",
"Warnings",
"(",
"warnings",
")",
",",
"actionerror",
".",
"MultipleOrganizationsFoundError",
"{",
"Name",
":",
"orgName",
",",
"GUIDs",
":",
"guids",
"}",
"\n",
"}",
"\n",
"return",
"Organization",
"(",
"orgs",
"[",
"0",
"]",
")",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // GetOrganizationByName returns an Organization based off of the name given. | [
"GetOrganizationByName",
"returns",
"an",
"Organization",
"based",
"off",
"of",
"the",
"name",
"given",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L26-L49 | train |
cloudfoundry/cli | actor/v2action/organization.go | GrantOrgManagerByUsername | func (actor Actor) GrantOrgManagerByUsername(guid string, username string) (Warnings, error) {
var warnings ccv2.Warnings
var err error
if actor.Config.UAAGrantType() != string(uaaconst.GrantTypeClientCredentials) {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManagerByUsername(guid, username)
} else {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManager(guid, username)
}
return Warnings(warnings), err
} | go | func (actor Actor) GrantOrgManagerByUsername(guid string, username string) (Warnings, error) {
var warnings ccv2.Warnings
var err error
if actor.Config.UAAGrantType() != string(uaaconst.GrantTypeClientCredentials) {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManagerByUsername(guid, username)
} else {
warnings, err = actor.CloudControllerClient.UpdateOrganizationManager(guid, username)
}
return Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GrantOrgManagerByUsername",
"(",
"guid",
"string",
",",
"username",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"var",
"warnings",
"ccv2",
".",
"Warnings",
"\n",
"var",
"err",
"error",
"\n",
"if",
"actor",
".",
"Config",
".",
"UAAGrantType",
"(",
")",
"!=",
"string",
"(",
"uaaconst",
".",
"GrantTypeClientCredentials",
")",
"{",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationManagerByUsername",
"(",
"guid",
",",
"username",
")",
"\n",
"}",
"else",
"{",
"warnings",
",",
"err",
"=",
"actor",
".",
"CloudControllerClient",
".",
"UpdateOrganizationManager",
"(",
"guid",
",",
"username",
")",
"\n",
"}",
"\n",
"return",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GrantOrgManagerByUsername gives the Org Manager role to the provided user. | [
"GrantOrgManagerByUsername",
"gives",
"the",
"Org",
"Manager",
"role",
"to",
"the",
"provided",
"user",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L52-L63 | train |
cloudfoundry/cli | actor/v2action/organization.go | CreateOrganization | func (actor Actor) CreateOrganization(orgName string, quotaName string) (Organization, Warnings, error) {
var quotaGUID string
var allWarnings Warnings
if quotaName != "" {
quota, warnings, err := actor.GetOrganizationQuotaByName(quotaName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return Organization{}, allWarnings, err
}
quotaGUID = quota.GUID
}
org, warnings, err := actor.CloudControllerClient.CreateOrganization(orgName, quotaGUID)
allWarnings = append(allWarnings, warnings...)
if _, ok := err.(ccerror.OrganizationNameTakenError); ok {
return Organization{}, allWarnings, actionerror.OrganizationNameTakenError{Name: orgName}
}
if err != nil {
return Organization{}, allWarnings, err
}
return Organization(org), allWarnings, nil
} | go | func (actor Actor) CreateOrganization(orgName string, quotaName string) (Organization, Warnings, error) {
var quotaGUID string
var allWarnings Warnings
if quotaName != "" {
quota, warnings, err := actor.GetOrganizationQuotaByName(quotaName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return Organization{}, allWarnings, err
}
quotaGUID = quota.GUID
}
org, warnings, err := actor.CloudControllerClient.CreateOrganization(orgName, quotaGUID)
allWarnings = append(allWarnings, warnings...)
if _, ok := err.(ccerror.OrganizationNameTakenError); ok {
return Organization{}, allWarnings, actionerror.OrganizationNameTakenError{Name: orgName}
}
if err != nil {
return Organization{}, allWarnings, err
}
return Organization(org), allWarnings, nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"CreateOrganization",
"(",
"orgName",
"string",
",",
"quotaName",
"string",
")",
"(",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"var",
"quotaGUID",
"string",
"\n",
"var",
"allWarnings",
"Warnings",
"\n",
"if",
"quotaName",
"!=",
"\"\"",
"{",
"quota",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationQuotaByName",
"(",
"quotaName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"quotaGUID",
"=",
"quota",
".",
"GUID",
"\n",
"}",
"\n",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"CreateOrganization",
"(",
"orgName",
",",
"quotaGUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ccerror",
".",
"OrganizationNameTakenError",
")",
";",
"ok",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"actionerror",
".",
"OrganizationNameTakenError",
"{",
"Name",
":",
"orgName",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Organization",
"{",
"}",
",",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"return",
"Organization",
"(",
"org",
")",
",",
"allWarnings",
",",
"nil",
"\n",
"}"
] | // CreateOrganization creates an Organization based on the provided orgName. | [
"CreateOrganization",
"creates",
"an",
"Organization",
"based",
"on",
"the",
"provided",
"orgName",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L66-L91 | train |
cloudfoundry/cli | actor/v2action/organization.go | DeleteOrganization | func (actor Actor) DeleteOrganization(orgName string) (Warnings, error) {
var allWarnings Warnings
org, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
job, deleteWarnings, err := actor.CloudControllerClient.DeleteOrganizationJob(org.GUID)
allWarnings = append(allWarnings, deleteWarnings...)
if err != nil {
return allWarnings, err
}
ccWarnings, err := actor.CloudControllerClient.PollJob(job)
for _, warning := range ccWarnings {
allWarnings = append(allWarnings, warning)
}
return allWarnings, err
} | go | func (actor Actor) DeleteOrganization(orgName string) (Warnings, error) {
var allWarnings Warnings
org, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
if err != nil {
return allWarnings, err
}
job, deleteWarnings, err := actor.CloudControllerClient.DeleteOrganizationJob(org.GUID)
allWarnings = append(allWarnings, deleteWarnings...)
if err != nil {
return allWarnings, err
}
ccWarnings, err := actor.CloudControllerClient.PollJob(job)
for _, warning := range ccWarnings {
allWarnings = append(allWarnings, warning)
}
return allWarnings, err
} | [
"func",
"(",
"actor",
"Actor",
")",
"DeleteOrganization",
"(",
"orgName",
"string",
")",
"(",
"Warnings",
",",
"error",
")",
"{",
"var",
"allWarnings",
"Warnings",
"\n",
"org",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"GetOrganizationByName",
"(",
"orgName",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"job",
",",
"deleteWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"DeleteOrganizationJob",
"(",
"org",
".",
"GUID",
")",
"\n",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"deleteWarnings",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allWarnings",
",",
"err",
"\n",
"}",
"\n",
"ccWarnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"PollJob",
"(",
"job",
")",
"\n",
"for",
"_",
",",
"warning",
":=",
"range",
"ccWarnings",
"{",
"allWarnings",
"=",
"append",
"(",
"allWarnings",
",",
"warning",
")",
"\n",
"}",
"\n",
"return",
"allWarnings",
",",
"err",
"\n",
"}"
] | // DeleteOrganization deletes the Organization associated with the provided
// GUID. Once the deletion request is sent, it polls the deletion job until
// it's finished. | [
"DeleteOrganization",
"deletes",
"the",
"Organization",
"associated",
"with",
"the",
"provided",
"GUID",
".",
"Once",
"the",
"deletion",
"request",
"is",
"sent",
"it",
"polls",
"the",
"deletion",
"job",
"until",
"it",
"s",
"finished",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L96-L117 | train |
cloudfoundry/cli | actor/v2action/organization.go | GetOrganizations | func (actor Actor) GetOrganizations() ([]Organization, Warnings, error) {
var returnedOrgs []Organization
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations()
for _, org := range orgs {
returnedOrgs = append(returnedOrgs, Organization(org))
}
return returnedOrgs, Warnings(warnings), err
} | go | func (actor Actor) GetOrganizations() ([]Organization, Warnings, error) {
var returnedOrgs []Organization
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations()
for _, org := range orgs {
returnedOrgs = append(returnedOrgs, Organization(org))
}
return returnedOrgs, Warnings(warnings), err
} | [
"func",
"(",
"actor",
"Actor",
")",
"GetOrganizations",
"(",
")",
"(",
"[",
"]",
"Organization",
",",
"Warnings",
",",
"error",
")",
"{",
"var",
"returnedOrgs",
"[",
"]",
"Organization",
"\n",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
")",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"returnedOrgs",
"=",
"append",
"(",
"returnedOrgs",
",",
"Organization",
"(",
"org",
")",
")",
"\n",
"}",
"\n",
"return",
"returnedOrgs",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}"
] | // GetOrganizations returns all the available organizations. | [
"GetOrganizations",
"returns",
"all",
"the",
"available",
"organizations",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L120-L127 | train |
cloudfoundry/cli | actor/v2action/organization.go | OrganizationExistsWithName | func (actor Actor) OrganizationExistsWithName(orgName string) (bool, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(orgs) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | go | func (actor Actor) OrganizationExistsWithName(orgName string) (bool, Warnings, error) {
orgs, warnings, err := actor.CloudControllerClient.GetOrganizations(ccv2.Filter{
Type: constant.NameFilter,
Operator: constant.EqualOperator,
Values: []string{orgName},
})
if err != nil {
return false, Warnings(warnings), err
}
if len(orgs) == 0 {
return false, Warnings(warnings), nil
}
return true, Warnings(warnings), nil
} | [
"func",
"(",
"actor",
"Actor",
")",
"OrganizationExistsWithName",
"(",
"orgName",
"string",
")",
"(",
"bool",
",",
"Warnings",
",",
"error",
")",
"{",
"orgs",
",",
"warnings",
",",
"err",
":=",
"actor",
".",
"CloudControllerClient",
".",
"GetOrganizations",
"(",
"ccv2",
".",
"Filter",
"{",
"Type",
":",
"constant",
".",
"NameFilter",
",",
"Operator",
":",
"constant",
".",
"EqualOperator",
",",
"Values",
":",
"[",
"]",
"string",
"{",
"orgName",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"orgs",
")",
"==",
"0",
"{",
"return",
"false",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"Warnings",
"(",
"warnings",
")",
",",
"nil",
"\n",
"}"
] | // OrganizationExistsWithName returns true if there is an Organization with the
// provided name, otherwise false. | [
"OrganizationExistsWithName",
"returns",
"true",
"if",
"there",
"is",
"an",
"Organization",
"with",
"the",
"provided",
"name",
"otherwise",
"false",
"."
] | 5010c000047f246b870475e2c299556078cdad30 | https://github.com/cloudfoundry/cli/blob/5010c000047f246b870475e2c299556078cdad30/actor/v2action/organization.go#L131-L146 | train |
google/seesaw | ncc/client/ncc_client.go | call | func (nc *nccClient) call(name string, in interface{}, out interface{}) error {
nc.lock.RLock()
client := nc.client
nc.lock.RUnlock()
if client == nil {
return fmt.Errorf("Not connected")
}
ch := make(chan error, 1)
go func() {
ch <- client.Call(name, in, out)
}()
select {
case err := <-ch:
return err
case <-time.After(nccRPCTimeout):
return fmt.Errorf("RPC call timed out after %v", nccRPCTimeout)
}
} | go | func (nc *nccClient) call(name string, in interface{}, out interface{}) error {
nc.lock.RLock()
client := nc.client
nc.lock.RUnlock()
if client == nil {
return fmt.Errorf("Not connected")
}
ch := make(chan error, 1)
go func() {
ch <- client.Call(name, in, out)
}()
select {
case err := <-ch:
return err
case <-time.After(nccRPCTimeout):
return fmt.Errorf("RPC call timed out after %v", nccRPCTimeout)
}
} | [
"func",
"(",
"nc",
"*",
"nccClient",
")",
"call",
"(",
"name",
"string",
",",
"in",
"interface",
"{",
"}",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"nc",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"client",
":=",
"nc",
".",
"client",
"\n",
"nc",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"client",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Not connected\"",
")",
"\n",
"}",
"\n",
"ch",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"ch",
"<-",
"client",
".",
"Call",
"(",
"name",
",",
"in",
",",
"out",
")",
"\n",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"ch",
":",
"return",
"err",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"nccRPCTimeout",
")",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"RPC call timed out after %v\"",
",",
"nccRPCTimeout",
")",
"\n",
"}",
"\n",
"}"
] | // call performs an RPC call to the Seesaw v2 nccClient. | [
"call",
"performs",
"an",
"RPC",
"call",
"to",
"the",
"Seesaw",
"v2",
"nccClient",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/client/ncc_client.go#L159-L176 | train |
google/seesaw | healthcheck/core.go | String | func (s State) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "<unknown>"
} | go | func (s State) String() string {
if name, ok := stateNames[s]; ok {
return name
}
return "<unknown>"
} | [
"func",
"(",
"s",
"State",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"stateNames",
"[",
"s",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"<unknown>\"",
"\n",
"}"
] | // String returns the string representation for the given healthcheck state. | [
"String",
"returns",
"the",
"string",
"representation",
"for",
"the",
"given",
"healthcheck",
"state",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L67-L72 | train |
google/seesaw | healthcheck/core.go | String | func (t Target) String() string {
var via string
if t.Mode == seesaw.HCModeDSR {
via = fmt.Sprintf(" (via %s mark %d)", t.Host, t.Mark)
}
return fmt.Sprintf("%s %s%s", t.addr(), t.Mode, via)
} | go | func (t Target) String() string {
var via string
if t.Mode == seesaw.HCModeDSR {
via = fmt.Sprintf(" (via %s mark %d)", t.Host, t.Mark)
}
return fmt.Sprintf("%s %s%s", t.addr(), t.Mode, via)
} | [
"func",
"(",
"t",
"Target",
")",
"String",
"(",
")",
"string",
"{",
"var",
"via",
"string",
"\n",
"if",
"t",
".",
"Mode",
"==",
"seesaw",
".",
"HCModeDSR",
"{",
"via",
"=",
"fmt",
".",
"Sprintf",
"(",
"\" (via %s mark %d)\"",
",",
"t",
".",
"Host",
",",
"t",
".",
"Mark",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s %s%s\"",
",",
"t",
".",
"addr",
"(",
")",
",",
"t",
".",
"Mode",
",",
"via",
")",
"\n",
"}"
] | // String returns the string representation of a healthcheck target. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L91-L97 | train |
google/seesaw | healthcheck/core.go | addr | func (t *Target) addr() string {
if t.IP.To4() != nil {
return fmt.Sprintf("%v:%d", t.IP, t.Port)
}
return fmt.Sprintf("[%v]:%d", t.IP, t.Port)
} | go | func (t *Target) addr() string {
if t.IP.To4() != nil {
return fmt.Sprintf("%v:%d", t.IP, t.Port)
}
return fmt.Sprintf("[%v]:%d", t.IP, t.Port)
} | [
"func",
"(",
"t",
"*",
"Target",
")",
"addr",
"(",
")",
"string",
"{",
"if",
"t",
".",
"IP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%v:%d\"",
",",
"t",
".",
"IP",
",",
"t",
".",
"Port",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"[%v]:%d\"",
",",
"t",
".",
"IP",
",",
"t",
".",
"Port",
")",
"\n",
"}"
] | // addr returns the address string for the healthcheck target. | [
"addr",
"returns",
"the",
"address",
"string",
"for",
"the",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L100-L105 | train |
google/seesaw | healthcheck/core.go | network | func (t *Target) network() string {
version := 4
if t.IP.To4() == nil {
version = 6
}
var network string
switch t.Proto {
case seesaw.IPProtoICMP:
network = "ip4:icmp"
case seesaw.IPProtoICMPv6:
network = "ip6:ipv6-icmp"
case seesaw.IPProtoTCP:
network = fmt.Sprintf("tcp%d", version)
case seesaw.IPProtoUDP:
network = fmt.Sprintf("udp%d", version)
default:
return "(unknown)"
}
return network
} | go | func (t *Target) network() string {
version := 4
if t.IP.To4() == nil {
version = 6
}
var network string
switch t.Proto {
case seesaw.IPProtoICMP:
network = "ip4:icmp"
case seesaw.IPProtoICMPv6:
network = "ip6:ipv6-icmp"
case seesaw.IPProtoTCP:
network = fmt.Sprintf("tcp%d", version)
case seesaw.IPProtoUDP:
network = fmt.Sprintf("udp%d", version)
default:
return "(unknown)"
}
return network
} | [
"func",
"(",
"t",
"*",
"Target",
")",
"network",
"(",
")",
"string",
"{",
"version",
":=",
"4",
"\n",
"if",
"t",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"version",
"=",
"6",
"\n",
"}",
"\n",
"var",
"network",
"string",
"\n",
"switch",
"t",
".",
"Proto",
"{",
"case",
"seesaw",
".",
"IPProtoICMP",
":",
"network",
"=",
"\"ip4:icmp\"",
"\n",
"case",
"seesaw",
".",
"IPProtoICMPv6",
":",
"network",
"=",
"\"ip6:ipv6-icmp\"",
"\n",
"case",
"seesaw",
".",
"IPProtoTCP",
":",
"network",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"tcp%d\"",
",",
"version",
")",
"\n",
"case",
"seesaw",
".",
"IPProtoUDP",
":",
"network",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"udp%d\"",
",",
"version",
")",
"\n",
"default",
":",
"return",
"\"(unknown)\"",
"\n",
"}",
"\n",
"return",
"network",
"\n",
"}"
] | // network returns the network name for the healthcheck target. | [
"network",
"returns",
"the",
"network",
"name",
"for",
"the",
"healthcheck",
"target",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L108-L129 | train |
google/seesaw | healthcheck/core.go | String | func (r *Result) String() string {
if r.Err != nil {
return r.Err.Error()
}
return r.Message
} | go | func (r *Result) String() string {
if r.Err != nil {
return r.Err.Error()
}
return r.Message
} | [
"func",
"(",
"r",
"*",
"Result",
")",
"String",
"(",
")",
"string",
"{",
"if",
"r",
".",
"Err",
"!=",
"nil",
"{",
"return",
"r",
".",
"Err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"Message",
"\n",
"}"
] | // String returns the string representation of a healthcheck result. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"healthcheck",
"result",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L140-L145 | train |
google/seesaw | healthcheck/core.go | complete | func complete(start time.Time, msg string, success bool, err error) *Result {
// TODO(jsing): Make this clock skew safe.
duration := time.Since(start)
return &Result{msg, success, duration, err}
} | go | func complete(start time.Time, msg string, success bool, err error) *Result {
// TODO(jsing): Make this clock skew safe.
duration := time.Since(start)
return &Result{msg, success, duration, err}
} | [
"func",
"complete",
"(",
"start",
"time",
".",
"Time",
",",
"msg",
"string",
",",
"success",
"bool",
",",
"err",
"error",
")",
"*",
"Result",
"{",
"duration",
":=",
"time",
".",
"Since",
"(",
"start",
")",
"\n",
"return",
"&",
"Result",
"{",
"msg",
",",
"success",
",",
"duration",
",",
"err",
"}",
"\n",
"}"
] | // complete returns a Result for a completed healthcheck. | [
"complete",
"returns",
"a",
"Result",
"for",
"a",
"completed",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L148-L152 | train |
google/seesaw | healthcheck/core.go | String | func (n *Notification) String() string {
return fmt.Sprintf("ID 0x%x %v", n.Id, n.State)
} | go | func (n *Notification) String() string {
return fmt.Sprintf("ID 0x%x %v", n.Id, n.State)
} | [
"func",
"(",
"n",
"*",
"Notification",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"ID 0x%x %v\"",
",",
"n",
".",
"Id",
",",
"n",
".",
"State",
")",
"\n",
"}"
] | // String returns the string representation for the given notification. | [
"String",
"returns",
"the",
"string",
"representation",
"for",
"the",
"given",
"notification",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L161-L163 | train |
google/seesaw | healthcheck/core.go | NewConfig | func NewConfig(id Id, checker Checker) *Config {
return &Config{
Id: id,
Interval: 5 * time.Second,
Timeout: 30 * time.Second,
Retries: 0,
Checker: checker,
}
} | go | func NewConfig(id Id, checker Checker) *Config {
return &Config{
Id: id,
Interval: 5 * time.Second,
Timeout: 30 * time.Second,
Retries: 0,
Checker: checker,
}
} | [
"func",
"NewConfig",
"(",
"id",
"Id",
",",
"checker",
"Checker",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"Id",
":",
"id",
",",
"Interval",
":",
"5",
"*",
"time",
".",
"Second",
",",
"Timeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Retries",
":",
"0",
",",
"Checker",
":",
"checker",
",",
"}",
"\n",
"}"
] | // NewConfig returns an initialised Config. | [
"NewConfig",
"returns",
"an",
"initialised",
"Config",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L186-L194 | train |
google/seesaw | healthcheck/core.go | NewCheck | func NewCheck(notify chan<- *Notification) *Check {
return &Check{
state: StateUnknown,
notify: notify,
update: make(chan Config, 1),
quit: make(chan bool, 1),
}
} | go | func NewCheck(notify chan<- *Notification) *Check {
return &Check{
state: StateUnknown,
notify: notify,
update: make(chan Config, 1),
quit: make(chan bool, 1),
}
} | [
"func",
"NewCheck",
"(",
"notify",
"chan",
"<-",
"*",
"Notification",
")",
"*",
"Check",
"{",
"return",
"&",
"Check",
"{",
"state",
":",
"StateUnknown",
",",
"notify",
":",
"notify",
",",
"update",
":",
"make",
"(",
"chan",
"Config",
",",
"1",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"}",
"\n",
"}"
] | // NewCheck returns an initialised Check. | [
"NewCheck",
"returns",
"an",
"initialised",
"Check",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L225-L232 | train |
google/seesaw | healthcheck/core.go | Status | func (hc *Check) Status() Status {
hc.lock.RLock()
defer hc.lock.RUnlock()
status := Status{
LastCheck: hc.start,
Failures: hc.failures,
Successes: hc.successes,
State: hc.state,
}
if hc.result != nil {
status.Duration = hc.result.Duration
status.Message = hc.result.String()
}
return status
} | go | func (hc *Check) Status() Status {
hc.lock.RLock()
defer hc.lock.RUnlock()
status := Status{
LastCheck: hc.start,
Failures: hc.failures,
Successes: hc.successes,
State: hc.state,
}
if hc.result != nil {
status.Duration = hc.result.Duration
status.Message = hc.result.String()
}
return status
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Status",
"(",
")",
"Status",
"{",
"hc",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"hc",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"status",
":=",
"Status",
"{",
"LastCheck",
":",
"hc",
".",
"start",
",",
"Failures",
":",
"hc",
".",
"failures",
",",
"Successes",
":",
"hc",
".",
"successes",
",",
"State",
":",
"hc",
".",
"state",
",",
"}",
"\n",
"if",
"hc",
".",
"result",
"!=",
"nil",
"{",
"status",
".",
"Duration",
"=",
"hc",
".",
"result",
".",
"Duration",
"\n",
"status",
".",
"Message",
"=",
"hc",
".",
"result",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"status",
"\n",
"}"
] | // Status returns the current status for this healthcheck instance. | [
"Status",
"returns",
"the",
"current",
"status",
"for",
"this",
"healthcheck",
"instance",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L235-L249 | train |
google/seesaw | healthcheck/core.go | Run | func (hc *Check) Run(start <-chan time.Time) {
// Wait for initial configuration.
select {
case config := <-hc.update:
hc.Config = config
case <-hc.quit:
return
}
// Wait for a tick to avoid a thundering herd at startup and to
// stagger healthchecks that have the same interval.
if start != nil {
<-start
}
log.Infof("Starting healthchecker for %d (%s)", hc.Id, hc)
ticker := time.NewTicker(hc.Interval)
hc.healthcheck()
for {
select {
case <-hc.quit:
ticker.Stop()
log.Infof("Stopping healthchecker for %d (%s)", hc.Id, hc)
return
case config := <-hc.update:
if hc.Interval != config.Interval {
ticker.Stop()
if start != nil {
<-start
}
ticker = time.NewTicker(config.Interval)
}
hc.Config = config
case <-ticker.C:
hc.healthcheck()
}
}
} | go | func (hc *Check) Run(start <-chan time.Time) {
// Wait for initial configuration.
select {
case config := <-hc.update:
hc.Config = config
case <-hc.quit:
return
}
// Wait for a tick to avoid a thundering herd at startup and to
// stagger healthchecks that have the same interval.
if start != nil {
<-start
}
log.Infof("Starting healthchecker for %d (%s)", hc.Id, hc)
ticker := time.NewTicker(hc.Interval)
hc.healthcheck()
for {
select {
case <-hc.quit:
ticker.Stop()
log.Infof("Stopping healthchecker for %d (%s)", hc.Id, hc)
return
case config := <-hc.update:
if hc.Interval != config.Interval {
ticker.Stop()
if start != nil {
<-start
}
ticker = time.NewTicker(config.Interval)
}
hc.Config = config
case <-ticker.C:
hc.healthcheck()
}
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Run",
"(",
"start",
"<-",
"chan",
"time",
".",
"Time",
")",
"{",
"select",
"{",
"case",
"config",
":=",
"<-",
"hc",
".",
"update",
":",
"hc",
".",
"Config",
"=",
"config",
"\n",
"case",
"<-",
"hc",
".",
"quit",
":",
"return",
"\n",
"}",
"\n",
"if",
"start",
"!=",
"nil",
"{",
"<-",
"start",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"Starting healthchecker for %d (%s)\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"hc",
".",
"Interval",
")",
"\n",
"hc",
".",
"healthcheck",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"hc",
".",
"quit",
":",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"Stopping healthchecker for %d (%s)\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n",
"return",
"\n",
"case",
"config",
":=",
"<-",
"hc",
".",
"update",
":",
"if",
"hc",
".",
"Interval",
"!=",
"config",
".",
"Interval",
"{",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"if",
"start",
"!=",
"nil",
"{",
"<-",
"start",
"\n",
"}",
"\n",
"ticker",
"=",
"time",
".",
"NewTicker",
"(",
"config",
".",
"Interval",
")",
"\n",
"}",
"\n",
"hc",
".",
"Config",
"=",
"config",
"\n",
"case",
"<-",
"ticker",
".",
"C",
":",
"hc",
".",
"healthcheck",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Run invokes a healthcheck. It waits for the initial configuration to be
// provided via the configuration channel, after which the configured
// healthchecker is invoked at the given interval. If a new configuration
// is provided the healthchecker is updated and checks are scheduled at the
// new interval. Notifications are generated and sent via the notification
// channel whenever a state transition occurs. Run will terminate once a
// value is received on the quit channel. | [
"Run",
"invokes",
"a",
"healthcheck",
".",
"It",
"waits",
"for",
"the",
"initial",
"configuration",
"to",
"be",
"provided",
"via",
"the",
"configuration",
"channel",
"after",
"which",
"the",
"configured",
"healthchecker",
"is",
"invoked",
"at",
"the",
"given",
"interval",
".",
"If",
"a",
"new",
"configuration",
"is",
"provided",
"the",
"healthchecker",
"is",
"updated",
"and",
"checks",
"are",
"scheduled",
"at",
"the",
"new",
"interval",
".",
"Notifications",
"are",
"generated",
"and",
"sent",
"via",
"the",
"notification",
"channel",
"whenever",
"a",
"state",
"transition",
"occurs",
".",
"Run",
"will",
"terminate",
"once",
"a",
"value",
"is",
"received",
"on",
"the",
"quit",
"channel",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L258-L298 | train |
google/seesaw | healthcheck/core.go | healthcheck | func (hc *Check) healthcheck() {
if hc.Checker == nil {
return
}
start := time.Now()
result := hc.execute()
status := "SUCCESS"
if !result.Success {
status = "FAILURE"
}
log.Infof("%d: (%s) %s: %v", hc.Id, hc, status, result)
hc.lock.Lock()
hc.start = start
hc.result = result
var state State
if result.Success {
state = StateHealthy
hc.failed = 0
hc.successes++
} else {
hc.failed++
hc.failures++
state = StateUnhealthy
}
if hc.state == StateHealthy && hc.failed > 0 && hc.failed <= uint64(hc.Config.Retries) {
log.Infof("%d: Failure %d - retrying...", hc.Id, hc.failed)
state = StateHealthy
}
transition := (hc.state != state)
hc.state = state
hc.lock.Unlock()
if transition {
hc.Notify()
}
} | go | func (hc *Check) healthcheck() {
if hc.Checker == nil {
return
}
start := time.Now()
result := hc.execute()
status := "SUCCESS"
if !result.Success {
status = "FAILURE"
}
log.Infof("%d: (%s) %s: %v", hc.Id, hc, status, result)
hc.lock.Lock()
hc.start = start
hc.result = result
var state State
if result.Success {
state = StateHealthy
hc.failed = 0
hc.successes++
} else {
hc.failed++
hc.failures++
state = StateUnhealthy
}
if hc.state == StateHealthy && hc.failed > 0 && hc.failed <= uint64(hc.Config.Retries) {
log.Infof("%d: Failure %d - retrying...", hc.Id, hc.failed)
state = StateHealthy
}
transition := (hc.state != state)
hc.state = state
hc.lock.Unlock()
if transition {
hc.Notify()
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"healthcheck",
"(",
")",
"{",
"if",
"hc",
".",
"Checker",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"result",
":=",
"hc",
".",
"execute",
"(",
")",
"\n",
"status",
":=",
"\"SUCCESS\"",
"\n",
"if",
"!",
"result",
".",
"Success",
"{",
"status",
"=",
"\"FAILURE\"",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"%d: (%s) %s: %v\"",
",",
"hc",
".",
"Id",
",",
"hc",
",",
"status",
",",
"result",
")",
"\n",
"hc",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"hc",
".",
"start",
"=",
"start",
"\n",
"hc",
".",
"result",
"=",
"result",
"\n",
"var",
"state",
"State",
"\n",
"if",
"result",
".",
"Success",
"{",
"state",
"=",
"StateHealthy",
"\n",
"hc",
".",
"failed",
"=",
"0",
"\n",
"hc",
".",
"successes",
"++",
"\n",
"}",
"else",
"{",
"hc",
".",
"failed",
"++",
"\n",
"hc",
".",
"failures",
"++",
"\n",
"state",
"=",
"StateUnhealthy",
"\n",
"}",
"\n",
"if",
"hc",
".",
"state",
"==",
"StateHealthy",
"&&",
"hc",
".",
"failed",
">",
"0",
"&&",
"hc",
".",
"failed",
"<=",
"uint64",
"(",
"hc",
".",
"Config",
".",
"Retries",
")",
"{",
"log",
".",
"Infof",
"(",
"\"%d: Failure %d - retrying...\"",
",",
"hc",
".",
"Id",
",",
"hc",
".",
"failed",
")",
"\n",
"state",
"=",
"StateHealthy",
"\n",
"}",
"\n",
"transition",
":=",
"(",
"hc",
".",
"state",
"!=",
"state",
")",
"\n",
"hc",
".",
"state",
"=",
"state",
"\n",
"hc",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"transition",
"{",
"hc",
".",
"Notify",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // healthcheck executes the given checker. | [
"healthcheck",
"executes",
"the",
"given",
"checker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L301-L342 | train |
google/seesaw | healthcheck/core.go | Notify | func (hc *Check) Notify() {
hc.notify <- &Notification{
Id: hc.Id,
Status: hc.Status(),
}
} | go | func (hc *Check) Notify() {
hc.notify <- &Notification{
Id: hc.Id,
Status: hc.Status(),
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Notify",
"(",
")",
"{",
"hc",
".",
"notify",
"<-",
"&",
"Notification",
"{",
"Id",
":",
"hc",
".",
"Id",
",",
"Status",
":",
"hc",
".",
"Status",
"(",
")",
",",
"}",
"\n",
"}"
] | // Notify generates a healthcheck notification for this checker. | [
"Notify",
"generates",
"a",
"healthcheck",
"notification",
"for",
"this",
"checker",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L345-L350 | train |
google/seesaw | healthcheck/core.go | execute | func (hc *Check) execute() *Result {
ch := make(chan *Result, 1)
checker := hc.Checker
go func() {
// TODO(jsing): Determine a way to ensure that this go routine
// does not linger.
ch <- checker.Check(hc.Timeout)
}()
select {
case result := <-ch:
return result
case <-time.After(hc.Timeout):
return &Result{"Timed out", false, hc.Timeout, nil}
}
} | go | func (hc *Check) execute() *Result {
ch := make(chan *Result, 1)
checker := hc.Checker
go func() {
// TODO(jsing): Determine a way to ensure that this go routine
// does not linger.
ch <- checker.Check(hc.Timeout)
}()
select {
case result := <-ch:
return result
case <-time.After(hc.Timeout):
return &Result{"Timed out", false, hc.Timeout, nil}
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"execute",
"(",
")",
"*",
"Result",
"{",
"ch",
":=",
"make",
"(",
"chan",
"*",
"Result",
",",
"1",
")",
"\n",
"checker",
":=",
"hc",
".",
"Checker",
"\n",
"go",
"func",
"(",
")",
"{",
"ch",
"<-",
"checker",
".",
"Check",
"(",
"hc",
".",
"Timeout",
")",
"\n",
"}",
"(",
")",
"\n",
"select",
"{",
"case",
"result",
":=",
"<-",
"ch",
":",
"return",
"result",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"hc",
".",
"Timeout",
")",
":",
"return",
"&",
"Result",
"{",
"\"Timed out\"",
",",
"false",
",",
"hc",
".",
"Timeout",
",",
"nil",
"}",
"\n",
"}",
"\n",
"}"
] | // execute invokes the given healthcheck checker with the configured timeout. | [
"execute",
"invokes",
"the",
"given",
"healthcheck",
"checker",
"with",
"the",
"configured",
"timeout",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L353-L367 | train |
google/seesaw | healthcheck/core.go | Blocking | func (hc *Check) Blocking(block bool) {
len := 0
if !block {
len = 1
}
hc.blocking = block
hc.update = make(chan Config, len)
} | go | func (hc *Check) Blocking(block bool) {
len := 0
if !block {
len = 1
}
hc.blocking = block
hc.update = make(chan Config, len)
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Blocking",
"(",
"block",
"bool",
")",
"{",
"len",
":=",
"0",
"\n",
"if",
"!",
"block",
"{",
"len",
"=",
"1",
"\n",
"}",
"\n",
"hc",
".",
"blocking",
"=",
"block",
"\n",
"hc",
".",
"update",
"=",
"make",
"(",
"chan",
"Config",
",",
"len",
")",
"\n",
"}"
] | // Blocking enables or disables blocking updates for a healthcheck. | [
"Blocking",
"enables",
"or",
"disables",
"blocking",
"updates",
"for",
"a",
"healthcheck",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L378-L385 | train |
google/seesaw | healthcheck/core.go | Update | func (hc *Check) Update(config *Config) {
if hc.blocking {
hc.update <- *config
return
}
select {
case hc.update <- *config:
default:
log.Warningf("Unable to update %d (%s), last update still queued", hc.Id, hc)
}
} | go | func (hc *Check) Update(config *Config) {
if hc.blocking {
hc.update <- *config
return
}
select {
case hc.update <- *config:
default:
log.Warningf("Unable to update %d (%s), last update still queued", hc.Id, hc)
}
} | [
"func",
"(",
"hc",
"*",
"Check",
")",
"Update",
"(",
"config",
"*",
"Config",
")",
"{",
"if",
"hc",
".",
"blocking",
"{",
"hc",
".",
"update",
"<-",
"*",
"config",
"\n",
"return",
"\n",
"}",
"\n",
"select",
"{",
"case",
"hc",
".",
"update",
"<-",
"*",
"config",
":",
"default",
":",
"log",
".",
"Warningf",
"(",
"\"Unable to update %d (%s), last update still queued\"",
",",
"hc",
".",
"Id",
",",
"hc",
")",
"\n",
"}",
"\n",
"}"
] | // Update queues a healthcheck configuration update for processing. | [
"Update",
"queues",
"a",
"healthcheck",
"configuration",
"update",
"for",
"processing",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L388-L398 | train |
google/seesaw | healthcheck/core.go | NewServer | func NewServer(cfg *ServerConfig) *Server {
if cfg == nil {
defaultCfg := DefaultServerConfig()
cfg = &defaultCfg
}
return &Server{
config: cfg,
healthchecks: make(map[Id]*Check),
notify: make(chan *Notification, cfg.ChannelSize),
configs: make(chan map[Id]*Config),
batch: make([]*Notification, 0, cfg.BatchSize),
quit: make(chan bool, 1),
}
} | go | func NewServer(cfg *ServerConfig) *Server {
if cfg == nil {
defaultCfg := DefaultServerConfig()
cfg = &defaultCfg
}
return &Server{
config: cfg,
healthchecks: make(map[Id]*Check),
notify: make(chan *Notification, cfg.ChannelSize),
configs: make(chan map[Id]*Config),
batch: make([]*Notification, 0, cfg.BatchSize),
quit: make(chan bool, 1),
}
} | [
"func",
"NewServer",
"(",
"cfg",
"*",
"ServerConfig",
")",
"*",
"Server",
"{",
"if",
"cfg",
"==",
"nil",
"{",
"defaultCfg",
":=",
"DefaultServerConfig",
"(",
")",
"\n",
"cfg",
"=",
"&",
"defaultCfg",
"\n",
"}",
"\n",
"return",
"&",
"Server",
"{",
"config",
":",
"cfg",
",",
"healthchecks",
":",
"make",
"(",
"map",
"[",
"Id",
"]",
"*",
"Check",
")",
",",
"notify",
":",
"make",
"(",
"chan",
"*",
"Notification",
",",
"cfg",
".",
"ChannelSize",
")",
",",
"configs",
":",
"make",
"(",
"chan",
"map",
"[",
"Id",
"]",
"*",
"Config",
")",
",",
"batch",
":",
"make",
"(",
"[",
"]",
"*",
"Notification",
",",
"0",
",",
"cfg",
".",
"BatchSize",
")",
",",
"quit",
":",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
",",
"}",
"\n",
"}"
] | // NewServer returns an initialised healthcheck server. | [
"NewServer",
"returns",
"an",
"initialised",
"healthcheck",
"server",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L439-L454 | train |
google/seesaw | healthcheck/core.go | Run | func (s *Server) Run() {
go s.updater()
go s.notifier()
go s.manager()
<-s.quit
} | go | func (s *Server) Run() {
go s.updater()
go s.notifier()
go s.manager()
<-s.quit
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Run",
"(",
")",
"{",
"go",
"s",
".",
"updater",
"(",
")",
"\n",
"go",
"s",
".",
"notifier",
"(",
")",
"\n",
"go",
"s",
".",
"manager",
"(",
")",
"\n",
"<-",
"s",
".",
"quit",
"\n",
"}"
] | // Run runs a healthcheck server. | [
"Run",
"runs",
"a",
"healthcheck",
"server",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L465-L471 | train |
google/seesaw | healthcheck/core.go | getHealthchecks | func (s *Server) getHealthchecks() (*Checks, error) {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return nil, fmt.Errorf("Dial failed: %v", err)
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var checks Checks
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
}
return &checks, nil
} | go | func (s *Server) getHealthchecks() (*Checks, error) {
engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
if err != nil {
return nil, fmt.Errorf("Dial failed: %v", err)
}
engineConn.SetDeadline(time.Now().Add(engineTimeout))
engine := rpc.NewClient(engineConn)
defer engine.Close()
var checks Checks
ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
}
return &checks, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"getHealthchecks",
"(",
")",
"(",
"*",
"Checks",
",",
"error",
")",
"{",
"engineConn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"\"unix\"",
",",
"s",
".",
"config",
".",
"EngineSocket",
",",
"engineTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Dial failed: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"engineConn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"engineTimeout",
")",
")",
"\n",
"engine",
":=",
"rpc",
".",
"NewClient",
"(",
"engineConn",
")",
"\n",
"defer",
"engine",
".",
"Close",
"(",
")",
"\n",
"var",
"checks",
"Checks",
"\n",
"ctx",
":=",
"ipc",
".",
"NewTrustedContext",
"(",
"seesaw",
".",
"SCHealthcheck",
")",
"\n",
"if",
"err",
":=",
"engine",
".",
"Call",
"(",
"\"SeesawEngine.Healthchecks\"",
",",
"ctx",
",",
"&",
"checks",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"SeesawEngine.Healthchecks failed: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"checks",
",",
"nil",
"\n",
"}"
] | // getHealthchecks attempts to get the current healthcheck configurations from
// the Seesaw Engine. | [
"getHealthchecks",
"attempts",
"to",
"get",
"the",
"current",
"healthcheck",
"configurations",
"from",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L475-L491 | train |
google/seesaw | healthcheck/core.go | updater | func (s *Server) updater() {
for {
log.Info("Getting healthchecks from engine...")
checks, err := s.getHealthchecks()
if err != nil {
log.Error(err)
time.Sleep(5 * time.Second)
} else {
log.Infof("Engine returned %d healthchecks", len(checks.Configs))
s.configs <- checks.Configs
time.Sleep(15 * time.Second)
}
}
} | go | func (s *Server) updater() {
for {
log.Info("Getting healthchecks from engine...")
checks, err := s.getHealthchecks()
if err != nil {
log.Error(err)
time.Sleep(5 * time.Second)
} else {
log.Infof("Engine returned %d healthchecks", len(checks.Configs))
s.configs <- checks.Configs
time.Sleep(15 * time.Second)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"updater",
"(",
")",
"{",
"for",
"{",
"log",
".",
"Info",
"(",
"\"Getting healthchecks from engine...\"",
")",
"\n",
"checks",
",",
"err",
":=",
"s",
".",
"getHealthchecks",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"time",
".",
"Sleep",
"(",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"Engine returned %d healthchecks\"",
",",
"len",
"(",
"checks",
".",
"Configs",
")",
")",
"\n",
"s",
".",
"configs",
"<-",
"checks",
".",
"Configs",
"\n",
"time",
".",
"Sleep",
"(",
"15",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // updater attempts to fetch healthcheck configurations at regular intervals.
// When configurations are successfully retrieved they are provided to the
// manager via the configs channel. | [
"updater",
"attempts",
"to",
"fetch",
"healthcheck",
"configurations",
"at",
"regular",
"intervals",
".",
"When",
"configurations",
"are",
"successfully",
"retrieved",
"they",
"are",
"provided",
"to",
"the",
"manager",
"via",
"the",
"configs",
"channel",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L496-L509 | train |
google/seesaw | healthcheck/core.go | manager | func (s *Server) manager() {
checkTicker := time.NewTicker(50 * time.Millisecond)
notifyTicker := time.NewTicker(s.config.NotifyInterval)
for {
select {
case configs := <-s.configs:
// Remove healthchecks that have been deleted.
for id, hc := range s.healthchecks {
if configs[id] == nil {
hc.Stop()
delete(s.healthchecks, id)
}
}
// Spawn new healthchecks.
for id := range configs {
if s.healthchecks[id] == nil {
hc := NewCheck(s.notify)
s.healthchecks[id] = hc
go hc.Run(checkTicker.C)
}
}
// Update configurations.
for id, hc := range s.healthchecks {
hc.Update(configs[id])
}
case <-notifyTicker.C:
// Send status notifications for all healthchecks.
for _, hc := range s.healthchecks {
hc.Notify()
}
}
}
} | go | func (s *Server) manager() {
checkTicker := time.NewTicker(50 * time.Millisecond)
notifyTicker := time.NewTicker(s.config.NotifyInterval)
for {
select {
case configs := <-s.configs:
// Remove healthchecks that have been deleted.
for id, hc := range s.healthchecks {
if configs[id] == nil {
hc.Stop()
delete(s.healthchecks, id)
}
}
// Spawn new healthchecks.
for id := range configs {
if s.healthchecks[id] == nil {
hc := NewCheck(s.notify)
s.healthchecks[id] = hc
go hc.Run(checkTicker.C)
}
}
// Update configurations.
for id, hc := range s.healthchecks {
hc.Update(configs[id])
}
case <-notifyTicker.C:
// Send status notifications for all healthchecks.
for _, hc := range s.healthchecks {
hc.Notify()
}
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"manager",
"(",
")",
"{",
"checkTicker",
":=",
"time",
".",
"NewTicker",
"(",
"50",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"notifyTicker",
":=",
"time",
".",
"NewTicker",
"(",
"s",
".",
"config",
".",
"NotifyInterval",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"configs",
":=",
"<-",
"s",
".",
"configs",
":",
"for",
"id",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"if",
"configs",
"[",
"id",
"]",
"==",
"nil",
"{",
"hc",
".",
"Stop",
"(",
")",
"\n",
"delete",
"(",
"s",
".",
"healthchecks",
",",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"id",
":=",
"range",
"configs",
"{",
"if",
"s",
".",
"healthchecks",
"[",
"id",
"]",
"==",
"nil",
"{",
"hc",
":=",
"NewCheck",
"(",
"s",
".",
"notify",
")",
"\n",
"s",
".",
"healthchecks",
"[",
"id",
"]",
"=",
"hc",
"\n",
"go",
"hc",
".",
"Run",
"(",
"checkTicker",
".",
"C",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"id",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"hc",
".",
"Update",
"(",
"configs",
"[",
"id",
"]",
")",
"\n",
"}",
"\n",
"case",
"<-",
"notifyTicker",
".",
"C",
":",
"for",
"_",
",",
"hc",
":=",
"range",
"s",
".",
"healthchecks",
"{",
"hc",
".",
"Notify",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // manager is responsible for controlling the healthchecks that are currently
// running. When healthcheck configurations become available, the manager will
// stop and remove deleted healthchecks, spawn new healthchecks and provide
// the current configurations to each of the running healthchecks. | [
"manager",
"is",
"responsible",
"for",
"controlling",
"the",
"healthchecks",
"that",
"are",
"currently",
"running",
".",
"When",
"healthcheck",
"configurations",
"become",
"available",
"the",
"manager",
"will",
"stop",
"and",
"remove",
"deleted",
"healthchecks",
"spawn",
"new",
"healthchecks",
"and",
"provide",
"the",
"current",
"configurations",
"to",
"each",
"of",
"the",
"running",
"healthchecks",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L515-L550 | train |
google/seesaw | healthcheck/core.go | notifier | func (s *Server) notifier() {
var timer <-chan time.Time
for {
var err error
select {
case notification := <-s.notify:
s.batch = append(s.batch, notification)
// Collect until BatchDelay passes, or BatchSize are queued.
switch len(s.batch) {
case 1:
timer = time.After(s.config.BatchDelay)
case s.config.BatchSize:
err = s.send()
timer = nil
}
case <-timer:
err = s.send()
}
if err != nil {
log.Fatal(err)
}
}
} | go | func (s *Server) notifier() {
var timer <-chan time.Time
for {
var err error
select {
case notification := <-s.notify:
s.batch = append(s.batch, notification)
// Collect until BatchDelay passes, or BatchSize are queued.
switch len(s.batch) {
case 1:
timer = time.After(s.config.BatchDelay)
case s.config.BatchSize:
err = s.send()
timer = nil
}
case <-timer:
err = s.send()
}
if err != nil {
log.Fatal(err)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"notifier",
"(",
")",
"{",
"var",
"timer",
"<-",
"chan",
"time",
".",
"Time",
"\n",
"for",
"{",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"notification",
":=",
"<-",
"s",
".",
"notify",
":",
"s",
".",
"batch",
"=",
"append",
"(",
"s",
".",
"batch",
",",
"notification",
")",
"\n",
"switch",
"len",
"(",
"s",
".",
"batch",
")",
"{",
"case",
"1",
":",
"timer",
"=",
"time",
".",
"After",
"(",
"s",
".",
"config",
".",
"BatchDelay",
")",
"\n",
"case",
"s",
".",
"config",
".",
"BatchSize",
":",
"err",
"=",
"s",
".",
"send",
"(",
")",
"\n",
"timer",
"=",
"nil",
"\n",
"}",
"\n",
"case",
"<-",
"timer",
":",
"err",
"=",
"s",
".",
"send",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // notifier batches healthcheck notifications and sends them to the Seesaw
// Engine. | [
"notifier",
"batches",
"healthcheck",
"notifications",
"and",
"sends",
"them",
"to",
"the",
"Seesaw",
"Engine",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L554-L578 | train |
google/seesaw | healthcheck/core.go | send | func (s *Server) send() error {
failures := 0
for {
err := s.sendBatch(s.batch)
if err == nil {
break
}
failures++
log.Errorf("Send failed %d times: %v", failures, err)
if failures >= s.config.MaxFailures {
return fmt.Errorf("send: %d errors, giving up", failures)
}
time.Sleep(s.config.RetryDelay)
}
s.batch = s.batch[:0]
return nil
} | go | func (s *Server) send() error {
failures := 0
for {
err := s.sendBatch(s.batch)
if err == nil {
break
}
failures++
log.Errorf("Send failed %d times: %v", failures, err)
if failures >= s.config.MaxFailures {
return fmt.Errorf("send: %d errors, giving up", failures)
}
time.Sleep(s.config.RetryDelay)
}
s.batch = s.batch[:0]
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"send",
"(",
")",
"error",
"{",
"failures",
":=",
"0",
"\n",
"for",
"{",
"err",
":=",
"s",
".",
"sendBatch",
"(",
"s",
".",
"batch",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"failures",
"++",
"\n",
"log",
".",
"Errorf",
"(",
"\"Send failed %d times: %v\"",
",",
"failures",
",",
"err",
")",
"\n",
"if",
"failures",
">=",
"s",
".",
"config",
".",
"MaxFailures",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"send: %d errors, giving up\"",
",",
"failures",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"s",
".",
"config",
".",
"RetryDelay",
")",
"\n",
"}",
"\n",
"s",
".",
"batch",
"=",
"s",
".",
"batch",
"[",
":",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // send sends a batch of notifications to the Seesaw Engine, retrying on any
// error and giving up after MaxFailures. | [
"send",
"sends",
"a",
"batch",
"of",
"notifications",
"to",
"the",
"Seesaw",
"Engine",
"retrying",
"on",
"any",
"error",
"and",
"giving",
"up",
"after",
"MaxFailures",
"."
] | 34716af0775ecb1fad239a726390d63d6b0742dd | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/healthcheck/core.go#L582-L601 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.