id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c180900
other.TypeNames = append(first, last...) typ := other.Types[name] delete(other.Types, name) typ.TypeName = newName other.Types[newName] = typ } } } for name, resource := range other.Resources { d.Resources[name] = resource } for name, typ := range other.Types { d.Types[name] = typ } d.ResourceNames = append(d.ResourceNames, other.ResourceNames...) d.TypeNames = append(d.TypeNames, other.TypeNames...) return nil }
c180901
ty.TypeName = newName d.Types[newName] = ty d.TypeNames = append(d.TypeNames, newName) } } } } // 3. Finally initialize .ResourceNames and .TypeNames idx = 0 resourceNames := make([]string, len(d.Resources)) for n := range d.Resources { resourceNames[idx] = n idx++ } sort.Strings(resourceNames) d.ResourceNames = resourceNames typeNames := make([]string, len(d.Types)) idx = 0 for tn := range d.Types { typeNames[idx] = tn idx++ } sort.Strings(typeNames) d.TypeNames = typeNames }
c180902
false for _, tn := range d.TypeNames { if tn == u { taken = true break } } if taken { idx++ } } return u }
c180903
i := 0 for _, p := range a.Params { if p.Mandatory { m[i] = p i++ } } return m[:i] }
c180904
:= range a.Params { if !param.Mandatory { return true } } return false }
c180905
for _, gn := range taken { if gn == uniq { inuse = true break } } if inuse { idx++ uniq = base + strconv.Itoa(idx) } } return uniq }
c180906
template.New("resource-client").Funcs(funcMap).Parse(resourceTmpl) if err != nil { return nil, err } return &ClientWriter{ headerTmpl: headerT, resourceTmpl: resourceT, }, nil }
c180907
"NeedTime": needTime, "NeedJSON": needJSON, } return c.headerTmpl.Execute(w, ctx) }
c180908
fmt.Fprintf(w, "/****** %s ******/\n\n", name) }
c180909
fmt.Sprintf("%s %s `json:\"%s,omitempty\"`", strings.Title(f.VarName), f.Signature(), f.Name) } decl := fmt.Sprintf("type %s struct {\n%s\n}", o.TypeName, strings.Join(fields, "\n\t")) fmt.Fprintf(w, "%s\n\n", decl) }
c180910
return c.resourceTmpl.Execute(w, resource) }
c180911
trailCopy = append(trailCopy, val) } newEC.Trail = append(trailCopy, t) return newEC }
c180912
:= range ep.Parameters { ec := EvalCtx{IsResult: false, Trail: nil, Svc: res, Method: action} ap := a.AnalyzeParam(ec, p) switch p.In { case "header": action.HeaderParamNames = append(action.HeaderParamNames, p.Name) action.Params = append(action.Params, ap) case "query": action.QueryParamNames = append(action.QueryParamNames, p.Name) action.Params = append(action.Params, ap) case "path": action.PathParamNames = append(action.PathParamNames, p.Name) action.Params = append(action.Params, ap) case "body": def := a.Doc.Ref(p.Schema) if def != nil { if def.Type == "array" { fail("Array type for body not implemented yet") } else if def.Type == "object" { // Flatten the first level of object dt := a.AnalyzeDefinition(ec, def, p.Schema.ID()) if obj, ok := dt.(*gen.ObjectDataType); ok { a.addType(ec, obj, p.Schema) action.Payload = obj for _, f := range obj.Fields { action.PayloadParamNames = append(action.PayloadParamNames, f.Name) action.Params = append(action.Params, f) } } } } } } if returnDT != nil { action.Return = signature(returnDT) } action.ReturnLocation = hasLocation dbg("DEBUG ACTION %s", prettify(action)) return nil }
c180913
&NetworkInterfaceLocator{Href(href), api} }
c180914
{ return &NetworkInterfaceAttachmentLocator{Href(href), api} }
c180915
s[1:len(s)-1]) if err != nil { return err } r.Time = t return nil }
c180916
&ExecutionLocator{Href(href), api} }
c180917
&NotificationLocator{Href(href), api} }
c180918
&OperationLocator{Href(href), api} }
c180919
&ScheduledActionLocator{Href(href), api} }
c180920
password, accountID: accountID} return newCookieSigner(&builder, accountID) }
c180921
auther, accountID: accountID, refreshAt: time.Now().Add(-2 * time.Minute), client: httpclient.NewNoRedirect(), } }
c180922
accountID, refreshAt: time.Now().Add(-2 * time.Minute), client: httpclient.NewNoRedirect(), } }
c180923
if url != nil { authReq, authErr = s.builder.BuildLoginRequest(url.Host) if authErr != nil { return authErr } s.host = url.Host req.Host = url.Host req.URL.Host = url.Host resp, err = s.client.DoHidden(authReq) } if err != nil { return fmt.Errorf("Authentication failed: %s", err) } if err := s.refresh(resp); err != nil { return err } } for _, c := range s.cookies { req.AddCookie(c) } req.Header.Set("X-Account", strconv.Itoa(s.accountID)) return nil }
c180924
:= s.builder.(*instanceLoginRequestBuilder) return testAuth(s, s.client, host, instance) }
c180925
failed: %s", resp.Status) } s.cookies = resp.Cookies() s.refreshAt = time.Now().Add(time.Duration(2) * time.Hour) return nil }
c180926
r.Header.Set("X-Account", strconv.Itoa(t.accountID)) } return nil }
c180927
error { r.Header.Set("X-RLL-Secret", a.secret) return nil }
c180928
a.SetHost(ca.host) authReq.Host = a.host authReq.URL.Host = a.host } authReq.Header.Set("Content-Type", "application/json") resp, err := a.client.DoHidden(authReq) if err != nil { return fmt.Errorf("Authentication failed: %s", err) } if resp.StatusCode != 303 { body, err := ioutil.ReadAll(resp.Body) var msg string if err != nil { msg = " - <failed to read body>" } if len(body) > 0 { msg = " - " + string(body) } return fmt.Errorf("Authentication failed: %s%s", resp.Status, msg) } a.refreshAt = time.Now().Add(2 * time.Hour) } a.auther.Sign(r) r.Header.Set("X-Api-Version", "1.0") r.Host = a.host r.URL.Host = a.host return nil }
c180929
= host return } else { elems[len(elems)-2] = "selfservice" } ssLoginHostPrefix := strings.Join(elems, "-") a.host = strings.Join(append([]string{ssLoginHostPrefix}, urlElems[1:]...), ".") }
c180930
if err := a.Sign(req); err != nil { return err } resp, err := a.client.DoHidden(req) if err != nil { return err } if resp.StatusCode != 200 { var body string if b, err := ioutil.ReadAll(resp.Body); err != nil { body = ": " + string(b) } return fmt.Errorf("%s%s", resp.Status, body) } return nil }
c180931
err = url.Parse(loc) if err != nil { return nil, fmt.Errorf("invalid Location header '%s': %s", loc, err) } } } return u, nil }
c180932
scheme = "http" } u := url.URL{ Scheme: scheme, Host: host, Path: path, } return u.String() }
c180933
a.Name == name { return a } } return nil }
c180934
== name { return true } } return false }
c180935
if pattern.Regexp.MatchString(href) || pattern.Regexp.MatchString(href+"/") { matches = append(matches, pattern) } } } return matches }
c180936
{ hiddenHeaders = defaultHiddenHeaders // immutable } else { hiddenHeaders = copyHiddenHeaders(hiddenHeaders) // copy to avoid side-effects } dc := &dumpClient{Client: newRawClient(pb.NoRedirect, pb.NoCertCheck, pb.DisableKeepAlives, responseHeaderTimeout)} dc.isInsecure = func() bool { return pb.Insecure } dc.dumpFormat = func() Format { return dumpFormat } dc.hiddenHeaders = func() map[string]bool { return hiddenHeaders } return dc }
c180937
} dc.hiddenHeaders = func() map[string]bool { return HiddenHeaders } return dc }
c180938
Proxy: http.ProxyFromEnvironment, } tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: noCertCheck} c := http.Client{Transport: &tr} if noRedirect { c.CheckRedirect = func(*http.Request, []*http.Request) error { return fmt.Errorf(noRedirectError) } } return &c }
c180939
return d.doImp(req, true, nil) }
c180940
return d.doImp(req, false, nil) }
c180941
resp, err = ctxhttpDo(ctx, d.getClientWithoutTimeout(), req) } if urlError, ok := err.(*url.Error); ok { if urlError.Err.Error() == noRedirectError { err = nil } } if err != nil { return nil, err } if !hide { d.dumpResponse(resp, req, reqBody) } log.Info("completed", "id", id, "status", resp.Status, "time", time.Since(startedAt).String()) return resp, nil }
c180942
ExpectContinueTimeout: tr.ExpectContinueTimeout, TLSNextProto: tr.TLSNextProto, MaxResponseHeaderBytes: tr.MaxResponseHeaderBytes, } tr = trCopy } else { // note that the following code has a known issue in that it depends on the // current value of the NoCertCheck global. if that global changes after // creation of this client then the behavior is undefined. tr = &http.Transport{Proxy: http.ProxyFromEnvironment} tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: NoCertCheck} } client.Transport = tr return &client }
c180943
if df.IsDebug() { var buffer bytes.Buffer buffer.WriteString(req.Method + " " + req.URL.String() + "\n") d.writeHeaders(&buffer, req.Header) if reqBody != nil { buffer.WriteString("\n") buffer.Write(reqBody) buffer.WriteString("\n") } fmt.Fprint(OsStderr, buffer.String()) } else if df.IsJSON() { return reqBody } return nil }
c180944
headers, func(name string, value []string) { buffer.WriteString(name) buffer.WriteString(": ") buffer.WriteString(strings.Join(value, ", ")) buffer.WriteString("\n") }) }
c180945
{ to = make(map[string]bool) for k, v := range from { to[k] = v } return }
c180946
&& cmdLine.APIToken == "" && !cmdLine.NoAuth { kingpin.Fatalf("missing --account option") } if cmdLine.Host == "" { kingpin.Fatalf("missing --host option") } if cmdLine.Password == "" && cmdLine.OAuthToken == "" && cmdLine.OAuthAccessToken == "" && cmdLine.APIToken == "" && !cmdLine.NoAuth { kingpin.Fatalf("missing login info, use --email and --pwd or use --key, --apiToken or --rl10") } }
c180947
return ca.FromCommandLine(cmdLine) case PolicyCommand: return policy.FromCommandLine(cmdLine) default: return nil, fmt.Errorf("No client for '%s'", name) } }
c180948
rl10Cmd} rl10.RegisterCommands(&registrar) caCmd := app.Command(CaCommand, ca.APIName) registrar = rsapi.Registrar{APICmd: caCmd} ca.RegisterCommands(&registrar) policyCmd := app.Command(PolicyCommand, policy.APIName) registrar = rsapi.Registrar{APICmd: policyCmd} policy.RegisterCommands(&registrar) }
c180949
log15.LvlError, log15.StderrHandler))) }
c180950
pathVariablesRegexp.FindAllStringSubmatch(path, -1) if len(matches) > 0 { pattern.Variables = make([]string, len(matches)) for i, m := range matches { pattern.Variables[i] = m[1] } } return &pattern }
c180951
return ctx } return context.WithValue(ctx, clientIPKey{}, ip) }
c180952
:= ctx.Value(clientIPKey{}).(net.IP) return ip }
c180953
done: make(chan struct{}), address: config.Address, topic: config.Topic, dialTimeout: config.DialTimeout, readTimeout: config.ReadTimeout, writeTimeout: config.WriteTimeout, } return }
c180954
err != nil { return } p.Start() return }
c180955
for i := 0; i != concurrency; i++ { go p.run() } p.started = true }
c180956
for req := range p.reqs { req.complete(err) } p.join.Wait() }
c180957
return p.PublishTo(p.topic, message) }
c180958
Topic: topic, Message: message, Response: response, Deadline: deadline, } // This will always trigger, either if the connection was lost or if a // response was successfully sent. err = <-response return }
c180959
DefaultLocalEngineTombstoneTimeout } e := &LocalEngine{ nodeTimeout: config.NodeTimeout, tombTimeout: config.TombstoneTimeout, done: make(chan struct{}), join: make(chan struct{}), nodes: make(map[string]*LocalNode), } go e.run() return e }
c180960
a non-empty topic") } if len(c.Channel) == 0 { return errors.New("creating a new consumer requires a non-empty channel") } return nil }
c180961
c.ReadTimeout = DefaultReadTimeout } if c.WriteTimeout == 0 { c.WriteTimeout = DefaultWriteTimeout } }
c180962
identify: setIdentifyDefaults(config.Identify), dialTimeout: config.DialTimeout, readTimeout: config.ReadTimeout, writeTimeout: config.WriteTimeout, conns: make(map[string](chan<- Command)), } return }
c180963
err != nil { return } c.Start() return }
c180964
has already been called") } go c.run() c.started = true }
c180965
0 input = messages case msg, ok := <-input: if !ok { return } output <- msg if count++; count >= limit { input = nil } } } }() return output }
c180966
writeResponse(w, []byte(r)) }
c180967
} switch { case bytes.Equal(data, []byte("OK")): res = OK{} case bytes.HasPrefix(data, []byte("E_")): res = readError(data) default: res = RawResponse(data) } return }
c180968
maybe we'll make it configuration in the // future? const coeff = 2.0 return jitteredBackoff(rand, attempt, min, max, coeff) }
c180969
return "message" default: return "frame <" + strconv.Itoa(int(t)) + ">" } }
c180970
if config.TombstoneTimeout == 0 { config.TombstoneTimeout = DefaultLocalEngineTombstoneTimeout } if !strings.Contains(config.Address, "://") { config.Address = "http://" + config.Address } return &ConsulEngine{ client: http.Client{Transport: config.Transport}, address: config.Address, namespace: config.Namespace, nodeTimeout: config.NodeTimeout, tombTimeout: config.TombstoneTimeout, } }
c180971
strconv.ParseUint(s, 16, 64) id = MessageID(v) return }
c180972
16) n := len(a) - len(b) copy(a[n:], b) for i := 0; i != n; i++ { a[i] = '0' } c, e := w.Write(a[:]) return int64(c), e }
c180973
id, Body: body, cmdChan: cmdChan, } }
c180974
called") } defer func() { recover() }() // the connection may have been closed asynchronously m.cmdChan <- Fin{MessageID: m.ID} m.cmdChan = nil }
c180975
been called") } defer func() { recover() }() // the connection may have been closed asynchronously m.cmdChan <- Req{MessageID: m.ID, Timeout: timeout} m.cmdChan = nil }
c180976
return } switch name, args := parts[0], parts[1:]; name { case "PING": return readPing(args...) case "IDENTIFY": return readIdentify(r, args...) case "REGISTER": return readRegister(args...) case "UNREGISTER": return readUnregister(args...) default: err = makeErrInvalid("invalid command %s", name) return } }
c180977
key, fc := range tmpl.render.Config.FuncMapMaker(tmpl.render, req, writer) { funcMap[key] = fc } } for key, fc := range tmpl.funcMap { funcMap[key] = fc } return funcMap }
c180978
*Template { tmpl.funcMap = funcMap return tmpl }
c180979
w.Header().Set("Content-Type", "text/html") } _, err = w.Write([]byte(result)) } return err }
c180980
if !existing { fs.paths = append(fs.paths, pth) } return nil } return errors.New("not found") }
c180981
return ioutil.ReadFile(filepath.Join(pth, name)) } } return []byte{}, fmt.Errorf("%v not found", name) }
c180982
:= filepath.Glob(filepath.Join(pth, pattern)); err == nil { for _, result := range results { matches = append(matches, strings.TrimPrefix(result, pth)) } } } return }
c180983
fs.nameSpacedFS[nameSpace] = &AssetFileSystem{} return fs.nameSpacedFS[nameSpace] }
c180984
assetfs.AssetFS().NameSpace("views") } config.ViewPaths = append(append(config.ViewPaths, viewPaths...), DefaultViewPath) render := &Render{funcMaps: map[string]interface{}{}, Config: config} for _, viewPath := range config.ViewPaths { render.RegisterViewPath(viewPath) } return render }
c180985
render.AssetFileSystem.RegisterPath(filepath.Join(utils.AppRoot, "vendor", pth)) } else { for _, gopath := range utils.GOPATH() { if p := filepath.Join(gopath, "src", pth); isExistingDir(p) { render.ViewPaths = append(render.ViewPaths, p) render.AssetFileSystem.RegisterPath(p) } } } } } }
c180986
assetFS.RegisterPath(viewPath) } render.AssetFileSystem = assetFS }
c180987
&Template{render: render, layout: name} }
c180988
&Template{render: render, usingDefaultLayout: true} return tmpl.Funcs(funcMap) }
c180989
error { tmpl := &Template{render: render, usingDefaultLayout: true} return tmpl.Execute(name, context, request, writer) }
c180990
= template.FuncMap{} } render.funcMaps[name] = fc }
c180991
render.AssetFileSystem.Asset(name) }
c180992
return &plainClient{identity, username, password} }
c180993
c = DefaultConfig } return newUploader(url, h, c) }
c180994
http.DefaultClient } resp, err := client.Do(r) if err != nil { return nil, err } if resp.StatusCode != 200 { return nil, newRespError(resp) } return resp.Body, nil }
c180995
DefaultService.Sign(r, k) }
c180996
[]byte(k.SecretKey)) s.writeSigData(h, r) sig := make([]byte, base64.StdEncoding.EncodedLen(h.Size())) base64.StdEncoding.Encode(sig, h.Sum(nil)) r.Header.Set("Authorization", "AWS "+k.AccessKey+":"+string(sig)) }
c180997
0), io.EOF } reader, err := f.sendRequest(n) if err != nil { return nil, err } defer reader.Close() return f.parseResponse(reader) }
c180998
if p.Axis == "" { findChild(x, &p, &ret) return ret } f := findMap[p.Axis] f(x, &p, &ret) return ret }
c180999
input: xpath, items: make(chan XItem), } go l.run() return l.items }