repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
go-acme/lego | certificate/certificates.go | Revoke | func (c *Certifier) Revoke(cert []byte) error {
certificates, err := certcrypto.ParsePEMBundle(cert)
if err != nil {
return err
}
x509Cert := certificates[0]
if x509Cert.IsCA {
return fmt.Errorf("certificate bundle starts with a CA certificate")
}
revokeMsg := acme.RevokeCertMessage{
Certificate: base64.RawURLEncoding.EncodeToString(x509Cert.Raw),
}
return c.core.Certificates.Revoke(revokeMsg)
} | go | func (c *Certifier) Revoke(cert []byte) error {
certificates, err := certcrypto.ParsePEMBundle(cert)
if err != nil {
return err
}
x509Cert := certificates[0]
if x509Cert.IsCA {
return fmt.Errorf("certificate bundle starts with a CA certificate")
}
revokeMsg := acme.RevokeCertMessage{
Certificate: base64.RawURLEncoding.EncodeToString(x509Cert.Raw),
}
return c.core.Certificates.Revoke(revokeMsg)
} | [
"func",
"(",
"c",
"*",
"Certifier",
")",
"Revoke",
"(",
"cert",
"[",
"]",
"byte",
")",
"error",
"{",
"certificates",
",",
"err",
":=",
"certcrypto",
".",
"ParsePEMBundle",
"(",
"cert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"x509Cert",
":=",
"certificates",
"[",
"0",
"]",
"\n",
"if",
"x509Cert",
".",
"IsCA",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"revokeMsg",
":=",
"acme",
".",
"RevokeCertMessage",
"{",
"Certificate",
":",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"x509Cert",
".",
"Raw",
")",
",",
"}",
"\n\n",
"return",
"c",
".",
"core",
".",
"Certificates",
".",
"Revoke",
"(",
"revokeMsg",
")",
"\n",
"}"
] | // Revoke takes a PEM encoded certificate or bundle and tries to revoke it at the CA. | [
"Revoke",
"takes",
"a",
"PEM",
"encoded",
"certificate",
"or",
"bundle",
"and",
"tries",
"to",
"revoke",
"it",
"at",
"the",
"CA",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/certificate/certificates.go#L312-L328 | train |
go-acme/lego | providers/dns/dreamhost/client.go | updateTxtRecord | func (d *DNSProvider) updateTxtRecord(u fmt.Stringer) error {
resp, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode)
}
raw, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read body: %v", err)
}
var response apiResponse
err = json.Unmarshal(raw, &response)
if err != nil {
return fmt.Errorf("unable to decode API server response: %v: %s", err, string(raw))
}
if response.Result == "error" {
return fmt.Errorf("add TXT record failed: %s", response.Data)
}
log.Infof("dreamhost: %s", response.Data)
return nil
} | go | func (d *DNSProvider) updateTxtRecord(u fmt.Stringer) error {
resp, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("request failed with HTTP status code %d", resp.StatusCode)
}
raw, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read body: %v", err)
}
var response apiResponse
err = json.Unmarshal(raw, &response)
if err != nil {
return fmt.Errorf("unable to decode API server response: %v: %s", err, string(raw))
}
if response.Result == "error" {
return fmt.Errorf("add TXT record failed: %s", response.Data)
}
log.Infof("dreamhost: %s", response.Data)
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"updateTxtRecord",
"(",
"u",
"fmt",
".",
"Stringer",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"d",
".",
"config",
".",
"HTTPClient",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"200",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"raw",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"response",
"apiResponse",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"raw",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"string",
"(",
"raw",
")",
")",
"\n",
"}",
"\n\n",
"if",
"response",
".",
"Result",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"response",
".",
"Data",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"response",
".",
"Data",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateTxtRecord will either add or remove a TXT record.
// action is either cmdAddRecord or cmdRemoveRecord | [
"updateTxtRecord",
"will",
"either",
"add",
"or",
"remove",
"a",
"TXT",
"record",
".",
"action",
"is",
"either",
"cmdAddRecord",
"or",
"cmdRemoveRecord"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dreamhost/client.go#L45-L73 | train |
go-acme/lego | cmd/accounts_storage.go | NewAccountsStorage | func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
// TODO: move to account struct? Currently MUST pass email.
email := getEmail(ctx)
serverURL, err := url.Parse(ctx.GlobalString("server"))
if err != nil {
log.Fatal(err)
}
rootPath := filepath.Join(ctx.GlobalString("path"), baseAccountsRootFolderName)
serverPath := strings.NewReplacer(":", "_", "/", string(os.PathSeparator)).Replace(serverURL.Host)
accountsPath := filepath.Join(rootPath, serverPath)
rootUserPath := filepath.Join(accountsPath, email)
return &AccountsStorage{
userID: email,
rootPath: rootPath,
rootUserPath: rootUserPath,
keysPath: filepath.Join(rootUserPath, baseKeysFolderName),
accountFilePath: filepath.Join(rootUserPath, accountFileName),
ctx: ctx,
}
} | go | func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
// TODO: move to account struct? Currently MUST pass email.
email := getEmail(ctx)
serverURL, err := url.Parse(ctx.GlobalString("server"))
if err != nil {
log.Fatal(err)
}
rootPath := filepath.Join(ctx.GlobalString("path"), baseAccountsRootFolderName)
serverPath := strings.NewReplacer(":", "_", "/", string(os.PathSeparator)).Replace(serverURL.Host)
accountsPath := filepath.Join(rootPath, serverPath)
rootUserPath := filepath.Join(accountsPath, email)
return &AccountsStorage{
userID: email,
rootPath: rootPath,
rootUserPath: rootUserPath,
keysPath: filepath.Join(rootUserPath, baseKeysFolderName),
accountFilePath: filepath.Join(rootUserPath, accountFileName),
ctx: ctx,
}
} | [
"func",
"NewAccountsStorage",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"*",
"AccountsStorage",
"{",
"// TODO: move to account struct? Currently MUST pass email.",
"email",
":=",
"getEmail",
"(",
"ctx",
")",
"\n\n",
"serverURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"ctx",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"rootPath",
":=",
"filepath",
".",
"Join",
"(",
"ctx",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
",",
"baseAccountsRootFolderName",
")",
"\n",
"serverPath",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"string",
"(",
"os",
".",
"PathSeparator",
")",
")",
".",
"Replace",
"(",
"serverURL",
".",
"Host",
")",
"\n",
"accountsPath",
":=",
"filepath",
".",
"Join",
"(",
"rootPath",
",",
"serverPath",
")",
"\n",
"rootUserPath",
":=",
"filepath",
".",
"Join",
"(",
"accountsPath",
",",
"email",
")",
"\n\n",
"return",
"&",
"AccountsStorage",
"{",
"userID",
":",
"email",
",",
"rootPath",
":",
"rootPath",
",",
"rootUserPath",
":",
"rootUserPath",
",",
"keysPath",
":",
"filepath",
".",
"Join",
"(",
"rootUserPath",
",",
"baseKeysFolderName",
")",
",",
"accountFilePath",
":",
"filepath",
".",
"Join",
"(",
"rootUserPath",
",",
"accountFileName",
")",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}"
] | // NewAccountsStorage Creates a new AccountsStorage. | [
"NewAccountsStorage",
"Creates",
"a",
"new",
"AccountsStorage",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/cmd/accounts_storage.go#L73-L95 | train |
go-acme/lego | providers/dns/gandi/gandi.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("gandi: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("gandi: no API Key given")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{
config: config,
inProgressFQDNs: make(map[string]inProgressInfo),
inProgressAuthZones: make(map[string]struct{}),
findZoneByFqdn: dns01.FindZoneByFqdn,
}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("gandi: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("gandi: no API Key given")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{
config: config,
inProgressFQDNs: make(map[string]inProgressInfo),
inProgressAuthZones: make(map[string]struct{}),
findZoneByFqdn: dns01.FindZoneByFqdn,
}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"config",
".",
"BaseURL",
"=",
"defaultBaseURL",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
",",
"inProgressFQDNs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"inProgressInfo",
")",
",",
"inProgressAuthZones",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
",",
"findZoneByFqdn",
":",
"dns01",
".",
"FindZoneByFqdn",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Gandi. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Gandi",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/gandi/gandi.go#L81-L100 | train |
go-acme/lego | providers/dns/gandi/gandi.go | Present | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
if d.config.TTL < minTTL {
d.config.TTL = minTTL // 300 is gandi minimum value for ttl
}
// find authZone and Gandi zone_id for fqdn
authZone, err := d.findZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("gandi: findZoneByFqdn failure: %v", err)
}
zoneID, err := d.getZoneID(authZone)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
// determine name of TXT record
if !strings.HasSuffix(
strings.ToLower(fqdn), strings.ToLower("."+authZone)) {
return fmt.Errorf("gandi: unexpected authZone %s for fqdn %s", authZone, fqdn)
}
name := fqdn[:len(fqdn)-len("."+authZone)]
// acquire lock and check there is not a challenge already in
// progress for this value of authZone
d.inProgressMu.Lock()
defer d.inProgressMu.Unlock()
if _, ok := d.inProgressAuthZones[authZone]; ok {
return fmt.Errorf("gandi: challenge already in progress for authZone %s", authZone)
}
// perform API actions to create and activate new gandi zone
// containing the required TXT record
newZoneName := fmt.Sprintf("%s [ACME Challenge %s]", dns01.UnFqdn(authZone), time.Now().Format(time.RFC822Z))
newZoneID, err := d.cloneZone(zoneID, newZoneName)
if err != nil {
return err
}
newZoneVersion, err := d.newZoneVersion(newZoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.addTXTRecord(newZoneID, newZoneVersion, name, value, d.config.TTL)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.setZoneVersion(newZoneID, newZoneVersion)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.setZone(authZone, newZoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
// save data necessary for CleanUp
d.inProgressFQDNs[fqdn] = inProgressInfo{
zoneID: zoneID,
newZoneID: newZoneID,
authZone: authZone,
}
d.inProgressAuthZones[authZone] = struct{}{}
return nil
} | go | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
if d.config.TTL < minTTL {
d.config.TTL = minTTL // 300 is gandi minimum value for ttl
}
// find authZone and Gandi zone_id for fqdn
authZone, err := d.findZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("gandi: findZoneByFqdn failure: %v", err)
}
zoneID, err := d.getZoneID(authZone)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
// determine name of TXT record
if !strings.HasSuffix(
strings.ToLower(fqdn), strings.ToLower("."+authZone)) {
return fmt.Errorf("gandi: unexpected authZone %s for fqdn %s", authZone, fqdn)
}
name := fqdn[:len(fqdn)-len("."+authZone)]
// acquire lock and check there is not a challenge already in
// progress for this value of authZone
d.inProgressMu.Lock()
defer d.inProgressMu.Unlock()
if _, ok := d.inProgressAuthZones[authZone]; ok {
return fmt.Errorf("gandi: challenge already in progress for authZone %s", authZone)
}
// perform API actions to create and activate new gandi zone
// containing the required TXT record
newZoneName := fmt.Sprintf("%s [ACME Challenge %s]", dns01.UnFqdn(authZone), time.Now().Format(time.RFC822Z))
newZoneID, err := d.cloneZone(zoneID, newZoneName)
if err != nil {
return err
}
newZoneVersion, err := d.newZoneVersion(newZoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.addTXTRecord(newZoneID, newZoneVersion, name, value, d.config.TTL)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.setZoneVersion(newZoneID, newZoneVersion)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
err = d.setZone(authZone, newZoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
// save data necessary for CleanUp
d.inProgressFQDNs[fqdn] = inProgressInfo{
zoneID: zoneID,
newZoneID: newZoneID,
authZone: authZone,
}
d.inProgressAuthZones[authZone] = struct{}{}
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"Present",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"value",
":=",
"dns01",
".",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n\n",
"if",
"d",
".",
"config",
".",
"TTL",
"<",
"minTTL",
"{",
"d",
".",
"config",
".",
"TTL",
"=",
"minTTL",
"// 300 is gandi minimum value for ttl",
"\n",
"}",
"\n\n",
"// find authZone and Gandi zone_id for fqdn",
"authZone",
",",
"err",
":=",
"d",
".",
"findZoneByFqdn",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"zoneID",
",",
"err",
":=",
"d",
".",
"getZoneID",
"(",
"authZone",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// determine name of TXT record",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"strings",
".",
"ToLower",
"(",
"fqdn",
")",
",",
"strings",
".",
"ToLower",
"(",
"\"",
"\"",
"+",
"authZone",
")",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"authZone",
",",
"fqdn",
")",
"\n",
"}",
"\n",
"name",
":=",
"fqdn",
"[",
":",
"len",
"(",
"fqdn",
")",
"-",
"len",
"(",
"\"",
"\"",
"+",
"authZone",
")",
"]",
"\n\n",
"// acquire lock and check there is not a challenge already in",
"// progress for this value of authZone",
"d",
".",
"inProgressMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"inProgressMu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"d",
".",
"inProgressAuthZones",
"[",
"authZone",
"]",
";",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"authZone",
")",
"\n",
"}",
"\n\n",
"// perform API actions to create and activate new gandi zone",
"// containing the required TXT record",
"newZoneName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dns01",
".",
"UnFqdn",
"(",
"authZone",
")",
",",
"time",
".",
"Now",
"(",
")",
".",
"Format",
"(",
"time",
".",
"RFC822Z",
")",
")",
"\n\n",
"newZoneID",
",",
"err",
":=",
"d",
".",
"cloneZone",
"(",
"zoneID",
",",
"newZoneName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"newZoneVersion",
",",
"err",
":=",
"d",
".",
"newZoneVersion",
"(",
"newZoneID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"d",
".",
"addTXTRecord",
"(",
"newZoneID",
",",
"newZoneVersion",
",",
"name",
",",
"value",
",",
"d",
".",
"config",
".",
"TTL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"d",
".",
"setZoneVersion",
"(",
"newZoneID",
",",
"newZoneVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"d",
".",
"setZone",
"(",
"authZone",
",",
"newZoneID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// save data necessary for CleanUp",
"d",
".",
"inProgressFQDNs",
"[",
"fqdn",
"]",
"=",
"inProgressInfo",
"{",
"zoneID",
":",
"zoneID",
",",
"newZoneID",
":",
"newZoneID",
",",
"authZone",
":",
"authZone",
",",
"}",
"\n",
"d",
".",
"inProgressAuthZones",
"[",
"authZone",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Present creates a TXT record using the specified parameters. It
// does this by creating and activating a new temporary Gandi DNS
// zone. This new zone contains the TXT record. | [
"Present",
"creates",
"a",
"TXT",
"record",
"using",
"the",
"specified",
"parameters",
".",
"It",
"does",
"this",
"by",
"creating",
"and",
"activating",
"a",
"new",
"temporary",
"Gandi",
"DNS",
"zone",
".",
"This",
"new",
"zone",
"contains",
"the",
"TXT",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/gandi/gandi.go#L105-L177 | train |
go-acme/lego | providers/dns/gandi/gandi.go | CleanUp | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
// acquire lock and retrieve zoneID, newZoneID and authZone
d.inProgressMu.Lock()
defer d.inProgressMu.Unlock()
if _, ok := d.inProgressFQDNs[fqdn]; !ok {
// if there is no cleanup information then just return
return nil
}
zoneID := d.inProgressFQDNs[fqdn].zoneID
newZoneID := d.inProgressFQDNs[fqdn].newZoneID
authZone := d.inProgressFQDNs[fqdn].authZone
delete(d.inProgressFQDNs, fqdn)
delete(d.inProgressAuthZones, authZone)
// perform API actions to restore old gandi zone for authZone
err := d.setZone(authZone, zoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
return d.deleteZone(newZoneID)
} | go | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
// acquire lock and retrieve zoneID, newZoneID and authZone
d.inProgressMu.Lock()
defer d.inProgressMu.Unlock()
if _, ok := d.inProgressFQDNs[fqdn]; !ok {
// if there is no cleanup information then just return
return nil
}
zoneID := d.inProgressFQDNs[fqdn].zoneID
newZoneID := d.inProgressFQDNs[fqdn].newZoneID
authZone := d.inProgressFQDNs[fqdn].authZone
delete(d.inProgressFQDNs, fqdn)
delete(d.inProgressAuthZones, authZone)
// perform API actions to restore old gandi zone for authZone
err := d.setZone(authZone, zoneID)
if err != nil {
return fmt.Errorf("gandi: %v", err)
}
return d.deleteZone(newZoneID)
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"CleanUp",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"_",
":=",
"dns01",
".",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n\n",
"// acquire lock and retrieve zoneID, newZoneID and authZone",
"d",
".",
"inProgressMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"inProgressMu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"d",
".",
"inProgressFQDNs",
"[",
"fqdn",
"]",
";",
"!",
"ok",
"{",
"// if there is no cleanup information then just return",
"return",
"nil",
"\n",
"}",
"\n\n",
"zoneID",
":=",
"d",
".",
"inProgressFQDNs",
"[",
"fqdn",
"]",
".",
"zoneID",
"\n",
"newZoneID",
":=",
"d",
".",
"inProgressFQDNs",
"[",
"fqdn",
"]",
".",
"newZoneID",
"\n",
"authZone",
":=",
"d",
".",
"inProgressFQDNs",
"[",
"fqdn",
"]",
".",
"authZone",
"\n",
"delete",
"(",
"d",
".",
"inProgressFQDNs",
",",
"fqdn",
")",
"\n",
"delete",
"(",
"d",
".",
"inProgressAuthZones",
",",
"authZone",
")",
"\n\n",
"// perform API actions to restore old gandi zone for authZone",
"err",
":=",
"d",
".",
"setZone",
"(",
"authZone",
",",
"zoneID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"deleteZone",
"(",
"newZoneID",
")",
"\n",
"}"
] | // CleanUp removes the TXT record matching the specified
// parameters. It does this by restoring the old Gandi DNS zone and
// removing the temporary one created by Present. | [
"CleanUp",
"removes",
"the",
"TXT",
"record",
"matching",
"the",
"specified",
"parameters",
".",
"It",
"does",
"this",
"by",
"restoring",
"the",
"old",
"Gandi",
"DNS",
"zone",
"and",
"removing",
"the",
"temporary",
"one",
"created",
"by",
"Present",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/gandi/gandi.go#L182-L207 | train |
go-acme/lego | providers/dns/vultr/vultr.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("vultr: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("vultr: credentials missing")
}
options := &vultr.Options{
HTTPClient: config.HTTPClient,
}
client := vultr.NewClient(config.APIKey, options)
return &DNSProvider{client: client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("vultr: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("vultr: credentials missing")
}
options := &vultr.Options{
HTTPClient: config.HTTPClient,
}
client := vultr.NewClient(config.APIKey, options)
return &DNSProvider{client: client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"options",
":=",
"&",
"vultr",
".",
"Options",
"{",
"HTTPClient",
":",
"config",
".",
"HTTPClient",
",",
"}",
"\n",
"client",
":=",
"vultr",
".",
"NewClient",
"(",
"config",
".",
"APIKey",
",",
"options",
")",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Vultr. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Vultr",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vultr/vultr.go#L64-L79 | train |
go-acme/lego | providers/dns/vultr/vultr.go | Present | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneDomain, err := d.getHostedZone(domain)
if err != nil {
return fmt.Errorf("vultr: %v", err)
}
name := d.extractRecordName(fqdn, zoneDomain)
err = d.client.CreateDNSRecord(zoneDomain, name, "TXT", `"`+value+`"`, 0, d.config.TTL)
if err != nil {
return fmt.Errorf("vultr: API call failed: %v", err)
}
return nil
} | go | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneDomain, err := d.getHostedZone(domain)
if err != nil {
return fmt.Errorf("vultr: %v", err)
}
name := d.extractRecordName(fqdn, zoneDomain)
err = d.client.CreateDNSRecord(zoneDomain, name, "TXT", `"`+value+`"`, 0, d.config.TTL)
if err != nil {
return fmt.Errorf("vultr: API call failed: %v", err)
}
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"Present",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"value",
":=",
"dns01",
".",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n\n",
"zoneDomain",
",",
"err",
":=",
"d",
".",
"getHostedZone",
"(",
"domain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"name",
":=",
"d",
".",
"extractRecordName",
"(",
"fqdn",
",",
"zoneDomain",
")",
"\n\n",
"err",
"=",
"d",
".",
"client",
".",
"CreateDNSRecord",
"(",
"zoneDomain",
",",
"name",
",",
"\"",
"\"",
",",
"`\"`",
"+",
"value",
"+",
"`\"`",
",",
"0",
",",
"d",
".",
"config",
".",
"TTL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Present creates a TXT record to fulfill the DNS-01 challenge. | [
"Present",
"creates",
"a",
"TXT",
"record",
"to",
"fulfill",
"the",
"DNS",
"-",
"01",
"challenge",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vultr/vultr.go#L82-L98 | train |
go-acme/lego | challenge/dns01/nameserver.go | getNameservers | func getNameservers(path string, defaults []string) []string {
config, err := dns.ClientConfigFromFile(path)
if err != nil || len(config.Servers) == 0 {
return defaults
}
return ParseNameservers(config.Servers)
} | go | func getNameservers(path string, defaults []string) []string {
config, err := dns.ClientConfigFromFile(path)
if err != nil || len(config.Servers) == 0 {
return defaults
}
return ParseNameservers(config.Servers)
} | [
"func",
"getNameservers",
"(",
"path",
"string",
",",
"defaults",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"config",
",",
"err",
":=",
"dns",
".",
"ClientConfigFromFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"len",
"(",
"config",
".",
"Servers",
")",
"==",
"0",
"{",
"return",
"defaults",
"\n",
"}",
"\n\n",
"return",
"ParseNameservers",
"(",
"config",
".",
"Servers",
")",
"\n",
"}"
] | // getNameservers attempts to get systems nameservers before falling back to the defaults | [
"getNameservers",
"attempts",
"to",
"get",
"systems",
"nameservers",
"before",
"falling",
"back",
"to",
"the",
"defaults"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/nameserver.go#L53-L60 | train |
go-acme/lego | challenge/dns01/nameserver.go | lookupNameservers | func lookupNameservers(fqdn string) ([]string, error) {
var authoritativeNss []string
zone, err := FindZoneByFqdn(fqdn)
if err != nil {
return nil, fmt.Errorf("could not determine the zone: %v", err)
}
r, err := dnsQuery(zone, dns.TypeNS, recursiveNameservers, true)
if err != nil {
return nil, err
}
for _, rr := range r.Answer {
if ns, ok := rr.(*dns.NS); ok {
authoritativeNss = append(authoritativeNss, strings.ToLower(ns.Ns))
}
}
if len(authoritativeNss) > 0 {
return authoritativeNss, nil
}
return nil, fmt.Errorf("could not determine authoritative nameservers")
} | go | func lookupNameservers(fqdn string) ([]string, error) {
var authoritativeNss []string
zone, err := FindZoneByFqdn(fqdn)
if err != nil {
return nil, fmt.Errorf("could not determine the zone: %v", err)
}
r, err := dnsQuery(zone, dns.TypeNS, recursiveNameservers, true)
if err != nil {
return nil, err
}
for _, rr := range r.Answer {
if ns, ok := rr.(*dns.NS); ok {
authoritativeNss = append(authoritativeNss, strings.ToLower(ns.Ns))
}
}
if len(authoritativeNss) > 0 {
return authoritativeNss, nil
}
return nil, fmt.Errorf("could not determine authoritative nameservers")
} | [
"func",
"lookupNameservers",
"(",
"fqdn",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"authoritativeNss",
"[",
"]",
"string",
"\n\n",
"zone",
",",
"err",
":=",
"FindZoneByFqdn",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"dnsQuery",
"(",
"zone",
",",
"dns",
".",
"TypeNS",
",",
"recursiveNameservers",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"rr",
":=",
"range",
"r",
".",
"Answer",
"{",
"if",
"ns",
",",
"ok",
":=",
"rr",
".",
"(",
"*",
"dns",
".",
"NS",
")",
";",
"ok",
"{",
"authoritativeNss",
"=",
"append",
"(",
"authoritativeNss",
",",
"strings",
".",
"ToLower",
"(",
"ns",
".",
"Ns",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"authoritativeNss",
")",
">",
"0",
"{",
"return",
"authoritativeNss",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // lookupNameservers returns the authoritative nameservers for the given fqdn. | [
"lookupNameservers",
"returns",
"the",
"authoritative",
"nameservers",
"for",
"the",
"given",
"fqdn",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/nameserver.go#L76-L99 | train |
go-acme/lego | challenge/dns01/nameserver.go | FindZoneByFqdnCustom | func FindZoneByFqdnCustom(fqdn string, nameservers []string) (string, error) {
muFqdnToZone.Lock()
defer muFqdnToZone.Unlock()
// Do we have it cached?
if zone, ok := fqdnToZone[fqdn]; ok {
return zone, nil
}
var err error
var in *dns.Msg
labelIndexes := dns.Split(fqdn)
for _, index := range labelIndexes {
domain := fqdn[index:]
in, err = dnsQuery(domain, dns.TypeSOA, nameservers, true)
if err != nil {
continue
}
if in == nil {
continue
}
switch in.Rcode {
case dns.RcodeSuccess:
// Check if we got a SOA RR in the answer section
if len(in.Answer) == 0 {
continue
}
// CNAME records cannot/should not exist at the root of a zone.
// So we skip a domain when a CNAME is found.
if dnsMsgContainsCNAME(in) {
continue
}
for _, ans := range in.Answer {
if soa, ok := ans.(*dns.SOA); ok {
zone := soa.Hdr.Name
fqdnToZone[fqdn] = zone
return zone, nil
}
}
case dns.RcodeNameError:
// NXDOMAIN
default:
// Any response code other than NOERROR and NXDOMAIN is treated as error
return "", fmt.Errorf("unexpected response code '%s' for %s", dns.RcodeToString[in.Rcode], domain)
}
}
return "", fmt.Errorf("could not find the start of authority for %s%s", fqdn, formatDNSError(in, err))
} | go | func FindZoneByFqdnCustom(fqdn string, nameservers []string) (string, error) {
muFqdnToZone.Lock()
defer muFqdnToZone.Unlock()
// Do we have it cached?
if zone, ok := fqdnToZone[fqdn]; ok {
return zone, nil
}
var err error
var in *dns.Msg
labelIndexes := dns.Split(fqdn)
for _, index := range labelIndexes {
domain := fqdn[index:]
in, err = dnsQuery(domain, dns.TypeSOA, nameservers, true)
if err != nil {
continue
}
if in == nil {
continue
}
switch in.Rcode {
case dns.RcodeSuccess:
// Check if we got a SOA RR in the answer section
if len(in.Answer) == 0 {
continue
}
// CNAME records cannot/should not exist at the root of a zone.
// So we skip a domain when a CNAME is found.
if dnsMsgContainsCNAME(in) {
continue
}
for _, ans := range in.Answer {
if soa, ok := ans.(*dns.SOA); ok {
zone := soa.Hdr.Name
fqdnToZone[fqdn] = zone
return zone, nil
}
}
case dns.RcodeNameError:
// NXDOMAIN
default:
// Any response code other than NOERROR and NXDOMAIN is treated as error
return "", fmt.Errorf("unexpected response code '%s' for %s", dns.RcodeToString[in.Rcode], domain)
}
}
return "", fmt.Errorf("could not find the start of authority for %s%s", fqdn, formatDNSError(in, err))
} | [
"func",
"FindZoneByFqdnCustom",
"(",
"fqdn",
"string",
",",
"nameservers",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"muFqdnToZone",
".",
"Lock",
"(",
")",
"\n",
"defer",
"muFqdnToZone",
".",
"Unlock",
"(",
")",
"\n\n",
"// Do we have it cached?",
"if",
"zone",
",",
"ok",
":=",
"fqdnToZone",
"[",
"fqdn",
"]",
";",
"ok",
"{",
"return",
"zone",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"var",
"in",
"*",
"dns",
".",
"Msg",
"\n\n",
"labelIndexes",
":=",
"dns",
".",
"Split",
"(",
"fqdn",
")",
"\n",
"for",
"_",
",",
"index",
":=",
"range",
"labelIndexes",
"{",
"domain",
":=",
"fqdn",
"[",
"index",
":",
"]",
"\n\n",
"in",
",",
"err",
"=",
"dnsQuery",
"(",
"domain",
",",
"dns",
".",
"TypeSOA",
",",
"nameservers",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"in",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"switch",
"in",
".",
"Rcode",
"{",
"case",
"dns",
".",
"RcodeSuccess",
":",
"// Check if we got a SOA RR in the answer section",
"if",
"len",
"(",
"in",
".",
"Answer",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"// CNAME records cannot/should not exist at the root of a zone.",
"// So we skip a domain when a CNAME is found.",
"if",
"dnsMsgContainsCNAME",
"(",
"in",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ans",
":=",
"range",
"in",
".",
"Answer",
"{",
"if",
"soa",
",",
"ok",
":=",
"ans",
".",
"(",
"*",
"dns",
".",
"SOA",
")",
";",
"ok",
"{",
"zone",
":=",
"soa",
".",
"Hdr",
".",
"Name",
"\n",
"fqdnToZone",
"[",
"fqdn",
"]",
"=",
"zone",
"\n",
"return",
"zone",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"dns",
".",
"RcodeNameError",
":",
"// NXDOMAIN",
"default",
":",
"// Any response code other than NOERROR and NXDOMAIN is treated as error",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dns",
".",
"RcodeToString",
"[",
"in",
".",
"Rcode",
"]",
",",
"domain",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fqdn",
",",
"formatDNSError",
"(",
"in",
",",
"err",
")",
")",
"\n",
"}"
] | // FindZoneByFqdnCustom determines the zone apex for the given fqdn
// by recursing up the domain labels until the nameserver returns a SOA record in the answer section. | [
"FindZoneByFqdnCustom",
"determines",
"the",
"zone",
"apex",
"for",
"the",
"given",
"fqdn",
"by",
"recursing",
"up",
"the",
"domain",
"labels",
"until",
"the",
"nameserver",
"returns",
"a",
"SOA",
"record",
"in",
"the",
"answer",
"section",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/nameserver.go#L109-L164 | train |
go-acme/lego | challenge/dns01/nameserver.go | dnsMsgContainsCNAME | func dnsMsgContainsCNAME(msg *dns.Msg) bool {
for _, ans := range msg.Answer {
if _, ok := ans.(*dns.CNAME); ok {
return true
}
}
return false
} | go | func dnsMsgContainsCNAME(msg *dns.Msg) bool {
for _, ans := range msg.Answer {
if _, ok := ans.(*dns.CNAME); ok {
return true
}
}
return false
} | [
"func",
"dnsMsgContainsCNAME",
"(",
"msg",
"*",
"dns",
".",
"Msg",
")",
"bool",
"{",
"for",
"_",
",",
"ans",
":=",
"range",
"msg",
".",
"Answer",
"{",
"if",
"_",
",",
"ok",
":=",
"ans",
".",
"(",
"*",
"dns",
".",
"CNAME",
")",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // dnsMsgContainsCNAME checks for a CNAME answer in msg | [
"dnsMsgContainsCNAME",
"checks",
"for",
"a",
"CNAME",
"answer",
"in",
"msg"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/nameserver.go#L167-L174 | train |
go-acme/lego | providers/dns/joker/client.go | parseResponse | func parseResponse(message string) *response {
r := &response{Headers: url.Values{}, StatusCode: -1}
parts := strings.SplitN(message, "\n\n", 2)
for _, line := range strings.Split(parts[0], "\n") {
if strings.TrimSpace(line) == "" {
continue
}
kv := strings.SplitN(line, ":", 2)
val := ""
if len(kv) == 2 {
val = strings.TrimSpace(kv[1])
}
r.Headers.Add(kv[0], val)
switch kv[0] {
case "Status-Code":
i, err := strconv.Atoi(val)
if err == nil {
r.StatusCode = i
}
case "Status-Text":
r.StatusText = val
case "Auth-Sid":
r.AuthSid = val
}
}
if len(parts) > 1 {
r.Body = parts[1]
}
return r
} | go | func parseResponse(message string) *response {
r := &response{Headers: url.Values{}, StatusCode: -1}
parts := strings.SplitN(message, "\n\n", 2)
for _, line := range strings.Split(parts[0], "\n") {
if strings.TrimSpace(line) == "" {
continue
}
kv := strings.SplitN(line, ":", 2)
val := ""
if len(kv) == 2 {
val = strings.TrimSpace(kv[1])
}
r.Headers.Add(kv[0], val)
switch kv[0] {
case "Status-Code":
i, err := strconv.Atoi(val)
if err == nil {
r.StatusCode = i
}
case "Status-Text":
r.StatusText = val
case "Auth-Sid":
r.AuthSid = val
}
}
if len(parts) > 1 {
r.Body = parts[1]
}
return r
} | [
"func",
"parseResponse",
"(",
"message",
"string",
")",
"*",
"response",
"{",
"r",
":=",
"&",
"response",
"{",
"Headers",
":",
"url",
".",
"Values",
"{",
"}",
",",
"StatusCode",
":",
"-",
"1",
"}",
"\n\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"message",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"2",
")",
"\n\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"parts",
"[",
"0",
"]",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"kv",
":=",
"strings",
".",
"SplitN",
"(",
"line",
",",
"\"",
"\"",
",",
"2",
")",
"\n\n",
"val",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"kv",
")",
"==",
"2",
"{",
"val",
"=",
"strings",
".",
"TrimSpace",
"(",
"kv",
"[",
"1",
"]",
")",
"\n",
"}",
"\n\n",
"r",
".",
"Headers",
".",
"Add",
"(",
"kv",
"[",
"0",
"]",
",",
"val",
")",
"\n\n",
"switch",
"kv",
"[",
"0",
"]",
"{",
"case",
"\"",
"\"",
":",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"r",
".",
"StatusCode",
"=",
"i",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"r",
".",
"StatusText",
"=",
"val",
"\n",
"case",
"\"",
"\"",
":",
"r",
".",
"AuthSid",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"parts",
")",
">",
"1",
"{",
"r",
".",
"Body",
"=",
"parts",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // parseResponse parses HTTP response body | [
"parseResponse",
"parses",
"HTTP",
"response",
"body"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L27-L64 | train |
go-acme/lego | providers/dns/joker/client.go | login | func (d *DNSProvider) login() (*response, error) {
if d.config.AuthSid != "" {
// already logged in
return nil, nil
}
response, err := d.postRequest("login", url.Values{"api-key": {d.config.APIKey}})
if err != nil {
return response, err
}
if response == nil {
return nil, fmt.Errorf("login returned nil response")
}
if response.AuthSid == "" {
return response, fmt.Errorf("login did not return valid Auth-Sid")
}
d.config.AuthSid = response.AuthSid
return response, nil
} | go | func (d *DNSProvider) login() (*response, error) {
if d.config.AuthSid != "" {
// already logged in
return nil, nil
}
response, err := d.postRequest("login", url.Values{"api-key": {d.config.APIKey}})
if err != nil {
return response, err
}
if response == nil {
return nil, fmt.Errorf("login returned nil response")
}
if response.AuthSid == "" {
return response, fmt.Errorf("login did not return valid Auth-Sid")
}
d.config.AuthSid = response.AuthSid
return response, nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"login",
"(",
")",
"(",
"*",
"response",
",",
"error",
")",
"{",
"if",
"d",
".",
"config",
".",
"AuthSid",
"!=",
"\"",
"\"",
"{",
"// already logged in",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"d",
".",
"postRequest",
"(",
"\"",
"\"",
",",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"d",
".",
"config",
".",
"APIKey",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"response",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"response",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"response",
".",
"AuthSid",
"==",
"\"",
"\"",
"{",
"return",
"response",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"d",
".",
"config",
".",
"AuthSid",
"=",
"response",
".",
"AuthSid",
"\n\n",
"return",
"response",
",",
"nil",
"\n",
"}"
] | // login performs a login to Joker's DMAPI | [
"login",
"performs",
"a",
"login",
"to",
"Joker",
"s",
"DMAPI"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L67-L89 | train |
go-acme/lego | providers/dns/joker/client.go | logout | func (d *DNSProvider) logout() (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("already logged out")
}
response, err := d.postRequest("logout", url.Values{})
if err == nil {
d.config.AuthSid = ""
}
return response, err
} | go | func (d *DNSProvider) logout() (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("already logged out")
}
response, err := d.postRequest("logout", url.Values{})
if err == nil {
d.config.AuthSid = ""
}
return response, err
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"logout",
"(",
")",
"(",
"*",
"response",
",",
"error",
")",
"{",
"if",
"d",
".",
"config",
".",
"AuthSid",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"d",
".",
"postRequest",
"(",
"\"",
"\"",
",",
"url",
".",
"Values",
"{",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"d",
".",
"config",
".",
"AuthSid",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"response",
",",
"err",
"\n",
"}"
] | // logout closes authenticated session with Joker's DMAPI | [
"logout",
"closes",
"authenticated",
"session",
"with",
"Joker",
"s",
"DMAPI"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L92-L102 | train |
go-acme/lego | providers/dns/joker/client.go | getZone | func (d *DNSProvider) getZone(domain string) (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("must be logged in to get zone")
}
return d.postRequest("dns-zone-get", url.Values{"domain": {dns01.UnFqdn(domain)}})
} | go | func (d *DNSProvider) getZone(domain string) (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("must be logged in to get zone")
}
return d.postRequest("dns-zone-get", url.Values{"domain": {dns01.UnFqdn(domain)}})
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"getZone",
"(",
"domain",
"string",
")",
"(",
"*",
"response",
",",
"error",
")",
"{",
"if",
"d",
".",
"config",
".",
"AuthSid",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"postRequest",
"(",
"\"",
"\"",
",",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"dns01",
".",
"UnFqdn",
"(",
"domain",
")",
"}",
"}",
")",
"\n",
"}"
] | // getZone returns content of DNS zone for domain | [
"getZone",
"returns",
"content",
"of",
"DNS",
"zone",
"for",
"domain"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L105-L111 | train |
go-acme/lego | providers/dns/joker/client.go | putZone | func (d *DNSProvider) putZone(domain, zone string) (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("must be logged in to put zone")
}
return d.postRequest("dns-zone-put", url.Values{"domain": {dns01.UnFqdn(domain)}, "zone": {strings.TrimSpace(zone)}})
} | go | func (d *DNSProvider) putZone(domain, zone string) (*response, error) {
if d.config.AuthSid == "" {
return nil, fmt.Errorf("must be logged in to put zone")
}
return d.postRequest("dns-zone-put", url.Values{"domain": {dns01.UnFqdn(domain)}, "zone": {strings.TrimSpace(zone)}})
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"putZone",
"(",
"domain",
",",
"zone",
"string",
")",
"(",
"*",
"response",
",",
"error",
")",
"{",
"if",
"d",
".",
"config",
".",
"AuthSid",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"postRequest",
"(",
"\"",
"\"",
",",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"dns01",
".",
"UnFqdn",
"(",
"domain",
")",
"}",
",",
"\"",
"\"",
":",
"{",
"strings",
".",
"TrimSpace",
"(",
"zone",
")",
"}",
"}",
")",
"\n",
"}"
] | // putZone uploads DNS zone to Joker DMAPI | [
"putZone",
"uploads",
"DNS",
"zone",
"to",
"Joker",
"DMAPI"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L114-L120 | train |
go-acme/lego | providers/dns/joker/client.go | postRequest | func (d *DNSProvider) postRequest(cmd string, data url.Values) (*response, error) {
uri := d.config.BaseURL + cmd
if d.config.AuthSid != "" {
data.Set("auth-sid", d.config.AuthSid)
}
if d.config.Debug {
log.Infof("postRequest:\n\tURL: %q\n\tData: %v", uri, data)
}
resp, err := d.config.HTTPClient.PostForm(uri, data)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body))
}
return parseResponse(string(body)), nil
} | go | func (d *DNSProvider) postRequest(cmd string, data url.Values) (*response, error) {
uri := d.config.BaseURL + cmd
if d.config.AuthSid != "" {
data.Set("auth-sid", d.config.AuthSid)
}
if d.config.Debug {
log.Infof("postRequest:\n\tURL: %q\n\tData: %v", uri, data)
}
resp, err := d.config.HTTPClient.PostForm(uri, data)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body))
}
return parseResponse(string(body)), nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"postRequest",
"(",
"cmd",
"string",
",",
"data",
"url",
".",
"Values",
")",
"(",
"*",
"response",
",",
"error",
")",
"{",
"uri",
":=",
"d",
".",
"config",
".",
"BaseURL",
"+",
"cmd",
"\n\n",
"if",
"d",
".",
"config",
".",
"AuthSid",
"!=",
"\"",
"\"",
"{",
"data",
".",
"Set",
"(",
"\"",
"\"",
",",
"d",
".",
"config",
".",
"AuthSid",
")",
"\n",
"}",
"\n\n",
"if",
"d",
".",
"config",
".",
"Debug",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\\n",
"\\t",
"\\n",
"\\t",
"\"",
",",
"uri",
",",
"data",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"d",
".",
"config",
".",
"HTTPClient",
".",
"PostForm",
"(",
"uri",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"200",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
",",
"http",
".",
"StatusText",
"(",
"resp",
".",
"StatusCode",
")",
",",
"string",
"(",
"body",
")",
")",
"\n",
"}",
"\n\n",
"return",
"parseResponse",
"(",
"string",
"(",
"body",
")",
")",
",",
"nil",
"\n",
"}"
] | // postRequest performs actual HTTP request | [
"postRequest",
"performs",
"actual",
"HTTP",
"request"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L123-L150 | train |
go-acme/lego | providers/dns/joker/client.go | fixTxtLines | func fixTxtLines(line string) string {
fields := strings.Fields(line)
if len(fields) < 6 || fields[1] != "TXT" {
return line
}
if fields[3][0] == '"' && fields[4] == `"` {
fields[3] = strings.TrimSpace(fields[3]) + `"`
fields = append(fields[:4], fields[5:]...)
}
return strings.Join(fields, " ")
} | go | func fixTxtLines(line string) string {
fields := strings.Fields(line)
if len(fields) < 6 || fields[1] != "TXT" {
return line
}
if fields[3][0] == '"' && fields[4] == `"` {
fields[3] = strings.TrimSpace(fields[3]) + `"`
fields = append(fields[:4], fields[5:]...)
}
return strings.Join(fields, " ")
} | [
"func",
"fixTxtLines",
"(",
"line",
"string",
")",
"string",
"{",
"fields",
":=",
"strings",
".",
"Fields",
"(",
"line",
")",
"\n\n",
"if",
"len",
"(",
"fields",
")",
"<",
"6",
"||",
"fields",
"[",
"1",
"]",
"!=",
"\"",
"\"",
"{",
"return",
"line",
"\n",
"}",
"\n\n",
"if",
"fields",
"[",
"3",
"]",
"[",
"0",
"]",
"==",
"'\"'",
"&&",
"fields",
"[",
"4",
"]",
"==",
"`\"`",
"{",
"fields",
"[",
"3",
"]",
"=",
"strings",
".",
"TrimSpace",
"(",
"fields",
"[",
"3",
"]",
")",
"+",
"`\"`",
"\n",
"fields",
"=",
"append",
"(",
"fields",
"[",
":",
"4",
"]",
",",
"fields",
"[",
"5",
":",
"]",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"fields",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Temporary workaround, until it get fixed on API side | [
"Temporary",
"workaround",
"until",
"it",
"get",
"fixed",
"on",
"API",
"side"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L153-L166 | train |
go-acme/lego | providers/dns/joker/client.go | removeTxtEntryFromZone | func removeTxtEntryFromZone(zone, relative string) (string, bool) {
prefix := fmt.Sprintf("%s TXT 0 ", relative)
modified := false
var zoneEntries []string
for _, line := range strings.Split(zone, "\n") {
if strings.HasPrefix(line, prefix) {
modified = true
continue
}
zoneEntries = append(zoneEntries, line)
}
return strings.TrimSpace(strings.Join(zoneEntries, "\n")), modified
} | go | func removeTxtEntryFromZone(zone, relative string) (string, bool) {
prefix := fmt.Sprintf("%s TXT 0 ", relative)
modified := false
var zoneEntries []string
for _, line := range strings.Split(zone, "\n") {
if strings.HasPrefix(line, prefix) {
modified = true
continue
}
zoneEntries = append(zoneEntries, line)
}
return strings.TrimSpace(strings.Join(zoneEntries, "\n")), modified
} | [
"func",
"removeTxtEntryFromZone",
"(",
"zone",
",",
"relative",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"prefix",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"relative",
")",
"\n\n",
"modified",
":=",
"false",
"\n",
"var",
"zoneEntries",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"zone",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"line",
",",
"prefix",
")",
"{",
"modified",
"=",
"true",
"\n",
"continue",
"\n",
"}",
"\n",
"zoneEntries",
"=",
"append",
"(",
"zoneEntries",
",",
"line",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"Join",
"(",
"zoneEntries",
",",
"\"",
"\\n",
"\"",
")",
")",
",",
"modified",
"\n",
"}"
] | // removeTxtEntryFromZone clean-ups all TXT records with given name | [
"removeTxtEntryFromZone",
"clean",
"-",
"ups",
"all",
"TXT",
"records",
"with",
"given",
"name"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L169-L183 | train |
go-acme/lego | providers/dns/joker/client.go | addTxtEntryToZone | func addTxtEntryToZone(zone, relative, value string, ttl int) string {
var zoneEntries []string
for _, line := range strings.Split(zone, "\n") {
zoneEntries = append(zoneEntries, fixTxtLines(line))
}
newZoneEntry := fmt.Sprintf("%s TXT 0 %q %d", relative, value, ttl)
zoneEntries = append(zoneEntries, newZoneEntry)
return strings.TrimSpace(strings.Join(zoneEntries, "\n"))
} | go | func addTxtEntryToZone(zone, relative, value string, ttl int) string {
var zoneEntries []string
for _, line := range strings.Split(zone, "\n") {
zoneEntries = append(zoneEntries, fixTxtLines(line))
}
newZoneEntry := fmt.Sprintf("%s TXT 0 %q %d", relative, value, ttl)
zoneEntries = append(zoneEntries, newZoneEntry)
return strings.TrimSpace(strings.Join(zoneEntries, "\n"))
} | [
"func",
"addTxtEntryToZone",
"(",
"zone",
",",
"relative",
",",
"value",
"string",
",",
"ttl",
"int",
")",
"string",
"{",
"var",
"zoneEntries",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"zone",
",",
"\"",
"\\n",
"\"",
")",
"{",
"zoneEntries",
"=",
"append",
"(",
"zoneEntries",
",",
"fixTxtLines",
"(",
"line",
")",
")",
"\n",
"}",
"\n\n",
"newZoneEntry",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"relative",
",",
"value",
",",
"ttl",
")",
"\n",
"zoneEntries",
"=",
"append",
"(",
"zoneEntries",
",",
"newZoneEntry",
")",
"\n\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"Join",
"(",
"zoneEntries",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}"
] | // addTxtEntryToZone returns DNS zone with added TXT record | [
"addTxtEntryToZone",
"returns",
"DNS",
"zone",
"with",
"added",
"TXT",
"record"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/client.go#L186-L197 | train |
go-acme/lego | providers/dns/glesys/glesys.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("glesys: the configuration of the DNS provider is nil")
}
if config.APIUser == "" || config.APIKey == "" {
return nil, fmt.Errorf("glesys: incomplete credentials provided")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("glesys: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
return &DNSProvider{
config: config,
activeRecords: make(map[string]int),
}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("glesys: the configuration of the DNS provider is nil")
}
if config.APIUser == "" || config.APIKey == "" {
return nil, fmt.Errorf("glesys: incomplete credentials provided")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("glesys: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
return &DNSProvider{
config: config,
activeRecords: make(map[string]int),
}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIUser",
"==",
"\"",
"\"",
"||",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"TTL",
"<",
"minTTL",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"TTL",
",",
"minTTL",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
",",
"activeRecords",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for GleSYS. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"GleSYS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/glesys/glesys.go#L70-L87 | train |
go-acme/lego | providers/dns/dnsimple/dnsimple.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dnsimple: the configuration of the DNS provider is nil")
}
if config.AccessToken == "" {
return nil, fmt.Errorf("dnsimple: OAuth token is missing")
}
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.AccessToken})
client := dnsimple.NewClient(oauth2.NewClient(context.Background(), ts))
if config.BaseURL != "" {
client.BaseURL = config.BaseURL
}
return &DNSProvider{client: client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dnsimple: the configuration of the DNS provider is nil")
}
if config.AccessToken == "" {
return nil, fmt.Errorf("dnsimple: OAuth token is missing")
}
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.AccessToken})
client := dnsimple.NewClient(oauth2.NewClient(context.Background(), ts))
if config.BaseURL != "" {
client.BaseURL = config.BaseURL
}
return &DNSProvider{client: client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"AccessToken",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ts",
":=",
"oauth2",
".",
"StaticTokenSource",
"(",
"&",
"oauth2",
".",
"Token",
"{",
"AccessToken",
":",
"config",
".",
"AccessToken",
"}",
")",
"\n",
"client",
":=",
"dnsimple",
".",
"NewClient",
"(",
"oauth2",
".",
"NewClient",
"(",
"context",
".",
"Background",
"(",
")",
",",
"ts",
")",
")",
"\n\n",
"if",
"config",
".",
"BaseURL",
"!=",
"\"",
"\"",
"{",
"client",
".",
"BaseURL",
"=",
"config",
".",
"BaseURL",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for DNSimple. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"DNSimple",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dnsimple/dnsimple.go#L55-L72 | train |
go-acme/lego | providers/dns/fastdns/fastdns.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("fastdns: the configuration of the DNS provider is nil")
}
if config.ClientToken == "" || config.ClientSecret == "" || config.AccessToken == "" || config.Host == "" {
return nil, fmt.Errorf("fastdns: credentials are missing")
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("fastdns: the configuration of the DNS provider is nil")
}
if config.ClientToken == "" || config.ClientSecret == "" || config.AccessToken == "" || config.Host == "" {
return nil, fmt.Errorf("fastdns: credentials are missing")
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"ClientToken",
"==",
"\"",
"\"",
"||",
"config",
".",
"ClientSecret",
"==",
"\"",
"\"",
"||",
"config",
".",
"AccessToken",
"==",
"\"",
"\"",
"||",
"config",
".",
"Host",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for FastDNS. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"FastDNS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/fastdns/fastdns.go#L59-L69 | train |
go-acme/lego | providers/dns/fastdns/fastdns.go | Present | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn, domain)
if err != nil {
return fmt.Errorf("fastdns: %v", err)
}
configdns.Init(d.config.Config)
zone, err := configdns.GetZone(zoneName)
if err != nil {
return fmt.Errorf("fastdns: %v", err)
}
record := configdns.NewTxtRecord()
_ = record.SetField("name", recordName)
_ = record.SetField("ttl", d.config.TTL)
_ = record.SetField("target", value)
_ = record.SetField("active", true)
for _, r := range zone.Zone.Txt {
if r != nil && reflect.DeepEqual(r.ToMap(), record.ToMap()) {
return nil
}
}
return d.createRecord(zone, record)
} | go | func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)
zoneName, recordName, err := d.findZoneAndRecordName(fqdn, domain)
if err != nil {
return fmt.Errorf("fastdns: %v", err)
}
configdns.Init(d.config.Config)
zone, err := configdns.GetZone(zoneName)
if err != nil {
return fmt.Errorf("fastdns: %v", err)
}
record := configdns.NewTxtRecord()
_ = record.SetField("name", recordName)
_ = record.SetField("ttl", d.config.TTL)
_ = record.SetField("target", value)
_ = record.SetField("active", true)
for _, r := range zone.Zone.Txt {
if r != nil && reflect.DeepEqual(r.ToMap(), record.ToMap()) {
return nil
}
}
return d.createRecord(zone, record)
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"Present",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"value",
":=",
"dns01",
".",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n",
"zoneName",
",",
"recordName",
",",
"err",
":=",
"d",
".",
"findZoneAndRecordName",
"(",
"fqdn",
",",
"domain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"configdns",
".",
"Init",
"(",
"d",
".",
"config",
".",
"Config",
")",
"\n\n",
"zone",
",",
"err",
":=",
"configdns",
".",
"GetZone",
"(",
"zoneName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"record",
":=",
"configdns",
".",
"NewTxtRecord",
"(",
")",
"\n",
"_",
"=",
"record",
".",
"SetField",
"(",
"\"",
"\"",
",",
"recordName",
")",
"\n",
"_",
"=",
"record",
".",
"SetField",
"(",
"\"",
"\"",
",",
"d",
".",
"config",
".",
"TTL",
")",
"\n",
"_",
"=",
"record",
".",
"SetField",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"_",
"=",
"record",
".",
"SetField",
"(",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"zone",
".",
"Zone",
".",
"Txt",
"{",
"if",
"r",
"!=",
"nil",
"&&",
"reflect",
".",
"DeepEqual",
"(",
"r",
".",
"ToMap",
"(",
")",
",",
"record",
".",
"ToMap",
"(",
")",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"createRecord",
"(",
"zone",
",",
"record",
")",
"\n",
"}"
] | // Present creates a TXT record to fullfil the dns-01 challenge. | [
"Present",
"creates",
"a",
"TXT",
"record",
"to",
"fullfil",
"the",
"dns",
"-",
"01",
"challenge",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/fastdns/fastdns.go#L72-L99 | train |
go-acme/lego | providers/dns/oraclecloud/oraclecloud.go | NewDNSProvider | func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(ociPrivkey, ociTenancyOCID, ociUserOCID, ociPubkeyFingerprint, ociRegion, "OCI_COMPARTMENT_OCID")
if err != nil {
return nil, fmt.Errorf("oraclecloud: %v", err)
}
config := NewDefaultConfig()
config.CompartmentID = values["OCI_COMPARTMENT_OCID"]
config.OCIConfigProvider = newConfigProvider(values)
return NewDNSProviderConfig(config)
} | go | func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(ociPrivkey, ociTenancyOCID, ociUserOCID, ociPubkeyFingerprint, ociRegion, "OCI_COMPARTMENT_OCID")
if err != nil {
return nil, fmt.Errorf("oraclecloud: %v", err)
}
config := NewDefaultConfig()
config.CompartmentID = values["OCI_COMPARTMENT_OCID"]
config.OCIConfigProvider = newConfigProvider(values)
return NewDNSProviderConfig(config)
} | [
"func",
"NewDNSProvider",
"(",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"values",
",",
"err",
":=",
"env",
".",
"Get",
"(",
"ociPrivkey",
",",
"ociTenancyOCID",
",",
"ociUserOCID",
",",
"ociPubkeyFingerprint",
",",
"ociRegion",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"config",
":=",
"NewDefaultConfig",
"(",
")",
"\n",
"config",
".",
"CompartmentID",
"=",
"values",
"[",
"\"",
"\"",
"]",
"\n",
"config",
".",
"OCIConfigProvider",
"=",
"newConfigProvider",
"(",
"values",
")",
"\n\n",
"return",
"NewDNSProviderConfig",
"(",
"config",
")",
"\n",
"}"
] | // NewDNSProvider returns a DNSProvider instance configured for OracleCloud. | [
"NewDNSProvider",
"returns",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"OracleCloud",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/oraclecloud/oraclecloud.go#L45-L56 | train |
go-acme/lego | providers/dns/oraclecloud/oraclecloud.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("oraclecloud: the configuration of the DNS provider is nil")
}
if config.CompartmentID == "" {
return nil, errors.New("oraclecloud: CompartmentID is missing")
}
if config.OCIConfigProvider == nil {
return nil, errors.New("oraclecloud: OCIConfigProvider is missing")
}
client, err := dns.NewDnsClientWithConfigurationProvider(config.OCIConfigProvider)
if err != nil {
return nil, fmt.Errorf("oraclecloud: %v", err)
}
if config.HTTPClient != nil {
client.HTTPClient = config.HTTPClient
}
return &DNSProvider{client: &client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("oraclecloud: the configuration of the DNS provider is nil")
}
if config.CompartmentID == "" {
return nil, errors.New("oraclecloud: CompartmentID is missing")
}
if config.OCIConfigProvider == nil {
return nil, errors.New("oraclecloud: OCIConfigProvider is missing")
}
client, err := dns.NewDnsClientWithConfigurationProvider(config.OCIConfigProvider)
if err != nil {
return nil, fmt.Errorf("oraclecloud: %v", err)
}
if config.HTTPClient != nil {
client.HTTPClient = config.HTTPClient
}
return &DNSProvider{client: &client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"CompartmentID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"OCIConfigProvider",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"dns",
".",
"NewDnsClientWithConfigurationProvider",
"(",
"config",
".",
"OCIConfigProvider",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"HTTPClient",
"!=",
"nil",
"{",
"client",
".",
"HTTPClient",
"=",
"config",
".",
"HTTPClient",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"&",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for OracleCloud. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"OracleCloud",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/oraclecloud/oraclecloud.go#L59-L82 | train |
go-acme/lego | providers/dns/nifcloud/internal/client.go | NewClient | func NewClient(accessKey string, secretKey string) (*Client, error) {
if len(accessKey) == 0 || len(secretKey) == 0 {
return nil, errors.New("credentials missing")
}
return &Client{
accessKey: accessKey,
secretKey: secretKey,
BaseURL: defaultBaseURL,
HTTPClient: &http.Client{},
}, nil
} | go | func NewClient(accessKey string, secretKey string) (*Client, error) {
if len(accessKey) == 0 || len(secretKey) == 0 {
return nil, errors.New("credentials missing")
}
return &Client{
accessKey: accessKey,
secretKey: secretKey,
BaseURL: defaultBaseURL,
HTTPClient: &http.Client{},
}, nil
} | [
"func",
"NewClient",
"(",
"accessKey",
"string",
",",
"secretKey",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"len",
"(",
"accessKey",
")",
"==",
"0",
"||",
"len",
"(",
"secretKey",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"accessKey",
":",
"accessKey",
",",
"secretKey",
":",
"secretKey",
",",
"BaseURL",
":",
"defaultBaseURL",
",",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewClient Creates a new client of NIFCLOUD DNS | [
"NewClient",
"Creates",
"a",
"new",
"client",
"of",
"NIFCLOUD",
"DNS"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/nifcloud/internal/client.go#L91-L102 | train |
go-acme/lego | providers/dns/nifcloud/internal/client.go | ChangeResourceRecordSets | func (c *Client) ChangeResourceRecordSets(hostedZoneID string, input ChangeResourceRecordSetsRequest) (*ChangeResourceRecordSetsResponse, error) {
requestURL := fmt.Sprintf("%s/%s/hostedzone/%s/rrset", c.BaseURL, apiVersion, hostedZoneID)
body := &bytes.Buffer{}
body.Write([]byte(xml.Header))
err := xml.NewEncoder(body).Encode(input)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, requestURL, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "text/xml; charset=utf-8")
err = c.sign(req)
if err != nil {
return nil, fmt.Errorf("an error occurred during the creation of the signature: %v", err)
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if res.Body == nil {
return nil, errors.New("the response body is nil")
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
errResp := &ErrorResponse{}
err = xml.NewDecoder(res.Body).Decode(errResp)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the error body to XML: %v", err)
}
return nil, fmt.Errorf("an error occurred: %s", errResp.Error.Message)
}
output := &ChangeResourceRecordSetsResponse{}
err = xml.NewDecoder(res.Body).Decode(output)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the response body to XML: %v", err)
}
return output, err
} | go | func (c *Client) ChangeResourceRecordSets(hostedZoneID string, input ChangeResourceRecordSetsRequest) (*ChangeResourceRecordSetsResponse, error) {
requestURL := fmt.Sprintf("%s/%s/hostedzone/%s/rrset", c.BaseURL, apiVersion, hostedZoneID)
body := &bytes.Buffer{}
body.Write([]byte(xml.Header))
err := xml.NewEncoder(body).Encode(input)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, requestURL, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "text/xml; charset=utf-8")
err = c.sign(req)
if err != nil {
return nil, fmt.Errorf("an error occurred during the creation of the signature: %v", err)
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if res.Body == nil {
return nil, errors.New("the response body is nil")
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
errResp := &ErrorResponse{}
err = xml.NewDecoder(res.Body).Decode(errResp)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the error body to XML: %v", err)
}
return nil, fmt.Errorf("an error occurred: %s", errResp.Error.Message)
}
output := &ChangeResourceRecordSetsResponse{}
err = xml.NewDecoder(res.Body).Decode(output)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the response body to XML: %v", err)
}
return output, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ChangeResourceRecordSets",
"(",
"hostedZoneID",
"string",
",",
"input",
"ChangeResourceRecordSetsRequest",
")",
"(",
"*",
"ChangeResourceRecordSetsResponse",
",",
"error",
")",
"{",
"requestURL",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"BaseURL",
",",
"apiVersion",
",",
"hostedZoneID",
")",
"\n\n",
"body",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"body",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"xml",
".",
"Header",
")",
")",
"\n",
"err",
":=",
"xml",
".",
"NewEncoder",
"(",
"body",
")",
".",
"Encode",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodPost",
",",
"requestURL",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"err",
"=",
"c",
".",
"sign",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"res",
".",
"Body",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"defer",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"errResp",
":=",
"&",
"ErrorResponse",
"{",
"}",
"\n",
"err",
"=",
"xml",
".",
"NewDecoder",
"(",
"res",
".",
"Body",
")",
".",
"Decode",
"(",
"errResp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errResp",
".",
"Error",
".",
"Message",
")",
"\n",
"}",
"\n\n",
"output",
":=",
"&",
"ChangeResourceRecordSetsResponse",
"{",
"}",
"\n",
"err",
"=",
"xml",
".",
"NewDecoder",
"(",
"res",
".",
"Body",
")",
".",
"Decode",
"(",
"output",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"output",
",",
"err",
"\n",
"}"
] | // ChangeResourceRecordSets Call ChangeResourceRecordSets API and return response. | [
"ChangeResourceRecordSets",
"Call",
"ChangeResourceRecordSets",
"API",
"and",
"return",
"response",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/nifcloud/internal/client.go#L113-L162 | train |
go-acme/lego | providers/dns/nifcloud/internal/client.go | GetChange | func (c *Client) GetChange(statusID string) (*GetChangeResponse, error) {
requestURL := fmt.Sprintf("%s/%s/change/%s", c.BaseURL, apiVersion, statusID)
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
if err != nil {
return nil, err
}
err = c.sign(req)
if err != nil {
return nil, fmt.Errorf("an error occurred during the creation of the signature: %v", err)
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if res.Body == nil {
return nil, errors.New("the response body is nil")
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
errResp := &ErrorResponse{}
err = xml.NewDecoder(res.Body).Decode(errResp)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the error body to XML: %v", err)
}
return nil, fmt.Errorf("an error occurred: %s", errResp.Error.Message)
}
output := &GetChangeResponse{}
err = xml.NewDecoder(res.Body).Decode(output)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the response body to XML: %v", err)
}
return output, nil
} | go | func (c *Client) GetChange(statusID string) (*GetChangeResponse, error) {
requestURL := fmt.Sprintf("%s/%s/change/%s", c.BaseURL, apiVersion, statusID)
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
if err != nil {
return nil, err
}
err = c.sign(req)
if err != nil {
return nil, fmt.Errorf("an error occurred during the creation of the signature: %v", err)
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if res.Body == nil {
return nil, errors.New("the response body is nil")
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
errResp := &ErrorResponse{}
err = xml.NewDecoder(res.Body).Decode(errResp)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the error body to XML: %v", err)
}
return nil, fmt.Errorf("an error occurred: %s", errResp.Error.Message)
}
output := &GetChangeResponse{}
err = xml.NewDecoder(res.Body).Decode(output)
if err != nil {
return nil, fmt.Errorf("an error occurred while unmarshaling the response body to XML: %v", err)
}
return output, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetChange",
"(",
"statusID",
"string",
")",
"(",
"*",
"GetChangeResponse",
",",
"error",
")",
"{",
"requestURL",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"BaseURL",
",",
"apiVersion",
",",
"statusID",
")",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"requestURL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"sign",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"res",
".",
"Body",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"defer",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"errResp",
":=",
"&",
"ErrorResponse",
"{",
"}",
"\n",
"err",
"=",
"xml",
".",
"NewDecoder",
"(",
"res",
".",
"Body",
")",
".",
"Decode",
"(",
"errResp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errResp",
".",
"Error",
".",
"Message",
")",
"\n",
"}",
"\n\n",
"output",
":=",
"&",
"GetChangeResponse",
"{",
"}",
"\n",
"err",
"=",
"xml",
".",
"NewDecoder",
"(",
"res",
".",
"Body",
")",
".",
"Decode",
"(",
"output",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"output",
",",
"nil",
"\n",
"}"
] | // GetChange Call GetChange API and return response. | [
"GetChange",
"Call",
"GetChange",
"API",
"and",
"return",
"response",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/nifcloud/internal/client.go#L165-L205 | train |
go-acme/lego | platform/config/env/env.go | Get | func Get(names ...string) (map[string]string, error) {
values := map[string]string{}
var missingEnvVars []string
for _, envVar := range names {
value := GetOrFile(envVar)
if value == "" {
missingEnvVars = append(missingEnvVars, envVar)
}
values[envVar] = value
}
if len(missingEnvVars) > 0 {
return nil, fmt.Errorf("some credentials information are missing: %s", strings.Join(missingEnvVars, ","))
}
return values, nil
} | go | func Get(names ...string) (map[string]string, error) {
values := map[string]string{}
var missingEnvVars []string
for _, envVar := range names {
value := GetOrFile(envVar)
if value == "" {
missingEnvVars = append(missingEnvVars, envVar)
}
values[envVar] = value
}
if len(missingEnvVars) > 0 {
return nil, fmt.Errorf("some credentials information are missing: %s", strings.Join(missingEnvVars, ","))
}
return values, nil
} | [
"func",
"Get",
"(",
"names",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"values",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n\n",
"var",
"missingEnvVars",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"envVar",
":=",
"range",
"names",
"{",
"value",
":=",
"GetOrFile",
"(",
"envVar",
")",
"\n",
"if",
"value",
"==",
"\"",
"\"",
"{",
"missingEnvVars",
"=",
"append",
"(",
"missingEnvVars",
",",
"envVar",
")",
"\n",
"}",
"\n",
"values",
"[",
"envVar",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"missingEnvVars",
")",
">",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"missingEnvVars",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"return",
"values",
",",
"nil",
"\n",
"}"
] | // Get environment variables | [
"Get",
"environment",
"variables"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/platform/config/env/env.go#L16-L33 | train |
go-acme/lego | platform/config/env/env.go | GetOrDefaultInt | func GetOrDefaultInt(envVar string, defaultValue int) int {
v, err := strconv.Atoi(GetOrFile(envVar))
if err != nil {
return defaultValue
}
return v
} | go | func GetOrDefaultInt(envVar string, defaultValue int) int {
v, err := strconv.Atoi(GetOrFile(envVar))
if err != nil {
return defaultValue
}
return v
} | [
"func",
"GetOrDefaultInt",
"(",
"envVar",
"string",
",",
"defaultValue",
"int",
")",
"int",
"{",
"v",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"GetOrFile",
"(",
"envVar",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaultValue",
"\n",
"}",
"\n\n",
"return",
"v",
"\n",
"}"
] | // GetOrDefaultInt returns the given environment variable value as an integer.
// Returns the default if the envvar cannot be coopered to an int, or is not found. | [
"GetOrDefaultInt",
"returns",
"the",
"given",
"environment",
"variable",
"value",
"as",
"an",
"integer",
".",
"Returns",
"the",
"default",
"if",
"the",
"envvar",
"cannot",
"be",
"coopered",
"to",
"an",
"int",
"or",
"is",
"not",
"found",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/platform/config/env/env.go#L99-L106 | train |
go-acme/lego | platform/config/env/env.go | GetOrDefaultString | func GetOrDefaultString(envVar string, defaultValue string) string {
v := GetOrFile(envVar)
if len(v) == 0 {
return defaultValue
}
return v
} | go | func GetOrDefaultString(envVar string, defaultValue string) string {
v := GetOrFile(envVar)
if len(v) == 0 {
return defaultValue
}
return v
} | [
"func",
"GetOrDefaultString",
"(",
"envVar",
"string",
",",
"defaultValue",
"string",
")",
"string",
"{",
"v",
":=",
"GetOrFile",
"(",
"envVar",
")",
"\n",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{",
"return",
"defaultValue",
"\n",
"}",
"\n\n",
"return",
"v",
"\n",
"}"
] | // GetOrDefaultString returns the given environment variable value as a string.
// Returns the default if the envvar cannot be find. | [
"GetOrDefaultString",
"returns",
"the",
"given",
"environment",
"variable",
"value",
"as",
"a",
"string",
".",
"Returns",
"the",
"default",
"if",
"the",
"envvar",
"cannot",
"be",
"find",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/platform/config/env/env.go#L121-L128 | train |
go-acme/lego | platform/config/env/env.go | GetOrDefaultBool | func GetOrDefaultBool(envVar string, defaultValue bool) bool {
v, err := strconv.ParseBool(GetOrFile(envVar))
if err != nil {
return defaultValue
}
return v
} | go | func GetOrDefaultBool(envVar string, defaultValue bool) bool {
v, err := strconv.ParseBool(GetOrFile(envVar))
if err != nil {
return defaultValue
}
return v
} | [
"func",
"GetOrDefaultBool",
"(",
"envVar",
"string",
",",
"defaultValue",
"bool",
")",
"bool",
"{",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"GetOrFile",
"(",
"envVar",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaultValue",
"\n",
"}",
"\n\n",
"return",
"v",
"\n",
"}"
] | // GetOrDefaultBool returns the given environment variable value as a boolean.
// Returns the default if the envvar cannot be coopered to a boolean, or is not found. | [
"GetOrDefaultBool",
"returns",
"the",
"given",
"environment",
"variable",
"value",
"as",
"a",
"boolean",
".",
"Returns",
"the",
"default",
"if",
"the",
"envvar",
"cannot",
"be",
"coopered",
"to",
"a",
"boolean",
"or",
"is",
"not",
"found",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/platform/config/env/env.go#L132-L139 | train |
go-acme/lego | providers/dns/duckdns/duckdns.go | CleanUp | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return d.updateTxtRecord(domain, d.config.Token, "", true)
} | go | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return d.updateTxtRecord(domain, d.config.Token, "", true)
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"CleanUp",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"return",
"d",
".",
"updateTxtRecord",
"(",
"domain",
",",
"d",
".",
"config",
".",
"Token",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"}"
] | // CleanUp clears DuckDNS TXT record | [
"CleanUp",
"clears",
"DuckDNS",
"TXT",
"record"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/duckdns/duckdns.go#L75-L77 | train |
go-acme/lego | cmd/setup.go | getKeyType | func getKeyType(ctx *cli.Context) certcrypto.KeyType {
keyType := ctx.GlobalString("key-type")
switch strings.ToUpper(keyType) {
case "RSA2048":
return certcrypto.RSA2048
case "RSA4096":
return certcrypto.RSA4096
case "RSA8192":
return certcrypto.RSA8192
case "EC256":
return certcrypto.EC256
case "EC384":
return certcrypto.EC384
}
log.Fatalf("Unsupported KeyType: %s", keyType)
return ""
} | go | func getKeyType(ctx *cli.Context) certcrypto.KeyType {
keyType := ctx.GlobalString("key-type")
switch strings.ToUpper(keyType) {
case "RSA2048":
return certcrypto.RSA2048
case "RSA4096":
return certcrypto.RSA4096
case "RSA8192":
return certcrypto.RSA8192
case "EC256":
return certcrypto.EC256
case "EC384":
return certcrypto.EC384
}
log.Fatalf("Unsupported KeyType: %s", keyType)
return ""
} | [
"func",
"getKeyType",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"certcrypto",
".",
"KeyType",
"{",
"keyType",
":=",
"ctx",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
"\n",
"switch",
"strings",
".",
"ToUpper",
"(",
"keyType",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"certcrypto",
".",
"RSA2048",
"\n",
"case",
"\"",
"\"",
":",
"return",
"certcrypto",
".",
"RSA4096",
"\n",
"case",
"\"",
"\"",
":",
"return",
"certcrypto",
".",
"RSA8192",
"\n",
"case",
"\"",
"\"",
":",
"return",
"certcrypto",
".",
"EC256",
"\n",
"case",
"\"",
"\"",
":",
"return",
"certcrypto",
".",
"EC384",
"\n",
"}",
"\n\n",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"keyType",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // getKeyType the type from which private keys should be generated | [
"getKeyType",
"the",
"type",
"from",
"which",
"private",
"keys",
"should",
"be",
"generated"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/cmd/setup.go#L64-L81 | train |
go-acme/lego | providers/dns/dnspod/dnspod.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dnspod: the configuration of the DNS provider is nil")
}
if config.LoginToken == "" {
return nil, fmt.Errorf("dnspod: credentials missing")
}
params := dnspod.CommonParams{LoginToken: config.LoginToken, Format: "json"}
client := dnspod.NewClient(params)
client.HttpClient = config.HTTPClient
return &DNSProvider{client: client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dnspod: the configuration of the DNS provider is nil")
}
if config.LoginToken == "" {
return nil, fmt.Errorf("dnspod: credentials missing")
}
params := dnspod.CommonParams{LoginToken: config.LoginToken, Format: "json"}
client := dnspod.NewClient(params)
client.HttpClient = config.HTTPClient
return &DNSProvider{client: client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"LoginToken",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"params",
":=",
"dnspod",
".",
"CommonParams",
"{",
"LoginToken",
":",
"config",
".",
"LoginToken",
",",
"Format",
":",
"\"",
"\"",
"}",
"\n\n",
"client",
":=",
"dnspod",
".",
"NewClient",
"(",
"params",
")",
"\n",
"client",
".",
"HttpClient",
"=",
"config",
".",
"HTTPClient",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for dnspod. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"dnspod",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dnspod/dnspod.go#L59-L74 | train |
go-acme/lego | challenge/tlsalpn01/tls_alpn_challenge_server.go | Present | func (s *ProviderServer) Present(domain, token, keyAuth string) error {
if s.port == "" {
// Fallback to port 443 if the port was not provided.
s.port = defaultTLSPort
}
// Generate the challenge certificate using the provided keyAuth and domain.
cert, err := ChallengeCert(domain, keyAuth)
if err != nil {
return err
}
// Place the generated certificate with the extension into the TLS config
// so that it can serve the correct details.
tlsConf := new(tls.Config)
tlsConf.Certificates = []tls.Certificate{*cert}
// We must set that the `acme-tls/1` application level protocol is supported
// so that the protocol negotiation can succeed. Reference:
// https://tools.ietf.org/html/draft-ietf-acme-tls-alpn-01#section-5.2
tlsConf.NextProtos = []string{ACMETLS1Protocol}
// Create the listener with the created tls.Config.
s.listener, err = tls.Listen("tcp", s.GetAddress(), tlsConf)
if err != nil {
return fmt.Errorf("could not start HTTPS server for challenge -> %v", err)
}
// Shut the server down when we're finished.
go func() {
err := http.Serve(s.listener, nil)
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
log.Println(err)
}
}()
return nil
} | go | func (s *ProviderServer) Present(domain, token, keyAuth string) error {
if s.port == "" {
// Fallback to port 443 if the port was not provided.
s.port = defaultTLSPort
}
// Generate the challenge certificate using the provided keyAuth and domain.
cert, err := ChallengeCert(domain, keyAuth)
if err != nil {
return err
}
// Place the generated certificate with the extension into the TLS config
// so that it can serve the correct details.
tlsConf := new(tls.Config)
tlsConf.Certificates = []tls.Certificate{*cert}
// We must set that the `acme-tls/1` application level protocol is supported
// so that the protocol negotiation can succeed. Reference:
// https://tools.ietf.org/html/draft-ietf-acme-tls-alpn-01#section-5.2
tlsConf.NextProtos = []string{ACMETLS1Protocol}
// Create the listener with the created tls.Config.
s.listener, err = tls.Listen("tcp", s.GetAddress(), tlsConf)
if err != nil {
return fmt.Errorf("could not start HTTPS server for challenge -> %v", err)
}
// Shut the server down when we're finished.
go func() {
err := http.Serve(s.listener, nil)
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
log.Println(err)
}
}()
return nil
} | [
"func",
"(",
"s",
"*",
"ProviderServer",
")",
"Present",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"if",
"s",
".",
"port",
"==",
"\"",
"\"",
"{",
"// Fallback to port 443 if the port was not provided.",
"s",
".",
"port",
"=",
"defaultTLSPort",
"\n",
"}",
"\n\n",
"// Generate the challenge certificate using the provided keyAuth and domain.",
"cert",
",",
"err",
":=",
"ChallengeCert",
"(",
"domain",
",",
"keyAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Place the generated certificate with the extension into the TLS config",
"// so that it can serve the correct details.",
"tlsConf",
":=",
"new",
"(",
"tls",
".",
"Config",
")",
"\n",
"tlsConf",
".",
"Certificates",
"=",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"*",
"cert",
"}",
"\n\n",
"// We must set that the `acme-tls/1` application level protocol is supported",
"// so that the protocol negotiation can succeed. Reference:",
"// https://tools.ietf.org/html/draft-ietf-acme-tls-alpn-01#section-5.2",
"tlsConf",
".",
"NextProtos",
"=",
"[",
"]",
"string",
"{",
"ACMETLS1Protocol",
"}",
"\n\n",
"// Create the listener with the created tls.Config.",
"s",
".",
"listener",
",",
"err",
"=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"s",
".",
"GetAddress",
"(",
")",
",",
"tlsConf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Shut the server down when we're finished.",
"go",
"func",
"(",
")",
"{",
"err",
":=",
"http",
".",
"Serve",
"(",
"s",
".",
"listener",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"log",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Present generates a certificate with a SHA-256 digest of the keyAuth provided
// as the acmeValidation-v1 extension value to conform to the ACME-TLS-ALPN spec. | [
"Present",
"generates",
"a",
"certificate",
"with",
"a",
"SHA",
"-",
"256",
"digest",
"of",
"the",
"keyAuth",
"provided",
"as",
"the",
"acmeValidation",
"-",
"v1",
"extension",
"value",
"to",
"conform",
"to",
"the",
"ACME",
"-",
"TLS",
"-",
"ALPN",
"spec",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/tlsalpn01/tls_alpn_challenge_server.go#L44-L81 | train |
go-acme/lego | challenge/tlsalpn01/tls_alpn_challenge_server.go | CleanUp | func (s *ProviderServer) CleanUp(domain, token, keyAuth string) error {
if s.listener == nil {
return nil
}
// Server was created, close it.
if err := s.listener.Close(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
} | go | func (s *ProviderServer) CleanUp(domain, token, keyAuth string) error {
if s.listener == nil {
return nil
}
// Server was created, close it.
if err := s.listener.Close(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
} | [
"func",
"(",
"s",
"*",
"ProviderServer",
")",
"CleanUp",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"if",
"s",
".",
"listener",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Server was created, close it.",
"if",
"err",
":=",
"s",
".",
"listener",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"http",
".",
"ErrServerClosed",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CleanUp closes the HTTPS server. | [
"CleanUp",
"closes",
"the",
"HTTPS",
"server",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/tlsalpn01/tls_alpn_challenge_server.go#L84-L95 | train |
go-acme/lego | providers/dns/netcup/internal/client.go | NewClient | func NewClient(customerNumber string, apiKey string, apiPassword string) (*Client, error) {
if customerNumber == "" || apiKey == "" || apiPassword == "" {
return nil, fmt.Errorf("credentials missing")
}
return &Client{
customerNumber: customerNumber,
apiKey: apiKey,
apiPassword: apiPassword,
BaseURL: defaultBaseURL,
HTTPClient: &http.Client{
Timeout: 10 * time.Second,
},
}, nil
} | go | func NewClient(customerNumber string, apiKey string, apiPassword string) (*Client, error) {
if customerNumber == "" || apiKey == "" || apiPassword == "" {
return nil, fmt.Errorf("credentials missing")
}
return &Client{
customerNumber: customerNumber,
apiKey: apiKey,
apiPassword: apiPassword,
BaseURL: defaultBaseURL,
HTTPClient: &http.Client{
Timeout: 10 * time.Second,
},
}, nil
} | [
"func",
"NewClient",
"(",
"customerNumber",
"string",
",",
"apiKey",
"string",
",",
"apiPassword",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"customerNumber",
"==",
"\"",
"\"",
"||",
"apiKey",
"==",
"\"",
"\"",
"||",
"apiPassword",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"customerNumber",
":",
"customerNumber",
",",
"apiKey",
":",
"apiKey",
",",
"apiPassword",
":",
"apiPassword",
",",
"BaseURL",
":",
"defaultBaseURL",
",",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"Timeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewClient creates a netcup DNS client | [
"NewClient",
"creates",
"a",
"netcup",
"DNS",
"client"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/netcup/internal/client.go#L124-L138 | train |
go-acme/lego | providers/dns/netcup/internal/client.go | doRequest | func (c *Client) doRequest(payload interface{}, responseData interface{}) error {
body, err := json.Marshal(payload)
if err != nil {
return err
}
req, err := http.NewRequest(http.MethodPost, c.BaseURL, bytes.NewReader(body))
if err != nil {
return err
}
req.Close = true
req.Header.Set("content-type", "application/json")
resp, err := c.HTTPClient.Do(req)
if err != nil {
return err
}
if err = checkResponse(resp); err != nil {
return err
}
respMsg, err := decodeResponseMsg(resp)
if err != nil {
return err
}
if respMsg.Status != success {
return respMsg
}
if responseData != nil {
err = json.Unmarshal(respMsg.ResponseData, responseData)
if err != nil {
return fmt.Errorf("%v: unmarshaling %T error: %v: %s",
respMsg, responseData, err, string(respMsg.ResponseData))
}
}
return nil
} | go | func (c *Client) doRequest(payload interface{}, responseData interface{}) error {
body, err := json.Marshal(payload)
if err != nil {
return err
}
req, err := http.NewRequest(http.MethodPost, c.BaseURL, bytes.NewReader(body))
if err != nil {
return err
}
req.Close = true
req.Header.Set("content-type", "application/json")
resp, err := c.HTTPClient.Do(req)
if err != nil {
return err
}
if err = checkResponse(resp); err != nil {
return err
}
respMsg, err := decodeResponseMsg(resp)
if err != nil {
return err
}
if respMsg.Status != success {
return respMsg
}
if responseData != nil {
err = json.Unmarshal(respMsg.ResponseData, responseData)
if err != nil {
return fmt.Errorf("%v: unmarshaling %T error: %v: %s",
respMsg, responseData, err, string(respMsg.ResponseData))
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"doRequest",
"(",
"payload",
"interface",
"{",
"}",
",",
"responseData",
"interface",
"{",
"}",
")",
"error",
"{",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodPost",
",",
"c",
".",
"BaseURL",
",",
"bytes",
".",
"NewReader",
"(",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Close",
"=",
"true",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"checkResponse",
"(",
"resp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"respMsg",
",",
"err",
":=",
"decodeResponseMsg",
"(",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"respMsg",
".",
"Status",
"!=",
"success",
"{",
"return",
"respMsg",
"\n",
"}",
"\n\n",
"if",
"responseData",
"!=",
"nil",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"respMsg",
".",
"ResponseData",
",",
"responseData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"respMsg",
",",
"responseData",
",",
"err",
",",
"string",
"(",
"respMsg",
".",
"ResponseData",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // doRequest marshals given body to JSON, send the request to netcup API
// and returns body of response | [
"doRequest",
"marshals",
"given",
"body",
"to",
"JSON",
"send",
"the",
"request",
"to",
"netcup",
"API",
"and",
"returns",
"body",
"of",
"response"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/netcup/internal/client.go#L234-L275 | train |
go-acme/lego | providers/dns/netcup/internal/client.go | GetDNSRecordIdx | func GetDNSRecordIdx(records []DNSRecord, record DNSRecord) (int, error) {
for index, element := range records {
if record.Destination == element.Destination && record.RecordType == element.RecordType {
return index, nil
}
}
return -1, fmt.Errorf("no DNS Record found")
} | go | func GetDNSRecordIdx(records []DNSRecord, record DNSRecord) (int, error) {
for index, element := range records {
if record.Destination == element.Destination && record.RecordType == element.RecordType {
return index, nil
}
}
return -1, fmt.Errorf("no DNS Record found")
} | [
"func",
"GetDNSRecordIdx",
"(",
"records",
"[",
"]",
"DNSRecord",
",",
"record",
"DNSRecord",
")",
"(",
"int",
",",
"error",
")",
"{",
"for",
"index",
",",
"element",
":=",
"range",
"records",
"{",
"if",
"record",
".",
"Destination",
"==",
"element",
".",
"Destination",
"&&",
"record",
".",
"RecordType",
"==",
"element",
".",
"RecordType",
"{",
"return",
"index",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // GetDNSRecordIdx searches a given array of DNSRecords for a given DNSRecord
// equivalence is determined by Destination and RecortType attributes
// returns index of given DNSRecord in given array of DNSRecords | [
"GetDNSRecordIdx",
"searches",
"a",
"given",
"array",
"of",
"DNSRecords",
"for",
"a",
"given",
"DNSRecord",
"equivalence",
"is",
"determined",
"by",
"Destination",
"and",
"RecortType",
"attributes",
"returns",
"index",
"of",
"given",
"DNSRecord",
"in",
"given",
"array",
"of",
"DNSRecords"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/netcup/internal/client.go#L320-L327 | train |
go-acme/lego | providers/dns/vscale/internal/client.go | NewClient | func NewClient(opts ClientOpts) *Client {
if opts.HTTPClient == nil {
opts.HTTPClient = &http.Client{}
}
return &Client{
token: opts.Token,
baseURL: opts.BaseURL,
httpClient: opts.HTTPClient,
userAgent: opts.UserAgent,
}
} | go | func NewClient(opts ClientOpts) *Client {
if opts.HTTPClient == nil {
opts.HTTPClient = &http.Client{}
}
return &Client{
token: opts.Token,
baseURL: opts.BaseURL,
httpClient: opts.HTTPClient,
userAgent: opts.UserAgent,
}
} | [
"func",
"NewClient",
"(",
"opts",
"ClientOpts",
")",
"*",
"Client",
"{",
"if",
"opts",
".",
"HTTPClient",
"==",
"nil",
"{",
"opts",
".",
"HTTPClient",
"=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"token",
":",
"opts",
".",
"Token",
",",
"baseURL",
":",
"opts",
".",
"BaseURL",
",",
"httpClient",
":",
"opts",
".",
"HTTPClient",
",",
"userAgent",
":",
"opts",
".",
"UserAgent",
",",
"}",
"\n",
"}"
] | // NewClient returns a client instance. | [
"NewClient",
"returns",
"a",
"client",
"instance",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vscale/internal/client.go#L56-L67 | train |
go-acme/lego | providers/dns/vscale/internal/client.go | GetDomainByName | func (c *Client) GetDomainByName(domainName string) (*Domain, error) {
uri := fmt.Sprintf("/%s", domainName)
req, err := c.newRequest(http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
domain := &Domain{}
resp, err := c.do(req, domain)
if err != nil {
switch {
case resp.StatusCode == http.StatusNotFound && strings.Count(domainName, ".") > 1:
// Look up for the next sub domain
subIndex := strings.Index(domainName, ".")
return c.GetDomainByName(domainName[subIndex+1:])
default:
return nil, err
}
}
return domain, nil
} | go | func (c *Client) GetDomainByName(domainName string) (*Domain, error) {
uri := fmt.Sprintf("/%s", domainName)
req, err := c.newRequest(http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
domain := &Domain{}
resp, err := c.do(req, domain)
if err != nil {
switch {
case resp.StatusCode == http.StatusNotFound && strings.Count(domainName, ".") > 1:
// Look up for the next sub domain
subIndex := strings.Index(domainName, ".")
return c.GetDomainByName(domainName[subIndex+1:])
default:
return nil, err
}
}
return domain, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDomainByName",
"(",
"domainName",
"string",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainName",
")",
"\n",
"req",
",",
"err",
":=",
"c",
".",
"newRequest",
"(",
"http",
".",
"MethodGet",
",",
"uri",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"domain",
":=",
"&",
"Domain",
"{",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"do",
"(",
"req",
",",
"domain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"switch",
"{",
"case",
"resp",
".",
"StatusCode",
"==",
"http",
".",
"StatusNotFound",
"&&",
"strings",
".",
"Count",
"(",
"domainName",
",",
"\"",
"\"",
")",
">",
"1",
":",
"// Look up for the next sub domain",
"subIndex",
":=",
"strings",
".",
"Index",
"(",
"domainName",
",",
"\"",
"\"",
")",
"\n",
"return",
"c",
".",
"GetDomainByName",
"(",
"domainName",
"[",
"subIndex",
"+",
"1",
":",
"]",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"domain",
",",
"nil",
"\n",
"}"
] | // GetDomainByName gets Domain object by its name. If `domainName` level > 2 and there is
// no such domain on the account - it'll recursively search for the first
// which is exists in Vscale Domains API. | [
"GetDomainByName",
"gets",
"Domain",
"object",
"by",
"its",
"name",
".",
"If",
"domainName",
"level",
">",
"2",
"and",
"there",
"is",
"no",
"such",
"domain",
"on",
"the",
"account",
"-",
"it",
"ll",
"recursively",
"search",
"for",
"the",
"first",
"which",
"is",
"exists",
"in",
"Vscale",
"Domains",
"API",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vscale/internal/client.go#L72-L93 | train |
go-acme/lego | providers/dns/vscale/internal/client.go | AddRecord | func (c *Client) AddRecord(domainID int, body Record) (*Record, error) {
uri := fmt.Sprintf("/%d/records/", domainID)
req, err := c.newRequest(http.MethodPost, uri, body)
if err != nil {
return nil, err
}
record := &Record{}
_, err = c.do(req, record)
if err != nil {
return nil, err
}
return record, nil
} | go | func (c *Client) AddRecord(domainID int, body Record) (*Record, error) {
uri := fmt.Sprintf("/%d/records/", domainID)
req, err := c.newRequest(http.MethodPost, uri, body)
if err != nil {
return nil, err
}
record := &Record{}
_, err = c.do(req, record)
if err != nil {
return nil, err
}
return record, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"AddRecord",
"(",
"domainID",
"int",
",",
"body",
"Record",
")",
"(",
"*",
"Record",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
")",
"\n",
"req",
",",
"err",
":=",
"c",
".",
"newRequest",
"(",
"http",
".",
"MethodPost",
",",
"uri",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"record",
":=",
"&",
"Record",
"{",
"}",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"do",
"(",
"req",
",",
"record",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"record",
",",
"nil",
"\n",
"}"
] | // AddRecord adds Record for given domain. | [
"AddRecord",
"adds",
"Record",
"for",
"given",
"domain",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vscale/internal/client.go#L96-L110 | train |
go-acme/lego | providers/dns/vscale/internal/client.go | ListRecords | func (c *Client) ListRecords(domainID int) ([]*Record, error) {
uri := fmt.Sprintf("/%d/records/", domainID)
req, err := c.newRequest(http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
var records []*Record
_, err = c.do(req, &records)
if err != nil {
return nil, err
}
return records, nil
} | go | func (c *Client) ListRecords(domainID int) ([]*Record, error) {
uri := fmt.Sprintf("/%d/records/", domainID)
req, err := c.newRequest(http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
var records []*Record
_, err = c.do(req, &records)
if err != nil {
return nil, err
}
return records, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListRecords",
"(",
"domainID",
"int",
")",
"(",
"[",
"]",
"*",
"Record",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
")",
"\n",
"req",
",",
"err",
":=",
"c",
".",
"newRequest",
"(",
"http",
".",
"MethodGet",
",",
"uri",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"records",
"[",
"]",
"*",
"Record",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"do",
"(",
"req",
",",
"&",
"records",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"records",
",",
"nil",
"\n",
"}"
] | // ListRecords returns list records for specific domain. | [
"ListRecords",
"returns",
"list",
"records",
"for",
"specific",
"domain",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vscale/internal/client.go#L113-L126 | train |
go-acme/lego | providers/dns/vscale/internal/client.go | DeleteRecord | func (c *Client) DeleteRecord(domainID, recordID int) error {
uri := fmt.Sprintf("/%d/records/%d", domainID, recordID)
req, err := c.newRequest(http.MethodDelete, uri, nil)
if err != nil {
return err
}
_, err = c.do(req, nil)
return err
} | go | func (c *Client) DeleteRecord(domainID, recordID int) error {
uri := fmt.Sprintf("/%d/records/%d", domainID, recordID)
req, err := c.newRequest(http.MethodDelete, uri, nil)
if err != nil {
return err
}
_, err = c.do(req, nil)
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteRecord",
"(",
"domainID",
",",
"recordID",
"int",
")",
"error",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
",",
"recordID",
")",
"\n",
"req",
",",
"err",
":=",
"c",
".",
"newRequest",
"(",
"http",
".",
"MethodDelete",
",",
"uri",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"c",
".",
"do",
"(",
"req",
",",
"nil",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteRecord deletes specific record. | [
"DeleteRecord",
"deletes",
"specific",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vscale/internal/client.go#L129-L138 | train |
go-acme/lego | providers/dns/gandi/client.go | rpcCall | func (d *DNSProvider) rpcCall(call *methodCall, resp response) error {
// marshal
b, err := xml.MarshalIndent(call, "", " ")
if err != nil {
return fmt.Errorf("marshal error: %v", err)
}
// post
b = append([]byte(`<?xml version="1.0"?>`+"\n"), b...)
respBody, err := d.httpPost(d.config.BaseURL, "text/xml", bytes.NewReader(b))
if err != nil {
return err
}
// unmarshal
err = xml.Unmarshal(respBody, resp)
if err != nil {
return fmt.Errorf("unmarshal error: %v", err)
}
if resp.faultCode() != 0 {
return rpcError{
faultCode: resp.faultCode(), faultString: resp.faultString()}
}
return nil
} | go | func (d *DNSProvider) rpcCall(call *methodCall, resp response) error {
// marshal
b, err := xml.MarshalIndent(call, "", " ")
if err != nil {
return fmt.Errorf("marshal error: %v", err)
}
// post
b = append([]byte(`<?xml version="1.0"?>`+"\n"), b...)
respBody, err := d.httpPost(d.config.BaseURL, "text/xml", bytes.NewReader(b))
if err != nil {
return err
}
// unmarshal
err = xml.Unmarshal(respBody, resp)
if err != nil {
return fmt.Errorf("unmarshal error: %v", err)
}
if resp.faultCode() != 0 {
return rpcError{
faultCode: resp.faultCode(), faultString: resp.faultString()}
}
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"rpcCall",
"(",
"call",
"*",
"methodCall",
",",
"resp",
"response",
")",
"error",
"{",
"// marshal",
"b",
",",
"err",
":=",
"xml",
".",
"MarshalIndent",
"(",
"call",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// post",
"b",
"=",
"append",
"(",
"[",
"]",
"byte",
"(",
"`<?xml version=\"1.0\"?>`",
"+",
"\"",
"\\n",
"\"",
")",
",",
"b",
"...",
")",
"\n",
"respBody",
",",
"err",
":=",
"d",
".",
"httpPost",
"(",
"d",
".",
"config",
".",
"BaseURL",
",",
"\"",
"\"",
",",
"bytes",
".",
"NewReader",
"(",
"b",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// unmarshal",
"err",
"=",
"xml",
".",
"Unmarshal",
"(",
"respBody",
",",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"faultCode",
"(",
")",
"!=",
"0",
"{",
"return",
"rpcError",
"{",
"faultCode",
":",
"resp",
".",
"faultCode",
"(",
")",
",",
"faultString",
":",
"resp",
".",
"faultString",
"(",
")",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // rpcCall makes an XML-RPC call to Gandi's RPC endpoint by
// marshaling the data given in the call argument to XML and sending
// that via HTTP Post to Gandi.
// The response is then unmarshalled into the resp argument. | [
"rpcCall",
"makes",
"an",
"XML",
"-",
"RPC",
"call",
"to",
"Gandi",
"s",
"RPC",
"endpoint",
"by",
"marshaling",
"the",
"data",
"given",
"in",
"the",
"call",
"argument",
"to",
"XML",
"and",
"sending",
"that",
"via",
"HTTP",
"Post",
"to",
"Gandi",
".",
"The",
"response",
"is",
"then",
"unmarshalled",
"into",
"the",
"resp",
"argument",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/gandi/client.go#L101-L125 | train |
go-acme/lego | providers/dns/rfc2136/rfc2136.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("rfc2136: the configuration of the DNS provider is nil")
}
if config.Nameserver == "" {
return nil, fmt.Errorf("rfc2136: nameserver missing")
}
if config.TSIGAlgorithm == "" {
config.TSIGAlgorithm = dns.HmacMD5
}
// Append the default DNS port if none is specified.
if _, _, err := net.SplitHostPort(config.Nameserver); err != nil {
if strings.Contains(err.Error(), "missing port") {
config.Nameserver = net.JoinHostPort(config.Nameserver, "53")
} else {
return nil, fmt.Errorf("rfc2136: %v", err)
}
}
if len(config.TSIGKey) == 0 && len(config.TSIGSecret) > 0 ||
len(config.TSIGKey) > 0 && len(config.TSIGSecret) == 0 {
config.TSIGKey = ""
config.TSIGSecret = ""
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("rfc2136: the configuration of the DNS provider is nil")
}
if config.Nameserver == "" {
return nil, fmt.Errorf("rfc2136: nameserver missing")
}
if config.TSIGAlgorithm == "" {
config.TSIGAlgorithm = dns.HmacMD5
}
// Append the default DNS port if none is specified.
if _, _, err := net.SplitHostPort(config.Nameserver); err != nil {
if strings.Contains(err.Error(), "missing port") {
config.Nameserver = net.JoinHostPort(config.Nameserver, "53")
} else {
return nil, fmt.Errorf("rfc2136: %v", err)
}
}
if len(config.TSIGKey) == 0 && len(config.TSIGSecret) > 0 ||
len(config.TSIGKey) > 0 && len(config.TSIGSecret) == 0 {
config.TSIGKey = ""
config.TSIGSecret = ""
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"Nameserver",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"TSIGAlgorithm",
"==",
"\"",
"\"",
"{",
"config",
".",
"TSIGAlgorithm",
"=",
"dns",
".",
"HmacMD5",
"\n",
"}",
"\n\n",
"// Append the default DNS port if none is specified.",
"if",
"_",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"config",
".",
"Nameserver",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"config",
".",
"Nameserver",
"=",
"net",
".",
"JoinHostPort",
"(",
"config",
".",
"Nameserver",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"config",
".",
"TSIGKey",
")",
"==",
"0",
"&&",
"len",
"(",
"config",
".",
"TSIGSecret",
")",
">",
"0",
"||",
"len",
"(",
"config",
".",
"TSIGKey",
")",
">",
"0",
"&&",
"len",
"(",
"config",
".",
"TSIGSecret",
")",
"==",
"0",
"{",
"config",
".",
"TSIGKey",
"=",
"\"",
"\"",
"\n",
"config",
".",
"TSIGSecret",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for rfc2136. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"rfc2136",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/rfc2136/rfc2136.go#L71-L100 | train |
go-acme/lego | providers/dns/joker/joker.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("joker: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("joker: credentials missing")
}
if !strings.HasSuffix(config.BaseURL, "/") {
config.BaseURL += "/"
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("joker: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, fmt.Errorf("joker: credentials missing")
}
if !strings.HasSuffix(config.BaseURL, "/") {
config.BaseURL += "/"
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"config",
".",
"BaseURL",
",",
"\"",
"\"",
")",
"{",
"config",
".",
"BaseURL",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Joker DMAPI. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Joker",
"DMAPI",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/joker.go#L63-L77 | train |
go-acme/lego | providers/dns/joker/joker.go | formatResponseError | func formatResponseError(response *response, err error) error {
if response != nil {
return fmt.Errorf("joker: DMAPI error: %v Response: %v", err, response.Headers)
}
return fmt.Errorf("joker: DMAPI error: %v", err)
} | go | func formatResponseError(response *response, err error) error {
if response != nil {
return fmt.Errorf("joker: DMAPI error: %v Response: %v", err, response.Headers)
}
return fmt.Errorf("joker: DMAPI error: %v", err)
} | [
"func",
"formatResponseError",
"(",
"response",
"*",
"response",
",",
"err",
"error",
")",
"error",
"{",
"if",
"response",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"response",
".",
"Headers",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}"
] | // formatResponseError formats error with optional details from DMAPI response | [
"formatResponseError",
"formats",
"error",
"with",
"optional",
"details",
"from",
"DMAPI",
"response"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/joker/joker.go#L169-L174 | train |
go-acme/lego | providers/dns/transip/transip.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("transip: the configuration of the DNS provider is nil")
}
client, err := gotransip.NewSOAPClient(gotransip.ClientConfig{
AccountName: config.AccountName,
PrivateKeyPath: config.PrivateKeyPath,
})
if err != nil {
return nil, fmt.Errorf("transip: %v", err)
}
return &DNSProvider{client: client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("transip: the configuration of the DNS provider is nil")
}
client, err := gotransip.NewSOAPClient(gotransip.ClientConfig{
AccountName: config.AccountName,
PrivateKeyPath: config.PrivateKeyPath,
})
if err != nil {
return nil, fmt.Errorf("transip: %v", err)
}
return &DNSProvider{client: client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"gotransip",
".",
"NewSOAPClient",
"(",
"gotransip",
".",
"ClientConfig",
"{",
"AccountName",
":",
"config",
".",
"AccountName",
",",
"PrivateKeyPath",
":",
"config",
".",
"PrivateKeyPath",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for TransIP. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"TransIP",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/transip/transip.go#L59-L73 | train |
go-acme/lego | providers/dns/cloudns/internal/client.go | NewClient | func NewClient(authID string, authPassword string) (*Client, error) {
if authID == "" {
return nil, fmt.Errorf("credentials missing: authID")
}
if authPassword == "" {
return nil, fmt.Errorf("credentials missing: authPassword")
}
baseURL, err := url.Parse(defaultBaseURL)
if err != nil {
return nil, err
}
return &Client{
authID: authID,
authPassword: authPassword,
HTTPClient: &http.Client{},
BaseURL: baseURL,
}, nil
} | go | func NewClient(authID string, authPassword string) (*Client, error) {
if authID == "" {
return nil, fmt.Errorf("credentials missing: authID")
}
if authPassword == "" {
return nil, fmt.Errorf("credentials missing: authPassword")
}
baseURL, err := url.Parse(defaultBaseURL)
if err != nil {
return nil, err
}
return &Client{
authID: authID,
authPassword: authPassword,
HTTPClient: &http.Client{},
BaseURL: baseURL,
}, nil
} | [
"func",
"NewClient",
"(",
"authID",
"string",
",",
"authPassword",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"authID",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"authPassword",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"baseURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"defaultBaseURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"authID",
":",
"authID",
",",
"authPassword",
":",
"authPassword",
",",
"HTTPClient",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"BaseURL",
":",
"baseURL",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewClient creates a ClouDNS client | [
"NewClient",
"creates",
"a",
"ClouDNS",
"client"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/cloudns/internal/client.go#L44-L64 | train |
go-acme/lego | providers/dns/cloudns/internal/client.go | GetZone | func (c *Client) GetZone(authFQDN string) (*Zone, error) {
authZone, err := dns01.FindZoneByFqdn(authFQDN)
if err != nil {
return nil, err
}
authZoneName := dns01.UnFqdn(authZone)
reqURL := *c.BaseURL
reqURL.Path += "get-zone-info.json"
q := reqURL.Query()
q.Add("domain-name", authZoneName)
reqURL.RawQuery = q.Encode()
result, err := c.doRequest(http.MethodGet, &reqURL)
if err != nil {
return nil, err
}
var zone Zone
if len(result) > 0 {
if err = json.Unmarshal(result, &zone); err != nil {
return nil, fmt.Errorf("zone unmarshaling error: %v", err)
}
}
if zone.Name == authZoneName {
return &zone, nil
}
return nil, fmt.Errorf("zone %s not found for authFQDN %s", authZoneName, authFQDN)
} | go | func (c *Client) GetZone(authFQDN string) (*Zone, error) {
authZone, err := dns01.FindZoneByFqdn(authFQDN)
if err != nil {
return nil, err
}
authZoneName := dns01.UnFqdn(authZone)
reqURL := *c.BaseURL
reqURL.Path += "get-zone-info.json"
q := reqURL.Query()
q.Add("domain-name", authZoneName)
reqURL.RawQuery = q.Encode()
result, err := c.doRequest(http.MethodGet, &reqURL)
if err != nil {
return nil, err
}
var zone Zone
if len(result) > 0 {
if err = json.Unmarshal(result, &zone); err != nil {
return nil, fmt.Errorf("zone unmarshaling error: %v", err)
}
}
if zone.Name == authZoneName {
return &zone, nil
}
return nil, fmt.Errorf("zone %s not found for authFQDN %s", authZoneName, authFQDN)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetZone",
"(",
"authFQDN",
"string",
")",
"(",
"*",
"Zone",
",",
"error",
")",
"{",
"authZone",
",",
"err",
":=",
"dns01",
".",
"FindZoneByFqdn",
"(",
"authFQDN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"authZoneName",
":=",
"dns01",
".",
"UnFqdn",
"(",
"authZone",
")",
"\n\n",
"reqURL",
":=",
"*",
"c",
".",
"BaseURL",
"\n",
"reqURL",
".",
"Path",
"+=",
"\"",
"\"",
"\n\n",
"q",
":=",
"reqURL",
".",
"Query",
"(",
")",
"\n",
"q",
".",
"Add",
"(",
"\"",
"\"",
",",
"authZoneName",
")",
"\n",
"reqURL",
".",
"RawQuery",
"=",
"q",
".",
"Encode",
"(",
")",
"\n\n",
"result",
",",
"err",
":=",
"c",
".",
"doRequest",
"(",
"http",
".",
"MethodGet",
",",
"&",
"reqURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"zone",
"Zone",
"\n\n",
"if",
"len",
"(",
"result",
")",
">",
"0",
"{",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"result",
",",
"&",
"zone",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"zone",
".",
"Name",
"==",
"authZoneName",
"{",
"return",
"&",
"zone",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"authZoneName",
",",
"authFQDN",
")",
"\n",
"}"
] | // GetZone Get domain name information for a FQDN | [
"GetZone",
"Get",
"domain",
"name",
"information",
"for",
"a",
"FQDN"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/cloudns/internal/client.go#L75-L108 | train |
go-acme/lego | acme/api/order.go | New | func (o *OrderService) New(domains []string) (acme.ExtendedOrder, error) {
var identifiers []acme.Identifier
for _, domain := range domains {
identifiers = append(identifiers, acme.Identifier{Type: "dns", Value: domain})
}
orderReq := acme.Order{Identifiers: identifiers}
var order acme.Order
resp, err := o.core.post(o.core.GetDirectory().NewOrderURL, orderReq, &order)
if err != nil {
return acme.ExtendedOrder{}, err
}
return acme.ExtendedOrder{
Location: resp.Header.Get("Location"),
Order: order,
}, nil
} | go | func (o *OrderService) New(domains []string) (acme.ExtendedOrder, error) {
var identifiers []acme.Identifier
for _, domain := range domains {
identifiers = append(identifiers, acme.Identifier{Type: "dns", Value: domain})
}
orderReq := acme.Order{Identifiers: identifiers}
var order acme.Order
resp, err := o.core.post(o.core.GetDirectory().NewOrderURL, orderReq, &order)
if err != nil {
return acme.ExtendedOrder{}, err
}
return acme.ExtendedOrder{
Location: resp.Header.Get("Location"),
Order: order,
}, nil
} | [
"func",
"(",
"o",
"*",
"OrderService",
")",
"New",
"(",
"domains",
"[",
"]",
"string",
")",
"(",
"acme",
".",
"ExtendedOrder",
",",
"error",
")",
"{",
"var",
"identifiers",
"[",
"]",
"acme",
".",
"Identifier",
"\n",
"for",
"_",
",",
"domain",
":=",
"range",
"domains",
"{",
"identifiers",
"=",
"append",
"(",
"identifiers",
",",
"acme",
".",
"Identifier",
"{",
"Type",
":",
"\"",
"\"",
",",
"Value",
":",
"domain",
"}",
")",
"\n",
"}",
"\n\n",
"orderReq",
":=",
"acme",
".",
"Order",
"{",
"Identifiers",
":",
"identifiers",
"}",
"\n\n",
"var",
"order",
"acme",
".",
"Order",
"\n",
"resp",
",",
"err",
":=",
"o",
".",
"core",
".",
"post",
"(",
"o",
".",
"core",
".",
"GetDirectory",
"(",
")",
".",
"NewOrderURL",
",",
"orderReq",
",",
"&",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"acme",
".",
"ExtendedOrder",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"acme",
".",
"ExtendedOrder",
"{",
"Location",
":",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"Order",
":",
"order",
",",
"}",
",",
"nil",
"\n",
"}"
] | // New Creates a new order. | [
"New",
"Creates",
"a",
"new",
"order",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/order.go#L13-L31 | train |
go-acme/lego | acme/api/order.go | Get | func (o *OrderService) Get(orderURL string) (acme.Order, error) {
if len(orderURL) == 0 {
return acme.Order{}, errors.New("order[get]: empty URL")
}
var order acme.Order
_, err := o.core.postAsGet(orderURL, &order)
if err != nil {
return acme.Order{}, err
}
return order, nil
} | go | func (o *OrderService) Get(orderURL string) (acme.Order, error) {
if len(orderURL) == 0 {
return acme.Order{}, errors.New("order[get]: empty URL")
}
var order acme.Order
_, err := o.core.postAsGet(orderURL, &order)
if err != nil {
return acme.Order{}, err
}
return order, nil
} | [
"func",
"(",
"o",
"*",
"OrderService",
")",
"Get",
"(",
"orderURL",
"string",
")",
"(",
"acme",
".",
"Order",
",",
"error",
")",
"{",
"if",
"len",
"(",
"orderURL",
")",
"==",
"0",
"{",
"return",
"acme",
".",
"Order",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"order",
"acme",
".",
"Order",
"\n",
"_",
",",
"err",
":=",
"o",
".",
"core",
".",
"postAsGet",
"(",
"orderURL",
",",
"&",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"acme",
".",
"Order",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"order",
",",
"nil",
"\n",
"}"
] | // Get Gets an order. | [
"Get",
"Gets",
"an",
"order",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/order.go#L34-L46 | train |
go-acme/lego | acme/api/order.go | UpdateForCSR | func (o *OrderService) UpdateForCSR(orderURL string, csr []byte) (acme.Order, error) {
csrMsg := acme.CSRMessage{
Csr: base64.RawURLEncoding.EncodeToString(csr),
}
var order acme.Order
_, err := o.core.post(orderURL, csrMsg, &order)
if err != nil {
return acme.Order{}, err
}
if order.Status == acme.StatusInvalid {
return acme.Order{}, order.Error
}
return order, nil
} | go | func (o *OrderService) UpdateForCSR(orderURL string, csr []byte) (acme.Order, error) {
csrMsg := acme.CSRMessage{
Csr: base64.RawURLEncoding.EncodeToString(csr),
}
var order acme.Order
_, err := o.core.post(orderURL, csrMsg, &order)
if err != nil {
return acme.Order{}, err
}
if order.Status == acme.StatusInvalid {
return acme.Order{}, order.Error
}
return order, nil
} | [
"func",
"(",
"o",
"*",
"OrderService",
")",
"UpdateForCSR",
"(",
"orderURL",
"string",
",",
"csr",
"[",
"]",
"byte",
")",
"(",
"acme",
".",
"Order",
",",
"error",
")",
"{",
"csrMsg",
":=",
"acme",
".",
"CSRMessage",
"{",
"Csr",
":",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"csr",
")",
",",
"}",
"\n\n",
"var",
"order",
"acme",
".",
"Order",
"\n",
"_",
",",
"err",
":=",
"o",
".",
"core",
".",
"post",
"(",
"orderURL",
",",
"csrMsg",
",",
"&",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"acme",
".",
"Order",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"order",
".",
"Status",
"==",
"acme",
".",
"StatusInvalid",
"{",
"return",
"acme",
".",
"Order",
"{",
"}",
",",
"order",
".",
"Error",
"\n",
"}",
"\n\n",
"return",
"order",
",",
"nil",
"\n",
"}"
] | // UpdateForCSR Updates an order for a CSR. | [
"UpdateForCSR",
"Updates",
"an",
"order",
"for",
"a",
"CSR",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/order.go#L49-L65 | train |
go-acme/lego | acme/api/api.go | New | func New(httpClient *http.Client, userAgent string, caDirURL, kid string, privateKey crypto.PrivateKey) (*Core, error) {
doer := sender.NewDoer(httpClient, userAgent)
dir, err := getDirectory(doer, caDirURL)
if err != nil {
return nil, err
}
nonceManager := nonces.NewManager(doer, dir.NewNonceURL)
jws := secure.NewJWS(privateKey, kid, nonceManager)
c := &Core{doer: doer, nonceManager: nonceManager, jws: jws, directory: dir, HTTPClient: httpClient}
c.common.core = c
c.Accounts = (*AccountService)(&c.common)
c.Authorizations = (*AuthorizationService)(&c.common)
c.Certificates = (*CertificateService)(&c.common)
c.Challenges = (*ChallengeService)(&c.common)
c.Orders = (*OrderService)(&c.common)
return c, nil
} | go | func New(httpClient *http.Client, userAgent string, caDirURL, kid string, privateKey crypto.PrivateKey) (*Core, error) {
doer := sender.NewDoer(httpClient, userAgent)
dir, err := getDirectory(doer, caDirURL)
if err != nil {
return nil, err
}
nonceManager := nonces.NewManager(doer, dir.NewNonceURL)
jws := secure.NewJWS(privateKey, kid, nonceManager)
c := &Core{doer: doer, nonceManager: nonceManager, jws: jws, directory: dir, HTTPClient: httpClient}
c.common.core = c
c.Accounts = (*AccountService)(&c.common)
c.Authorizations = (*AuthorizationService)(&c.common)
c.Certificates = (*CertificateService)(&c.common)
c.Challenges = (*ChallengeService)(&c.common)
c.Orders = (*OrderService)(&c.common)
return c, nil
} | [
"func",
"New",
"(",
"httpClient",
"*",
"http",
".",
"Client",
",",
"userAgent",
"string",
",",
"caDirURL",
",",
"kid",
"string",
",",
"privateKey",
"crypto",
".",
"PrivateKey",
")",
"(",
"*",
"Core",
",",
"error",
")",
"{",
"doer",
":=",
"sender",
".",
"NewDoer",
"(",
"httpClient",
",",
"userAgent",
")",
"\n\n",
"dir",
",",
"err",
":=",
"getDirectory",
"(",
"doer",
",",
"caDirURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"nonceManager",
":=",
"nonces",
".",
"NewManager",
"(",
"doer",
",",
"dir",
".",
"NewNonceURL",
")",
"\n\n",
"jws",
":=",
"secure",
".",
"NewJWS",
"(",
"privateKey",
",",
"kid",
",",
"nonceManager",
")",
"\n\n",
"c",
":=",
"&",
"Core",
"{",
"doer",
":",
"doer",
",",
"nonceManager",
":",
"nonceManager",
",",
"jws",
":",
"jws",
",",
"directory",
":",
"dir",
",",
"HTTPClient",
":",
"httpClient",
"}",
"\n\n",
"c",
".",
"common",
".",
"core",
"=",
"c",
"\n",
"c",
".",
"Accounts",
"=",
"(",
"*",
"AccountService",
")",
"(",
"&",
"c",
".",
"common",
")",
"\n",
"c",
".",
"Authorizations",
"=",
"(",
"*",
"AuthorizationService",
")",
"(",
"&",
"c",
".",
"common",
")",
"\n",
"c",
".",
"Certificates",
"=",
"(",
"*",
"CertificateService",
")",
"(",
"&",
"c",
".",
"common",
")",
"\n",
"c",
".",
"Challenges",
"=",
"(",
"*",
"ChallengeService",
")",
"(",
"&",
"c",
".",
"common",
")",
"\n",
"c",
".",
"Orders",
"=",
"(",
"*",
"OrderService",
")",
"(",
"&",
"c",
".",
"common",
")",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // New Creates a new Core. | [
"New",
"Creates",
"a",
"new",
"Core",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/api.go#L38-L60 | train |
go-acme/lego | acme/api/api.go | post | func (a *Core) post(uri string, reqBody, response interface{}) (*http.Response, error) {
content, err := json.Marshal(reqBody)
if err != nil {
return nil, errors.New("failed to marshal message")
}
return a.retrievablePost(uri, content, response)
} | go | func (a *Core) post(uri string, reqBody, response interface{}) (*http.Response, error) {
content, err := json.Marshal(reqBody)
if err != nil {
return nil, errors.New("failed to marshal message")
}
return a.retrievablePost(uri, content, response)
} | [
"func",
"(",
"a",
"*",
"Core",
")",
"post",
"(",
"uri",
"string",
",",
"reqBody",
",",
"response",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"content",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"reqBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"a",
".",
"retrievablePost",
"(",
"uri",
",",
"content",
",",
"response",
")",
"\n",
"}"
] | // post performs an HTTP POST request and parses the response body as JSON,
// into the provided respBody object. | [
"post",
"performs",
"an",
"HTTP",
"POST",
"request",
"and",
"parses",
"the",
"response",
"body",
"as",
"JSON",
"into",
"the",
"provided",
"respBody",
"object",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/api.go#L64-L71 | train |
go-acme/lego | acme/api/api.go | GetKeyAuthorization | func (a *Core) GetKeyAuthorization(token string) (string, error) {
return a.jws.GetKeyAuthorization(token)
} | go | func (a *Core) GetKeyAuthorization(token string) (string, error) {
return a.jws.GetKeyAuthorization(token)
} | [
"func",
"(",
"a",
"*",
"Core",
")",
"GetKeyAuthorization",
"(",
"token",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"a",
".",
"jws",
".",
"GetKeyAuthorization",
"(",
"token",
")",
"\n",
"}"
] | // GetKeyAuthorization Gets the key authorization | [
"GetKeyAuthorization",
"Gets",
"the",
"key",
"authorization"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/api.go#L144-L146 | train |
go-acme/lego | challenge/dns01/precheck.go | WrapPreCheck | func WrapPreCheck(wrap WrapPreCheckFunc) ChallengeOption {
return func(chlg *Challenge) error {
chlg.preCheck.checkFunc = wrap
return nil
}
} | go | func WrapPreCheck(wrap WrapPreCheckFunc) ChallengeOption {
return func(chlg *Challenge) error {
chlg.preCheck.checkFunc = wrap
return nil
}
} | [
"func",
"WrapPreCheck",
"(",
"wrap",
"WrapPreCheckFunc",
")",
"ChallengeOption",
"{",
"return",
"func",
"(",
"chlg",
"*",
"Challenge",
")",
"error",
"{",
"chlg",
".",
"preCheck",
".",
"checkFunc",
"=",
"wrap",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WrapPreCheck Allow to define checks before notifying ACME that the DNS challenge is ready. | [
"WrapPreCheck",
"Allow",
"to",
"define",
"checks",
"before",
"notifying",
"ACME",
"that",
"the",
"DNS",
"challenge",
"is",
"ready",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/precheck.go#L20-L25 | train |
go-acme/lego | challenge/dns01/precheck.go | checkDNSPropagation | func (p preCheck) checkDNSPropagation(fqdn, value string) (bool, error) {
// Initial attempt to resolve at the recursive NS
r, err := dnsQuery(fqdn, dns.TypeTXT, recursiveNameservers, true)
if err != nil {
return false, err
}
if !p.requireCompletePropagation {
return true, nil
}
if r.Rcode == dns.RcodeSuccess {
fqdn = updateDomainWithCName(r, fqdn)
}
authoritativeNss, err := lookupNameservers(fqdn)
if err != nil {
return false, err
}
return checkAuthoritativeNss(fqdn, value, authoritativeNss)
} | go | func (p preCheck) checkDNSPropagation(fqdn, value string) (bool, error) {
// Initial attempt to resolve at the recursive NS
r, err := dnsQuery(fqdn, dns.TypeTXT, recursiveNameservers, true)
if err != nil {
return false, err
}
if !p.requireCompletePropagation {
return true, nil
}
if r.Rcode == dns.RcodeSuccess {
fqdn = updateDomainWithCName(r, fqdn)
}
authoritativeNss, err := lookupNameservers(fqdn)
if err != nil {
return false, err
}
return checkAuthoritativeNss(fqdn, value, authoritativeNss)
} | [
"func",
"(",
"p",
"preCheck",
")",
"checkDNSPropagation",
"(",
"fqdn",
",",
"value",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Initial attempt to resolve at the recursive NS",
"r",
",",
"err",
":=",
"dnsQuery",
"(",
"fqdn",
",",
"dns",
".",
"TypeTXT",
",",
"recursiveNameservers",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"p",
".",
"requireCompletePropagation",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Rcode",
"==",
"dns",
".",
"RcodeSuccess",
"{",
"fqdn",
"=",
"updateDomainWithCName",
"(",
"r",
",",
"fqdn",
")",
"\n",
"}",
"\n\n",
"authoritativeNss",
",",
"err",
":=",
"lookupNameservers",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"checkAuthoritativeNss",
"(",
"fqdn",
",",
"value",
",",
"authoritativeNss",
")",
"\n",
"}"
] | // checkDNSPropagation checks if the expected TXT record has been propagated to all authoritative nameservers. | [
"checkDNSPropagation",
"checks",
"if",
"the",
"expected",
"TXT",
"record",
"has",
"been",
"propagated",
"to",
"all",
"authoritative",
"nameservers",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/precheck.go#L72-L93 | train |
go-acme/lego | challenge/dns01/precheck.go | checkAuthoritativeNss | func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, error) {
for _, ns := range nameservers {
r, err := dnsQuery(fqdn, dns.TypeTXT, []string{net.JoinHostPort(ns, "53")}, false)
if err != nil {
return false, err
}
if r.Rcode != dns.RcodeSuccess {
return false, fmt.Errorf("NS %s returned %s for %s", ns, dns.RcodeToString[r.Rcode], fqdn)
}
var records []string
var found bool
for _, rr := range r.Answer {
if txt, ok := rr.(*dns.TXT); ok {
record := strings.Join(txt.Txt, "")
records = append(records, record)
if record == value {
found = true
break
}
}
}
if !found {
return false, fmt.Errorf("NS %s did not return the expected TXT record [fqdn: %s, value: %s]: %s", ns, fqdn, value, strings.Join(records, " ,"))
}
}
return true, nil
} | go | func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, error) {
for _, ns := range nameservers {
r, err := dnsQuery(fqdn, dns.TypeTXT, []string{net.JoinHostPort(ns, "53")}, false)
if err != nil {
return false, err
}
if r.Rcode != dns.RcodeSuccess {
return false, fmt.Errorf("NS %s returned %s for %s", ns, dns.RcodeToString[r.Rcode], fqdn)
}
var records []string
var found bool
for _, rr := range r.Answer {
if txt, ok := rr.(*dns.TXT); ok {
record := strings.Join(txt.Txt, "")
records = append(records, record)
if record == value {
found = true
break
}
}
}
if !found {
return false, fmt.Errorf("NS %s did not return the expected TXT record [fqdn: %s, value: %s]: %s", ns, fqdn, value, strings.Join(records, " ,"))
}
}
return true, nil
} | [
"func",
"checkAuthoritativeNss",
"(",
"fqdn",
",",
"value",
"string",
",",
"nameservers",
"[",
"]",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"for",
"_",
",",
"ns",
":=",
"range",
"nameservers",
"{",
"r",
",",
"err",
":=",
"dnsQuery",
"(",
"fqdn",
",",
"dns",
".",
"TypeTXT",
",",
"[",
"]",
"string",
"{",
"net",
".",
"JoinHostPort",
"(",
"ns",
",",
"\"",
"\"",
")",
"}",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Rcode",
"!=",
"dns",
".",
"RcodeSuccess",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ns",
",",
"dns",
".",
"RcodeToString",
"[",
"r",
".",
"Rcode",
"]",
",",
"fqdn",
")",
"\n",
"}",
"\n\n",
"var",
"records",
"[",
"]",
"string",
"\n\n",
"var",
"found",
"bool",
"\n",
"for",
"_",
",",
"rr",
":=",
"range",
"r",
".",
"Answer",
"{",
"if",
"txt",
",",
"ok",
":=",
"rr",
".",
"(",
"*",
"dns",
".",
"TXT",
")",
";",
"ok",
"{",
"record",
":=",
"strings",
".",
"Join",
"(",
"txt",
".",
"Txt",
",",
"\"",
"\"",
")",
"\n",
"records",
"=",
"append",
"(",
"records",
",",
"record",
")",
"\n",
"if",
"record",
"==",
"value",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"found",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ns",
",",
"fqdn",
",",
"value",
",",
"strings",
".",
"Join",
"(",
"records",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // checkAuthoritativeNss queries each of the given nameservers for the expected TXT record. | [
"checkAuthoritativeNss",
"queries",
"each",
"of",
"the",
"given",
"nameservers",
"for",
"the",
"expected",
"TXT",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/precheck.go#L96-L127 | train |
go-acme/lego | providers/dns/dode/client.go | updateTxtRecord | func (d *DNSProvider) updateTxtRecord(fqdn, token, txt string, clear bool) error {
u, _ := url.Parse("https://www.do.de/api/letsencrypt")
query := u.Query()
query.Set("token", token)
query.Set("domain", dns01.UnFqdn(fqdn))
// api call differs per set/delete
if clear {
query.Set("action", "delete")
} else {
query.Set("value", txt)
}
u.RawQuery = query.Encode()
response, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
var r apiResponse
err = json.Unmarshal(bodyBytes, &r)
if err != nil {
return fmt.Errorf("request to change TXT record for do.de returned the following invalid json (%s); used url [%s]", string(bodyBytes), u)
}
body := string(bodyBytes)
if !r.Success {
return fmt.Errorf("request to change TXT record for do.de returned the following error result (%s); used url [%s]", body, u)
}
return nil
} | go | func (d *DNSProvider) updateTxtRecord(fqdn, token, txt string, clear bool) error {
u, _ := url.Parse("https://www.do.de/api/letsencrypt")
query := u.Query()
query.Set("token", token)
query.Set("domain", dns01.UnFqdn(fqdn))
// api call differs per set/delete
if clear {
query.Set("action", "delete")
} else {
query.Set("value", txt)
}
u.RawQuery = query.Encode()
response, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
var r apiResponse
err = json.Unmarshal(bodyBytes, &r)
if err != nil {
return fmt.Errorf("request to change TXT record for do.de returned the following invalid json (%s); used url [%s]", string(bodyBytes), u)
}
body := string(bodyBytes)
if !r.Success {
return fmt.Errorf("request to change TXT record for do.de returned the following error result (%s); used url [%s]", body, u)
}
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"updateTxtRecord",
"(",
"fqdn",
",",
"token",
",",
"txt",
"string",
",",
"clear",
"bool",
")",
"error",
"{",
"u",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
")",
"\n\n",
"query",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"token",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"dns01",
".",
"UnFqdn",
"(",
"fqdn",
")",
")",
"\n\n",
"// api call differs per set/delete",
"if",
"clear",
"{",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"txt",
")",
"\n",
"}",
"\n\n",
"u",
".",
"RawQuery",
"=",
"query",
".",
"Encode",
"(",
")",
"\n\n",
"response",
",",
"err",
":=",
"d",
".",
"config",
".",
"HTTPClient",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"bodyBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"r",
"apiResponse",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"bodyBytes",
",",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"bodyBytes",
")",
",",
"u",
")",
"\n",
"}",
"\n\n",
"body",
":=",
"string",
"(",
"bodyBytes",
")",
"\n",
"if",
"!",
"r",
".",
"Success",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"body",
",",
"u",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateTxtRecord Update the domains TXT record
// To update the TXT record we just need to make one simple get request. | [
"updateTxtRecord",
"Update",
"the",
"domains",
"TXT",
"record",
"To",
"update",
"the",
"TXT",
"record",
"we",
"just",
"need",
"to",
"make",
"one",
"simple",
"get",
"request",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dode/client.go#L19-L57 | train |
go-acme/lego | providers/http/memcached/memcached.go | NewMemcachedProvider | func NewMemcachedProvider(hosts []string) (*HTTPProvider, error) {
if len(hosts) == 0 {
return nil, fmt.Errorf("no memcached hosts provided")
}
c := &HTTPProvider{
hosts: hosts,
}
return c, nil
} | go | func NewMemcachedProvider(hosts []string) (*HTTPProvider, error) {
if len(hosts) == 0 {
return nil, fmt.Errorf("no memcached hosts provided")
}
c := &HTTPProvider{
hosts: hosts,
}
return c, nil
} | [
"func",
"NewMemcachedProvider",
"(",
"hosts",
"[",
"]",
"string",
")",
"(",
"*",
"HTTPProvider",
",",
"error",
")",
"{",
"if",
"len",
"(",
"hosts",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"HTTPProvider",
"{",
"hosts",
":",
"hosts",
",",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewMemcachedProvider returns a HTTPProvider instance with a configured webroot path | [
"NewMemcachedProvider",
"returns",
"a",
"HTTPProvider",
"instance",
"with",
"a",
"configured",
"webroot",
"path"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/http/memcached/memcached.go#L19-L29 | train |
go-acme/lego | providers/dns/exec/exec.go | NewDNSProvider | func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("EXEC_PATH")
if err != nil {
return nil, fmt.Errorf("exec: %v", err)
}
config := NewDefaultConfig()
config.Program = values["EXEC_PATH"]
config.Mode = os.Getenv("EXEC_MODE")
return NewDNSProviderConfig(config)
} | go | func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get("EXEC_PATH")
if err != nil {
return nil, fmt.Errorf("exec: %v", err)
}
config := NewDefaultConfig()
config.Program = values["EXEC_PATH"]
config.Mode = os.Getenv("EXEC_MODE")
return NewDNSProviderConfig(config)
} | [
"func",
"NewDNSProvider",
"(",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"values",
",",
"err",
":=",
"env",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"config",
":=",
"NewDefaultConfig",
"(",
")",
"\n",
"config",
".",
"Program",
"=",
"values",
"[",
"\"",
"\"",
"]",
"\n",
"config",
".",
"Mode",
"=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"NewDNSProviderConfig",
"(",
"config",
")",
"\n",
"}"
] | // NewDNSProvider returns a new DNS provider which runs the program in the
// environment variable EXEC_PATH for adding and removing the DNS record. | [
"NewDNSProvider",
"returns",
"a",
"new",
"DNS",
"provider",
"which",
"runs",
"the",
"program",
"in",
"the",
"environment",
"variable",
"EXEC_PATH",
"for",
"adding",
"and",
"removing",
"the",
"DNS",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/exec/exec.go#L40-L51 | train |
go-acme/lego | providers/dns/designate/designate.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("designate: the configuration of the DNS provider is nil")
}
provider, err := openstack.AuthenticatedClient(config.opts)
if err != nil {
return nil, fmt.Errorf("designate: failed to authenticate: %v", err)
}
dnsClient, err := openstack.NewDNSV2(provider, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
if err != nil {
return nil, fmt.Errorf("designate: failed to get DNS provider: %v", err)
}
return &DNSProvider{client: dnsClient, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("designate: the configuration of the DNS provider is nil")
}
provider, err := openstack.AuthenticatedClient(config.opts)
if err != nil {
return nil, fmt.Errorf("designate: failed to authenticate: %v", err)
}
dnsClient, err := openstack.NewDNSV2(provider, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
if err != nil {
return nil, fmt.Errorf("designate: failed to get DNS provider: %v", err)
}
return &DNSProvider{client: dnsClient, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"provider",
",",
"err",
":=",
"openstack",
".",
"AuthenticatedClient",
"(",
"config",
".",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"dnsClient",
",",
"err",
":=",
"openstack",
".",
"NewDNSV2",
"(",
"provider",
",",
"gophercloud",
".",
"EndpointOpts",
"{",
"Region",
":",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"dnsClient",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Designate. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Designate",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/designate/designate.go#L65-L83 | train |
go-acme/lego | providers/dns/vegadns/vegadns.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("vegadns: the configuration of the DNS provider is nil")
}
vega := vegaClient.NewVegaDNSClient(config.BaseURL)
vega.APIKey = config.APIKey
vega.APISecret = config.APISecret
return &DNSProvider{client: vega, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("vegadns: the configuration of the DNS provider is nil")
}
vega := vegaClient.NewVegaDNSClient(config.BaseURL)
vega.APIKey = config.APIKey
vega.APISecret = config.APISecret
return &DNSProvider{client: vega, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"vega",
":=",
"vegaClient",
".",
"NewVegaDNSClient",
"(",
"config",
".",
"BaseURL",
")",
"\n",
"vega",
".",
"APIKey",
"=",
"config",
".",
"APIKey",
"\n",
"vega",
".",
"APISecret",
"=",
"config",
".",
"APISecret",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"vega",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for VegaDNS. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"VegaDNS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/vegadns/vegadns.go#L58-L68 | train |
go-acme/lego | acme/api/internal/secure/jws.go | NewJWS | func NewJWS(privateKey crypto.PrivateKey, kid string, nonceManager *nonces.Manager) *JWS {
return &JWS{
privKey: privateKey,
nonces: nonceManager,
kid: kid,
}
} | go | func NewJWS(privateKey crypto.PrivateKey, kid string, nonceManager *nonces.Manager) *JWS {
return &JWS{
privKey: privateKey,
nonces: nonceManager,
kid: kid,
}
} | [
"func",
"NewJWS",
"(",
"privateKey",
"crypto",
".",
"PrivateKey",
",",
"kid",
"string",
",",
"nonceManager",
"*",
"nonces",
".",
"Manager",
")",
"*",
"JWS",
"{",
"return",
"&",
"JWS",
"{",
"privKey",
":",
"privateKey",
",",
"nonces",
":",
"nonceManager",
",",
"kid",
":",
"kid",
",",
"}",
"\n",
"}"
] | // NewJWS Create a new JWS. | [
"NewJWS",
"Create",
"a",
"new",
"JWS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/internal/secure/jws.go#L23-L29 | train |
go-acme/lego | acme/api/internal/secure/jws.go | SignContent | func (j *JWS) SignContent(url string, content []byte) (*jose.JSONWebSignature, error) {
var alg jose.SignatureAlgorithm
switch k := j.privKey.(type) {
case *rsa.PrivateKey:
alg = jose.RS256
case *ecdsa.PrivateKey:
if k.Curve == elliptic.P256() {
alg = jose.ES256
} else if k.Curve == elliptic.P384() {
alg = jose.ES384
}
}
signKey := jose.SigningKey{
Algorithm: alg,
Key: jose.JSONWebKey{Key: j.privKey, KeyID: j.kid},
}
options := jose.SignerOptions{
NonceSource: j.nonces,
ExtraHeaders: map[jose.HeaderKey]interface{}{
"url": url,
},
}
if j.kid == "" {
options.EmbedJWK = true
}
signer, err := jose.NewSigner(signKey, &options)
if err != nil {
return nil, fmt.Errorf("failed to create jose signer -> %v", err)
}
signed, err := signer.Sign(content)
if err != nil {
return nil, fmt.Errorf("failed to sign content -> %v", err)
}
return signed, nil
} | go | func (j *JWS) SignContent(url string, content []byte) (*jose.JSONWebSignature, error) {
var alg jose.SignatureAlgorithm
switch k := j.privKey.(type) {
case *rsa.PrivateKey:
alg = jose.RS256
case *ecdsa.PrivateKey:
if k.Curve == elliptic.P256() {
alg = jose.ES256
} else if k.Curve == elliptic.P384() {
alg = jose.ES384
}
}
signKey := jose.SigningKey{
Algorithm: alg,
Key: jose.JSONWebKey{Key: j.privKey, KeyID: j.kid},
}
options := jose.SignerOptions{
NonceSource: j.nonces,
ExtraHeaders: map[jose.HeaderKey]interface{}{
"url": url,
},
}
if j.kid == "" {
options.EmbedJWK = true
}
signer, err := jose.NewSigner(signKey, &options)
if err != nil {
return nil, fmt.Errorf("failed to create jose signer -> %v", err)
}
signed, err := signer.Sign(content)
if err != nil {
return nil, fmt.Errorf("failed to sign content -> %v", err)
}
return signed, nil
} | [
"func",
"(",
"j",
"*",
"JWS",
")",
"SignContent",
"(",
"url",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"(",
"*",
"jose",
".",
"JSONWebSignature",
",",
"error",
")",
"{",
"var",
"alg",
"jose",
".",
"SignatureAlgorithm",
"\n",
"switch",
"k",
":=",
"j",
".",
"privKey",
".",
"(",
"type",
")",
"{",
"case",
"*",
"rsa",
".",
"PrivateKey",
":",
"alg",
"=",
"jose",
".",
"RS256",
"\n",
"case",
"*",
"ecdsa",
".",
"PrivateKey",
":",
"if",
"k",
".",
"Curve",
"==",
"elliptic",
".",
"P256",
"(",
")",
"{",
"alg",
"=",
"jose",
".",
"ES256",
"\n",
"}",
"else",
"if",
"k",
".",
"Curve",
"==",
"elliptic",
".",
"P384",
"(",
")",
"{",
"alg",
"=",
"jose",
".",
"ES384",
"\n",
"}",
"\n",
"}",
"\n\n",
"signKey",
":=",
"jose",
".",
"SigningKey",
"{",
"Algorithm",
":",
"alg",
",",
"Key",
":",
"jose",
".",
"JSONWebKey",
"{",
"Key",
":",
"j",
".",
"privKey",
",",
"KeyID",
":",
"j",
".",
"kid",
"}",
",",
"}",
"\n\n",
"options",
":=",
"jose",
".",
"SignerOptions",
"{",
"NonceSource",
":",
"j",
".",
"nonces",
",",
"ExtraHeaders",
":",
"map",
"[",
"jose",
".",
"HeaderKey",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"url",
",",
"}",
",",
"}",
"\n\n",
"if",
"j",
".",
"kid",
"==",
"\"",
"\"",
"{",
"options",
".",
"EmbedJWK",
"=",
"true",
"\n",
"}",
"\n\n",
"signer",
",",
"err",
":=",
"jose",
".",
"NewSigner",
"(",
"signKey",
",",
"&",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"signed",
",",
"err",
":=",
"signer",
".",
"Sign",
"(",
"content",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"signed",
",",
"nil",
"\n",
"}"
] | // SignContent Signs a content with the JWS. | [
"SignContent",
"Signs",
"a",
"content",
"with",
"the",
"JWS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/internal/secure/jws.go#L37-L76 | train |
go-acme/lego | acme/api/internal/secure/jws.go | SignEABContent | func (j *JWS) SignEABContent(url, kid string, hmac []byte) (*jose.JSONWebSignature, error) {
jwk := jose.JSONWebKey{Key: j.privKey}
jwkJSON, err := jwk.Public().MarshalJSON()
if err != nil {
return nil, fmt.Errorf("acme: error encoding eab jwk key: %v", err)
}
signer, err := jose.NewSigner(
jose.SigningKey{Algorithm: jose.HS256, Key: hmac},
&jose.SignerOptions{
EmbedJWK: false,
ExtraHeaders: map[jose.HeaderKey]interface{}{
"kid": kid,
"url": url,
},
},
)
if err != nil {
return nil, fmt.Errorf("failed to create External Account Binding jose signer -> %v", err)
}
signed, err := signer.Sign(jwkJSON)
if err != nil {
return nil, fmt.Errorf("failed to External Account Binding sign content -> %v", err)
}
return signed, nil
} | go | func (j *JWS) SignEABContent(url, kid string, hmac []byte) (*jose.JSONWebSignature, error) {
jwk := jose.JSONWebKey{Key: j.privKey}
jwkJSON, err := jwk.Public().MarshalJSON()
if err != nil {
return nil, fmt.Errorf("acme: error encoding eab jwk key: %v", err)
}
signer, err := jose.NewSigner(
jose.SigningKey{Algorithm: jose.HS256, Key: hmac},
&jose.SignerOptions{
EmbedJWK: false,
ExtraHeaders: map[jose.HeaderKey]interface{}{
"kid": kid,
"url": url,
},
},
)
if err != nil {
return nil, fmt.Errorf("failed to create External Account Binding jose signer -> %v", err)
}
signed, err := signer.Sign(jwkJSON)
if err != nil {
return nil, fmt.Errorf("failed to External Account Binding sign content -> %v", err)
}
return signed, nil
} | [
"func",
"(",
"j",
"*",
"JWS",
")",
"SignEABContent",
"(",
"url",
",",
"kid",
"string",
",",
"hmac",
"[",
"]",
"byte",
")",
"(",
"*",
"jose",
".",
"JSONWebSignature",
",",
"error",
")",
"{",
"jwk",
":=",
"jose",
".",
"JSONWebKey",
"{",
"Key",
":",
"j",
".",
"privKey",
"}",
"\n",
"jwkJSON",
",",
"err",
":=",
"jwk",
".",
"Public",
"(",
")",
".",
"MarshalJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"signer",
",",
"err",
":=",
"jose",
".",
"NewSigner",
"(",
"jose",
".",
"SigningKey",
"{",
"Algorithm",
":",
"jose",
".",
"HS256",
",",
"Key",
":",
"hmac",
"}",
",",
"&",
"jose",
".",
"SignerOptions",
"{",
"EmbedJWK",
":",
"false",
",",
"ExtraHeaders",
":",
"map",
"[",
"jose",
".",
"HeaderKey",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"kid",
",",
"\"",
"\"",
":",
"url",
",",
"}",
",",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"signed",
",",
"err",
":=",
"signer",
".",
"Sign",
"(",
"jwkJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"signed",
",",
"nil",
"\n",
"}"
] | // SignEABContent Signs an external account binding content with the JWS. | [
"SignEABContent",
"Signs",
"an",
"external",
"account",
"binding",
"content",
"with",
"the",
"JWS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/internal/secure/jws.go#L79-L106 | train |
go-acme/lego | acme/api/internal/secure/jws.go | GetKeyAuthorization | func (j *JWS) GetKeyAuthorization(token string) (string, error) {
var publicKey crypto.PublicKey
switch k := j.privKey.(type) {
case *ecdsa.PrivateKey:
publicKey = k.Public()
case *rsa.PrivateKey:
publicKey = k.Public()
}
// Generate the Key Authorization for the challenge
jwk := &jose.JSONWebKey{Key: publicKey}
thumbBytes, err := jwk.Thumbprint(crypto.SHA256)
if err != nil {
return "", err
}
// unpad the base64URL
keyThumb := base64.RawURLEncoding.EncodeToString(thumbBytes)
return token + "." + keyThumb, nil
} | go | func (j *JWS) GetKeyAuthorization(token string) (string, error) {
var publicKey crypto.PublicKey
switch k := j.privKey.(type) {
case *ecdsa.PrivateKey:
publicKey = k.Public()
case *rsa.PrivateKey:
publicKey = k.Public()
}
// Generate the Key Authorization for the challenge
jwk := &jose.JSONWebKey{Key: publicKey}
thumbBytes, err := jwk.Thumbprint(crypto.SHA256)
if err != nil {
return "", err
}
// unpad the base64URL
keyThumb := base64.RawURLEncoding.EncodeToString(thumbBytes)
return token + "." + keyThumb, nil
} | [
"func",
"(",
"j",
"*",
"JWS",
")",
"GetKeyAuthorization",
"(",
"token",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"publicKey",
"crypto",
".",
"PublicKey",
"\n",
"switch",
"k",
":=",
"j",
".",
"privKey",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ecdsa",
".",
"PrivateKey",
":",
"publicKey",
"=",
"k",
".",
"Public",
"(",
")",
"\n",
"case",
"*",
"rsa",
".",
"PrivateKey",
":",
"publicKey",
"=",
"k",
".",
"Public",
"(",
")",
"\n",
"}",
"\n\n",
"// Generate the Key Authorization for the challenge",
"jwk",
":=",
"&",
"jose",
".",
"JSONWebKey",
"{",
"Key",
":",
"publicKey",
"}",
"\n\n",
"thumbBytes",
",",
"err",
":=",
"jwk",
".",
"Thumbprint",
"(",
"crypto",
".",
"SHA256",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// unpad the base64URL",
"keyThumb",
":=",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"thumbBytes",
")",
"\n\n",
"return",
"token",
"+",
"\"",
"\"",
"+",
"keyThumb",
",",
"nil",
"\n",
"}"
] | // GetKeyAuthorization Gets the key authorization for a token. | [
"GetKeyAuthorization",
"Gets",
"the",
"key",
"authorization",
"for",
"a",
"token",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/acme/api/internal/secure/jws.go#L109-L130 | train |
go-acme/lego | challenge/tlsalpn01/tls_alpn_challenge.go | Solve | func (c *Challenge) Solve(authz acme.Authorization) error {
domain := authz.Identifier.Value
log.Infof("[%s] acme: Trying to solve TLS-ALPN-01", challenge.GetTargetedDomain(authz))
chlng, err := challenge.FindChallenge(challenge.TLSALPN01, authz)
if err != nil {
return err
}
// Generate the Key Authorization for the challenge
keyAuth, err := c.core.GetKeyAuthorization(chlng.Token)
if err != nil {
return err
}
err = c.provider.Present(domain, chlng.Token, keyAuth)
if err != nil {
return fmt.Errorf("[%s] acme: error presenting token: %v", challenge.GetTargetedDomain(authz), err)
}
defer func() {
err := c.provider.CleanUp(domain, chlng.Token, keyAuth)
if err != nil {
log.Warnf("[%s] acme: error cleaning up: %v", challenge.GetTargetedDomain(authz), err)
}
}()
chlng.KeyAuthorization = keyAuth
return c.validate(c.core, domain, chlng)
} | go | func (c *Challenge) Solve(authz acme.Authorization) error {
domain := authz.Identifier.Value
log.Infof("[%s] acme: Trying to solve TLS-ALPN-01", challenge.GetTargetedDomain(authz))
chlng, err := challenge.FindChallenge(challenge.TLSALPN01, authz)
if err != nil {
return err
}
// Generate the Key Authorization for the challenge
keyAuth, err := c.core.GetKeyAuthorization(chlng.Token)
if err != nil {
return err
}
err = c.provider.Present(domain, chlng.Token, keyAuth)
if err != nil {
return fmt.Errorf("[%s] acme: error presenting token: %v", challenge.GetTargetedDomain(authz), err)
}
defer func() {
err := c.provider.CleanUp(domain, chlng.Token, keyAuth)
if err != nil {
log.Warnf("[%s] acme: error cleaning up: %v", challenge.GetTargetedDomain(authz), err)
}
}()
chlng.KeyAuthorization = keyAuth
return c.validate(c.core, domain, chlng)
} | [
"func",
"(",
"c",
"*",
"Challenge",
")",
"Solve",
"(",
"authz",
"acme",
".",
"Authorization",
")",
"error",
"{",
"domain",
":=",
"authz",
".",
"Identifier",
".",
"Value",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"challenge",
".",
"GetTargetedDomain",
"(",
"authz",
")",
")",
"\n\n",
"chlng",
",",
"err",
":=",
"challenge",
".",
"FindChallenge",
"(",
"challenge",
".",
"TLSALPN01",
",",
"authz",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Generate the Key Authorization for the challenge",
"keyAuth",
",",
"err",
":=",
"c",
".",
"core",
".",
"GetKeyAuthorization",
"(",
"chlng",
".",
"Token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"provider",
".",
"Present",
"(",
"domain",
",",
"chlng",
".",
"Token",
",",
"keyAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"challenge",
".",
"GetTargetedDomain",
"(",
"authz",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
":=",
"c",
".",
"provider",
".",
"CleanUp",
"(",
"domain",
",",
"chlng",
".",
"Token",
",",
"keyAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"challenge",
".",
"GetTargetedDomain",
"(",
"authz",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"chlng",
".",
"KeyAuthorization",
"=",
"keyAuth",
"\n",
"return",
"c",
".",
"validate",
"(",
"c",
".",
"core",
",",
"domain",
",",
"chlng",
")",
"\n",
"}"
] | // Solve manages the provider to validate and solve the challenge. | [
"Solve",
"manages",
"the",
"provider",
"to",
"validate",
"and",
"solve",
"the",
"challenge",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/tlsalpn01/tls_alpn_challenge.go#L43-L71 | train |
go-acme/lego | challenge/tlsalpn01/tls_alpn_challenge.go | ChallengeCert | func ChallengeCert(domain, keyAuth string) (*tls.Certificate, error) {
tempCertPEM, rsaPrivatePEM, err := ChallengeBlocks(domain, keyAuth)
if err != nil {
return nil, err
}
cert, err := tls.X509KeyPair(tempCertPEM, rsaPrivatePEM)
if err != nil {
return nil, err
}
return &cert, nil
} | go | func ChallengeCert(domain, keyAuth string) (*tls.Certificate, error) {
tempCertPEM, rsaPrivatePEM, err := ChallengeBlocks(domain, keyAuth)
if err != nil {
return nil, err
}
cert, err := tls.X509KeyPair(tempCertPEM, rsaPrivatePEM)
if err != nil {
return nil, err
}
return &cert, nil
} | [
"func",
"ChallengeCert",
"(",
"domain",
",",
"keyAuth",
"string",
")",
"(",
"*",
"tls",
".",
"Certificate",
",",
"error",
")",
"{",
"tempCertPEM",
",",
"rsaPrivatePEM",
",",
"err",
":=",
"ChallengeBlocks",
"(",
"domain",
",",
"keyAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cert",
",",
"err",
":=",
"tls",
".",
"X509KeyPair",
"(",
"tempCertPEM",
",",
"rsaPrivatePEM",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"cert",
",",
"nil",
"\n",
"}"
] | // ChallengeCert returns a certificate with the acmeValidation-v1 extension
// and domain name for the `tls-alpn-01` challenge. | [
"ChallengeCert",
"returns",
"a",
"certificate",
"with",
"the",
"acmeValidation",
"-",
"v1",
"extension",
"and",
"domain",
"name",
"for",
"the",
"tls",
"-",
"alpn",
"-",
"01",
"challenge",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/tlsalpn01/tls_alpn_challenge.go#L117-L129 | train |
go-acme/lego | providers/dns/dreamhost/dreamhost.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dreamhost: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, errors.New("dreamhost: credentials missing")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("dreamhost: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, errors.New("dreamhost: credentials missing")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"config",
".",
"BaseURL",
"=",
"defaultBaseURL",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for DreamHost. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"DreamHost",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dreamhost/dreamhost.go#L57-L71 | train |
go-acme/lego | providers/dns/bindman/bindman.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("bindman: the configuration of the DNS provider is nil")
}
if config.BaseURL == "" {
return nil, fmt.Errorf("bindman: bindman manager address missing")
}
bClient, err := client.New(config.BaseURL, config.HTTPClient)
if err != nil {
return nil, fmt.Errorf("bindman: %v", err)
}
return &DNSProvider{config: config, client: bClient}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("bindman: the configuration of the DNS provider is nil")
}
if config.BaseURL == "" {
return nil, fmt.Errorf("bindman: bindman manager address missing")
}
bClient, err := client.New(config.BaseURL, config.HTTPClient)
if err != nil {
return nil, fmt.Errorf("bindman: %v", err)
}
return &DNSProvider{config: config, client: bClient}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"bClient",
",",
"err",
":=",
"client",
".",
"New",
"(",
"config",
".",
"BaseURL",
",",
"config",
".",
"HTTPClient",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
",",
"client",
":",
"bClient",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Bindman. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Bindman",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/bindman/bindman.go#L56-L71 | train |
go-acme/lego | platform/wait/wait.go | For | func For(msg string, timeout, interval time.Duration, f func() (bool, error)) error {
log.Infof("Wait for %s [timeout: %s, interval: %s]", msg, timeout, interval)
var lastErr string
timeUp := time.After(timeout)
for {
select {
case <-timeUp:
return fmt.Errorf("time limit exceeded: last error: %s", lastErr)
default:
}
stop, err := f()
if stop {
return nil
}
if err != nil {
lastErr = err.Error()
}
time.Sleep(interval)
}
} | go | func For(msg string, timeout, interval time.Duration, f func() (bool, error)) error {
log.Infof("Wait for %s [timeout: %s, interval: %s]", msg, timeout, interval)
var lastErr string
timeUp := time.After(timeout)
for {
select {
case <-timeUp:
return fmt.Errorf("time limit exceeded: last error: %s", lastErr)
default:
}
stop, err := f()
if stop {
return nil
}
if err != nil {
lastErr = err.Error()
}
time.Sleep(interval)
}
} | [
"func",
"For",
"(",
"msg",
"string",
",",
"timeout",
",",
"interval",
"time",
".",
"Duration",
",",
"f",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"msg",
",",
"timeout",
",",
"interval",
")",
"\n\n",
"var",
"lastErr",
"string",
"\n",
"timeUp",
":=",
"time",
".",
"After",
"(",
"timeout",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"timeUp",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"lastErr",
")",
"\n",
"default",
":",
"}",
"\n\n",
"stop",
",",
"err",
":=",
"f",
"(",
")",
"\n",
"if",
"stop",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"lastErr",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"interval",
")",
"\n",
"}",
"\n",
"}"
] | // For polls the given function 'f', once every 'interval', up to 'timeout'. | [
"For",
"polls",
"the",
"given",
"function",
"f",
"once",
"every",
"interval",
"up",
"to",
"timeout",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/platform/wait/wait.go#L11-L33 | train |
go-acme/lego | cmd/cmd.go | CreateCommands | func CreateCommands() []cli.Command {
return []cli.Command{
createRun(),
createRevoke(),
createRenew(),
createDNSHelp(),
createList(),
}
} | go | func CreateCommands() []cli.Command {
return []cli.Command{
createRun(),
createRevoke(),
createRenew(),
createDNSHelp(),
createList(),
}
} | [
"func",
"CreateCommands",
"(",
")",
"[",
"]",
"cli",
".",
"Command",
"{",
"return",
"[",
"]",
"cli",
".",
"Command",
"{",
"createRun",
"(",
")",
",",
"createRevoke",
"(",
")",
",",
"createRenew",
"(",
")",
",",
"createDNSHelp",
"(",
")",
",",
"createList",
"(",
")",
",",
"}",
"\n",
"}"
] | // CreateCommands Creates all CLI commands | [
"CreateCommands",
"Creates",
"all",
"CLI",
"commands"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/cmd/cmd.go#L6-L14 | train |
go-acme/lego | providers/dns/dyn/client.go | login | func (d *DNSProvider) login() error {
payload := &credentials{Customer: d.config.CustomerName, User: d.config.UserName, Pass: d.config.Password}
dynRes, err := d.sendRequest(http.MethodPost, "Session", payload)
if err != nil {
return err
}
var s session
err = json.Unmarshal(dynRes.Data, &s)
if err != nil {
return err
}
d.token = s.Token
return nil
} | go | func (d *DNSProvider) login() error {
payload := &credentials{Customer: d.config.CustomerName, User: d.config.UserName, Pass: d.config.Password}
dynRes, err := d.sendRequest(http.MethodPost, "Session", payload)
if err != nil {
return err
}
var s session
err = json.Unmarshal(dynRes.Data, &s)
if err != nil {
return err
}
d.token = s.Token
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"login",
"(",
")",
"error",
"{",
"payload",
":=",
"&",
"credentials",
"{",
"Customer",
":",
"d",
".",
"config",
".",
"CustomerName",
",",
"User",
":",
"d",
".",
"config",
".",
"UserName",
",",
"Pass",
":",
"d",
".",
"config",
".",
"Password",
"}",
"\n",
"dynRes",
",",
"err",
":=",
"d",
".",
"sendRequest",
"(",
"http",
".",
"MethodPost",
",",
"\"",
"\"",
",",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"s",
"session",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"dynRes",
".",
"Data",
",",
"&",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"d",
".",
"token",
"=",
"s",
".",
"Token",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Starts a new Dyn API Session. Authenticates using customerName, userName,
// password and receives a token to be used in for subsequent requests. | [
"Starts",
"a",
"new",
"Dyn",
"API",
"Session",
".",
"Authenticates",
"using",
"customerName",
"userName",
"password",
"and",
"receives",
"a",
"token",
"to",
"be",
"used",
"in",
"for",
"subsequent",
"requests",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dyn/client.go#L44-L60 | train |
go-acme/lego | providers/dns/dyn/client.go | logout | func (d *DNSProvider) logout() error {
if len(d.token) == 0 {
// nothing to do
return nil
}
url := fmt.Sprintf("%s/Session", defaultBaseURL)
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Auth-Token", d.token)
resp, err := d.config.HTTPClient.Do(req)
if err != nil {
return err
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("API request failed to delete session with HTTP status code %d", resp.StatusCode)
}
d.token = ""
return nil
} | go | func (d *DNSProvider) logout() error {
if len(d.token) == 0 {
// nothing to do
return nil
}
url := fmt.Sprintf("%s/Session", defaultBaseURL)
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Auth-Token", d.token)
resp, err := d.config.HTTPClient.Do(req)
if err != nil {
return err
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("API request failed to delete session with HTTP status code %d", resp.StatusCode)
}
d.token = ""
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"logout",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"d",
".",
"token",
")",
"==",
"0",
"{",
"// nothing to do",
"return",
"nil",
"\n",
"}",
"\n\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"defaultBaseURL",
")",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodDelete",
",",
"url",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"d",
".",
"token",
")",
"\n\n",
"resp",
",",
"err",
":=",
"d",
".",
"config",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"d",
".",
"token",
"=",
"\"",
"\"",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Destroys Dyn Session | [
"Destroys",
"Dyn",
"Session"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/dyn/client.go#L63-L90 | train |
go-acme/lego | providers/dns/conoha/internal/client.go | NewClient | func NewClient(region string, auth Auth, httpClient *http.Client) (*Client, error) {
if httpClient == nil {
httpClient = &http.Client{}
}
c := &Client{httpClient: httpClient}
c.endpoint = fmt.Sprintf(identityBaseURL, region)
identity, err := c.getIdentity(auth)
if err != nil {
return nil, fmt.Errorf("failed to login: %v", err)
}
c.token = identity.Access.Token.ID
c.endpoint = fmt.Sprintf(dnsServiceBaseURL, region)
return c, nil
} | go | func NewClient(region string, auth Auth, httpClient *http.Client) (*Client, error) {
if httpClient == nil {
httpClient = &http.Client{}
}
c := &Client{httpClient: httpClient}
c.endpoint = fmt.Sprintf(identityBaseURL, region)
identity, err := c.getIdentity(auth)
if err != nil {
return nil, fmt.Errorf("failed to login: %v", err)
}
c.token = identity.Access.Token.ID
c.endpoint = fmt.Sprintf(dnsServiceBaseURL, region)
return c, nil
} | [
"func",
"NewClient",
"(",
"region",
"string",
",",
"auth",
"Auth",
",",
"httpClient",
"*",
"http",
".",
"Client",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"httpClient",
"==",
"nil",
"{",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"Client",
"{",
"httpClient",
":",
"httpClient",
"}",
"\n\n",
"c",
".",
"endpoint",
"=",
"fmt",
".",
"Sprintf",
"(",
"identityBaseURL",
",",
"region",
")",
"\n\n",
"identity",
",",
"err",
":=",
"c",
".",
"getIdentity",
"(",
"auth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"c",
".",
"token",
"=",
"identity",
".",
"Access",
".",
"Token",
".",
"ID",
"\n",
"c",
".",
"endpoint",
"=",
"fmt",
".",
"Sprintf",
"(",
"dnsServiceBaseURL",
",",
"region",
")",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewClient returns a client instance logged into the ConoHa service. | [
"NewClient",
"returns",
"a",
"client",
"instance",
"logged",
"into",
"the",
"ConoHa",
"service",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/conoha/internal/client.go#L82-L100 | train |
go-acme/lego | providers/dns/conoha/internal/client.go | GetDomainID | func (c *Client) GetDomainID(domainName string) (string, error) {
domainList := &DomainListResponse{}
err := c.do(http.MethodGet, "/v1/domains", nil, domainList)
if err != nil {
return "", err
}
for _, domain := range domainList.Domains {
if domain.Name == domainName {
return domain.ID, nil
}
}
return "", fmt.Errorf("no such domain: %s", domainName)
} | go | func (c *Client) GetDomainID(domainName string) (string, error) {
domainList := &DomainListResponse{}
err := c.do(http.MethodGet, "/v1/domains", nil, domainList)
if err != nil {
return "", err
}
for _, domain := range domainList.Domains {
if domain.Name == domainName {
return domain.ID, nil
}
}
return "", fmt.Errorf("no such domain: %s", domainName)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetDomainID",
"(",
"domainName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"domainList",
":=",
"&",
"DomainListResponse",
"{",
"}",
"\n\n",
"err",
":=",
"c",
".",
"do",
"(",
"http",
".",
"MethodGet",
",",
"\"",
"\"",
",",
"nil",
",",
"domainList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"domain",
":=",
"range",
"domainList",
".",
"Domains",
"{",
"if",
"domain",
".",
"Name",
"==",
"domainName",
"{",
"return",
"domain",
".",
"ID",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"domainName",
")",
"\n",
"}"
] | // GetDomainID returns an ID of specified domain. | [
"GetDomainID",
"returns",
"an",
"ID",
"of",
"specified",
"domain",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/conoha/internal/client.go#L116-L130 | train |
go-acme/lego | providers/dns/conoha/internal/client.go | GetRecordID | func (c *Client) GetRecordID(domainID, recordName, recordType, data string) (string, error) {
recordList := &RecordListResponse{}
err := c.do(http.MethodGet, fmt.Sprintf("/v1/domains/%s/records", domainID), nil, recordList)
if err != nil {
return "", err
}
for _, record := range recordList.Records {
if record.Name == recordName && record.Type == recordType && record.Data == data {
return record.ID, nil
}
}
return "", errors.New("no such record")
} | go | func (c *Client) GetRecordID(domainID, recordName, recordType, data string) (string, error) {
recordList := &RecordListResponse{}
err := c.do(http.MethodGet, fmt.Sprintf("/v1/domains/%s/records", domainID), nil, recordList)
if err != nil {
return "", err
}
for _, record := range recordList.Records {
if record.Name == recordName && record.Type == recordType && record.Data == data {
return record.ID, nil
}
}
return "", errors.New("no such record")
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetRecordID",
"(",
"domainID",
",",
"recordName",
",",
"recordType",
",",
"data",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"recordList",
":=",
"&",
"RecordListResponse",
"{",
"}",
"\n\n",
"err",
":=",
"c",
".",
"do",
"(",
"http",
".",
"MethodGet",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
")",
",",
"nil",
",",
"recordList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"record",
":=",
"range",
"recordList",
".",
"Records",
"{",
"if",
"record",
".",
"Name",
"==",
"recordName",
"&&",
"record",
".",
"Type",
"==",
"recordType",
"&&",
"record",
".",
"Data",
"==",
"data",
"{",
"return",
"record",
".",
"ID",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // GetRecordID returns an ID of specified record. | [
"GetRecordID",
"returns",
"an",
"ID",
"of",
"specified",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/conoha/internal/client.go#L133-L147 | train |
go-acme/lego | providers/dns/conoha/internal/client.go | CreateRecord | func (c *Client) CreateRecord(domainID string, record Record) error {
return c.do(http.MethodPost, fmt.Sprintf("/v1/domains/%s/records", domainID), record, nil)
} | go | func (c *Client) CreateRecord(domainID string, record Record) error {
return c.do(http.MethodPost, fmt.Sprintf("/v1/domains/%s/records", domainID), record, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CreateRecord",
"(",
"domainID",
"string",
",",
"record",
"Record",
")",
"error",
"{",
"return",
"c",
".",
"do",
"(",
"http",
".",
"MethodPost",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
")",
",",
"record",
",",
"nil",
")",
"\n",
"}"
] | // CreateRecord adds new record. | [
"CreateRecord",
"adds",
"new",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/conoha/internal/client.go#L150-L152 | train |
go-acme/lego | providers/dns/conoha/internal/client.go | DeleteRecord | func (c *Client) DeleteRecord(domainID, recordID string) error {
return c.do(http.MethodDelete, fmt.Sprintf("/v1/domains/%s/records/%s", domainID, recordID), nil, nil)
} | go | func (c *Client) DeleteRecord(domainID, recordID string) error {
return c.do(http.MethodDelete, fmt.Sprintf("/v1/domains/%s/records/%s", domainID, recordID), nil, nil)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteRecord",
"(",
"domainID",
",",
"recordID",
"string",
")",
"error",
"{",
"return",
"c",
".",
"do",
"(",
"http",
".",
"MethodDelete",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"domainID",
",",
"recordID",
")",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // DeleteRecord removes specified record. | [
"DeleteRecord",
"removes",
"specified",
"record",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/conoha/internal/client.go#L155-L157 | train |
go-acme/lego | providers/dns/cloudflare/cloudflare.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("cloudflare: the configuration of the DNS provider is nil")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("cloudflare: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
client, err := cloudflare.New(config.AuthKey, config.AuthEmail, cloudflare.HTTPClient(config.HTTPClient))
if err != nil {
return nil, err
}
return &DNSProvider{client: client, config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("cloudflare: the configuration of the DNS provider is nil")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("cloudflare: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
client, err := cloudflare.New(config.AuthKey, config.AuthEmail, cloudflare.HTTPClient(config.HTTPClient))
if err != nil {
return nil, err
}
return &DNSProvider{client: client, config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"TTL",
"<",
"minTTL",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"TTL",
",",
"minTTL",
")",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"cloudflare",
".",
"New",
"(",
"config",
".",
"AuthKey",
",",
"config",
".",
"AuthEmail",
",",
"cloudflare",
".",
"HTTPClient",
"(",
"config",
".",
"HTTPClient",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"client",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Cloudflare. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Cloudflare",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/cloudflare/cloudflare.go#L67-L82 | train |
go-acme/lego | providers/dns/digitalocean/digitalocean.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("digitalocean: the configuration of the DNS provider is nil")
}
if config.AuthToken == "" {
return nil, fmt.Errorf("digitalocean: credentials missing")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{
config: config,
recordIDs: make(map[string]int),
}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("digitalocean: the configuration of the DNS provider is nil")
}
if config.AuthToken == "" {
return nil, fmt.Errorf("digitalocean: credentials missing")
}
if config.BaseURL == "" {
config.BaseURL = defaultBaseURL
}
return &DNSProvider{
config: config,
recordIDs: make(map[string]int),
}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"AuthToken",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"config",
".",
"BaseURL",
"=",
"defaultBaseURL",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
",",
"recordIDs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Digital Ocean. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Digital",
"Ocean",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/digitalocean/digitalocean.go#L62-L79 | train |
go-acme/lego | challenge/dns01/fqdn.go | ToFqdn | func ToFqdn(name string) string {
n := len(name)
if n == 0 || name[n-1] == '.' {
return name
}
return name + "."
} | go | func ToFqdn(name string) string {
n := len(name)
if n == 0 || name[n-1] == '.' {
return name
}
return name + "."
} | [
"func",
"ToFqdn",
"(",
"name",
"string",
")",
"string",
"{",
"n",
":=",
"len",
"(",
"name",
")",
"\n",
"if",
"n",
"==",
"0",
"||",
"name",
"[",
"n",
"-",
"1",
"]",
"==",
"'.'",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"name",
"+",
"\"",
"\"",
"\n",
"}"
] | // ToFqdn converts the name into a fqdn appending a trailing dot. | [
"ToFqdn",
"converts",
"the",
"name",
"into",
"a",
"fqdn",
"appending",
"a",
"trailing",
"dot",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/fqdn.go#L4-L10 | train |
go-acme/lego | challenge/dns01/fqdn.go | UnFqdn | func UnFqdn(name string) string {
n := len(name)
if n != 0 && name[n-1] == '.' {
return name[:n-1]
}
return name
} | go | func UnFqdn(name string) string {
n := len(name)
if n != 0 && name[n-1] == '.' {
return name[:n-1]
}
return name
} | [
"func",
"UnFqdn",
"(",
"name",
"string",
")",
"string",
"{",
"n",
":=",
"len",
"(",
"name",
")",
"\n",
"if",
"n",
"!=",
"0",
"&&",
"name",
"[",
"n",
"-",
"1",
"]",
"==",
"'.'",
"{",
"return",
"name",
"[",
":",
"n",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
] | // UnFqdn converts the fqdn into a name removing the trailing dot. | [
"UnFqdn",
"converts",
"the",
"fqdn",
"into",
"a",
"name",
"removing",
"the",
"trailing",
"dot",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/fqdn.go#L13-L19 | train |
go-acme/lego | providers/dns/bluecat/bluecat.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("bluecat: the configuration of the DNS provider is nil")
}
if config.BaseURL == "" || config.UserName == "" || config.Password == "" || config.ConfigName == "" || config.DNSView == "" {
return nil, fmt.Errorf("bluecat: credentials missing")
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("bluecat: the configuration of the DNS provider is nil")
}
if config.BaseURL == "" || config.UserName == "" || config.Password == "" || config.ConfigName == "" || config.DNSView == "" {
return nil, fmt.Errorf("bluecat: credentials missing")
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"BaseURL",
"==",
"\"",
"\"",
"||",
"config",
".",
"UserName",
"==",
"\"",
"\"",
"||",
"config",
".",
"Password",
"==",
"\"",
"\"",
"||",
"config",
".",
"ConfigName",
"==",
"\"",
"\"",
"||",
"config",
".",
"DNSView",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for Bluecat DNS. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"Bluecat",
"DNS",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/bluecat/bluecat.go#L78-L88 | train |
go-acme/lego | providers/dns/sakuracloud/sakuracloud.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("sakuracloud: the configuration of the DNS provider is nil")
}
if config.Token == "" {
return nil, errors.New("sakuracloud: AccessToken is missing")
}
if config.Secret == "" {
return nil, errors.New("sakuracloud: AccessSecret is missing")
}
apiClient := api.NewClient(config.Token, config.Secret, "is1a")
if config.HTTPClient == nil {
apiClient.HTTPClient = http.DefaultClient
} else {
apiClient.HTTPClient = config.HTTPClient
}
return &DNSProvider{
client: apiClient.GetDNSAPI(),
config: config,
}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("sakuracloud: the configuration of the DNS provider is nil")
}
if config.Token == "" {
return nil, errors.New("sakuracloud: AccessToken is missing")
}
if config.Secret == "" {
return nil, errors.New("sakuracloud: AccessSecret is missing")
}
apiClient := api.NewClient(config.Token, config.Secret, "is1a")
if config.HTTPClient == nil {
apiClient.HTTPClient = http.DefaultClient
} else {
apiClient.HTTPClient = config.HTTPClient
}
return &DNSProvider{
client: apiClient.GetDNSAPI(),
config: config,
}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"Token",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"Secret",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"apiClient",
":=",
"api",
".",
"NewClient",
"(",
"config",
".",
"Token",
",",
"config",
".",
"Secret",
",",
"\"",
"\"",
")",
"\n",
"if",
"config",
".",
"HTTPClient",
"==",
"nil",
"{",
"apiClient",
".",
"HTTPClient",
"=",
"http",
".",
"DefaultClient",
"\n",
"}",
"else",
"{",
"apiClient",
".",
"HTTPClient",
"=",
"config",
".",
"HTTPClient",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"client",
":",
"apiClient",
".",
"GetDNSAPI",
"(",
")",
",",
"config",
":",
"config",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for SakuraCloud. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"SakuraCloud",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/sakuracloud/sakuracloud.go#L59-L83 | train |
go-acme/lego | providers/dns/godaddy/godaddy.go | NewDNSProviderConfig | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("godaddy: the configuration of the DNS provider is nil")
}
if config.APIKey == "" || config.APISecret == "" {
return nil, fmt.Errorf("godaddy: credentials missing")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("godaddy: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
return &DNSProvider{config: config}, nil
} | go | func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("godaddy: the configuration of the DNS provider is nil")
}
if config.APIKey == "" || config.APISecret == "" {
return nil, fmt.Errorf("godaddy: credentials missing")
}
if config.TTL < minTTL {
return nil, fmt.Errorf("godaddy: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}
return &DNSProvider{config: config}, nil
} | [
"func",
"NewDNSProviderConfig",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"DNSProvider",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"APIKey",
"==",
"\"",
"\"",
"||",
"config",
".",
"APISecret",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"TTL",
"<",
"minTTL",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"TTL",
",",
"minTTL",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"DNSProvider",
"{",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // NewDNSProviderConfig return a DNSProvider instance configured for godaddy. | [
"NewDNSProviderConfig",
"return",
"a",
"DNSProvider",
"instance",
"configured",
"for",
"godaddy",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/godaddy/godaddy.go#L67-L81 | train |
go-acme/lego | providers/dns/godaddy/godaddy.go | CleanUp | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
domainZone, err := d.getZone(fqdn)
if err != nil {
return err
}
recordName := d.extractRecordName(fqdn, domainZone)
rec := []DNSRecord{
{
Type: "TXT",
Name: recordName,
Data: "null",
},
}
return d.updateRecords(rec, domainZone, recordName)
} | go | func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := dns01.GetRecord(domain, keyAuth)
domainZone, err := d.getZone(fqdn)
if err != nil {
return err
}
recordName := d.extractRecordName(fqdn, domainZone)
rec := []DNSRecord{
{
Type: "TXT",
Name: recordName,
Data: "null",
},
}
return d.updateRecords(rec, domainZone, recordName)
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"CleanUp",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"_",
":=",
"dns01",
".",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n",
"domainZone",
",",
"err",
":=",
"d",
".",
"getZone",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"recordName",
":=",
"d",
".",
"extractRecordName",
"(",
"fqdn",
",",
"domainZone",
")",
"\n",
"rec",
":=",
"[",
"]",
"DNSRecord",
"{",
"{",
"Type",
":",
"\"",
"\"",
",",
"Name",
":",
"recordName",
",",
"Data",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n\n",
"return",
"d",
".",
"updateRecords",
"(",
"rec",
",",
"domainZone",
",",
"recordName",
")",
"\n",
"}"
] | // CleanUp sets null value in the TXT DNS record as GoDaddy has no proper DELETE record method | [
"CleanUp",
"sets",
"null",
"value",
"in",
"the",
"TXT",
"DNS",
"record",
"as",
"GoDaddy",
"has",
"no",
"proper",
"DELETE",
"record",
"method"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/godaddy/godaddy.go#L111-L128 | train |
go-acme/lego | providers/dns/duckdns/client.go | updateTxtRecord | func (d *DNSProvider) updateTxtRecord(domain, token, txt string, clear bool) error {
u, _ := url.Parse("https://www.duckdns.org/update")
mainDomain := getMainDomain(domain)
if len(mainDomain) == 0 {
return fmt.Errorf("unable to find the main domain for: %s", domain)
}
query := u.Query()
query.Set("domains", mainDomain)
query.Set("token", token)
query.Set("clear", strconv.FormatBool(clear))
query.Set("txt", txt)
u.RawQuery = query.Encode()
response, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
body := string(bodyBytes)
if body != "OK" {
return fmt.Errorf("request to change TXT record for DuckDNS returned the following result (%s) this does not match expectation (OK) used url [%s]", body, u)
}
return nil
} | go | func (d *DNSProvider) updateTxtRecord(domain, token, txt string, clear bool) error {
u, _ := url.Parse("https://www.duckdns.org/update")
mainDomain := getMainDomain(domain)
if len(mainDomain) == 0 {
return fmt.Errorf("unable to find the main domain for: %s", domain)
}
query := u.Query()
query.Set("domains", mainDomain)
query.Set("token", token)
query.Set("clear", strconv.FormatBool(clear))
query.Set("txt", txt)
u.RawQuery = query.Encode()
response, err := d.config.HTTPClient.Get(u.String())
if err != nil {
return err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
body := string(bodyBytes)
if body != "OK" {
return fmt.Errorf("request to change TXT record for DuckDNS returned the following result (%s) this does not match expectation (OK) used url [%s]", body, u)
}
return nil
} | [
"func",
"(",
"d",
"*",
"DNSProvider",
")",
"updateTxtRecord",
"(",
"domain",
",",
"token",
",",
"txt",
"string",
",",
"clear",
"bool",
")",
"error",
"{",
"u",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
")",
"\n\n",
"mainDomain",
":=",
"getMainDomain",
"(",
"domain",
")",
"\n",
"if",
"len",
"(",
"mainDomain",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"domain",
")",
"\n",
"}",
"\n\n",
"query",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"mainDomain",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"token",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"FormatBool",
"(",
"clear",
")",
")",
"\n",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"txt",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"query",
".",
"Encode",
"(",
")",
"\n\n",
"response",
",",
"err",
":=",
"d",
".",
"config",
".",
"HTTPClient",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"bodyBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"body",
":=",
"string",
"(",
"bodyBytes",
")",
"\n",
"if",
"body",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"body",
",",
"u",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateTxtRecord Update the domains TXT record
// To update the TXT record we just need to make one simple get request.
// In DuckDNS you only have one TXT record shared with the domain and all sub domains. | [
"updateTxtRecord",
"Update",
"the",
"domains",
"TXT",
"record",
"To",
"update",
"the",
"TXT",
"record",
"we",
"just",
"need",
"to",
"make",
"one",
"simple",
"get",
"request",
".",
"In",
"DuckDNS",
"you",
"only",
"have",
"one",
"TXT",
"record",
"shared",
"with",
"the",
"domain",
"and",
"all",
"sub",
"domains",
"."
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/duckdns/client.go#L17-L48 | train |
go-acme/lego | providers/dns/duckdns/client.go | getMainDomain | func getMainDomain(domain string) string {
domain = dns01.UnFqdn(domain)
split := dns.Split(domain)
if strings.HasSuffix(strings.ToLower(domain), "duckdns.org") {
if len(split) < 3 {
return ""
}
firstSubDomainIndex := split[len(split)-3]
return domain[firstSubDomainIndex:]
}
return domain[split[len(split)-1]:]
} | go | func getMainDomain(domain string) string {
domain = dns01.UnFqdn(domain)
split := dns.Split(domain)
if strings.HasSuffix(strings.ToLower(domain), "duckdns.org") {
if len(split) < 3 {
return ""
}
firstSubDomainIndex := split[len(split)-3]
return domain[firstSubDomainIndex:]
}
return domain[split[len(split)-1]:]
} | [
"func",
"getMainDomain",
"(",
"domain",
"string",
")",
"string",
"{",
"domain",
"=",
"dns01",
".",
"UnFqdn",
"(",
"domain",
")",
"\n\n",
"split",
":=",
"dns",
".",
"Split",
"(",
"domain",
")",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"strings",
".",
"ToLower",
"(",
"domain",
")",
",",
"\"",
"\"",
")",
"{",
"if",
"len",
"(",
"split",
")",
"<",
"3",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"firstSubDomainIndex",
":=",
"split",
"[",
"len",
"(",
"split",
")",
"-",
"3",
"]",
"\n",
"return",
"domain",
"[",
"firstSubDomainIndex",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"domain",
"[",
"split",
"[",
"len",
"(",
"split",
")",
"-",
"1",
"]",
":",
"]",
"\n",
"}"
] | // DuckDNS only lets you write to your subdomain
// so it must be in format subdomain.duckdns.org
// not in format subsubdomain.subdomain.duckdns.org
// so strip off everything that is not top 3 levels | [
"DuckDNS",
"only",
"lets",
"you",
"write",
"to",
"your",
"subdomain",
"so",
"it",
"must",
"be",
"in",
"format",
"subdomain",
".",
"duckdns",
".",
"org",
"not",
"in",
"format",
"subsubdomain",
".",
"subdomain",
".",
"duckdns",
".",
"org",
"so",
"strip",
"off",
"everything",
"that",
"is",
"not",
"top",
"3",
"levels"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/providers/dns/duckdns/client.go#L54-L68 | train |
go-acme/lego | challenge/dns01/dns_challenge_manual.go | Present | func (*DNSProviderManual) Present(domain, token, keyAuth string) error {
fqdn, value := GetRecord(domain, keyAuth)
authZone, err := FindZoneByFqdn(fqdn)
if err != nil {
return err
}
fmt.Printf("lego: Please create the following TXT record in your %s zone:\n", authZone)
fmt.Printf(dnsTemplate+"\n", fqdn, DefaultTTL, value)
fmt.Printf("lego: Press 'Enter' when you are done\n")
_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
return err
} | go | func (*DNSProviderManual) Present(domain, token, keyAuth string) error {
fqdn, value := GetRecord(domain, keyAuth)
authZone, err := FindZoneByFqdn(fqdn)
if err != nil {
return err
}
fmt.Printf("lego: Please create the following TXT record in your %s zone:\n", authZone)
fmt.Printf(dnsTemplate+"\n", fqdn, DefaultTTL, value)
fmt.Printf("lego: Press 'Enter' when you are done\n")
_, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
return err
} | [
"func",
"(",
"*",
"DNSProviderManual",
")",
"Present",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"value",
":=",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n\n",
"authZone",
",",
"err",
":=",
"FindZoneByFqdn",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"authZone",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"dnsTemplate",
"+",
"\"",
"\\n",
"\"",
",",
"fqdn",
",",
"DefaultTTL",
",",
"value",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
")",
"\n\n",
"_",
",",
"err",
"=",
"bufio",
".",
"NewReader",
"(",
"os",
".",
"Stdin",
")",
".",
"ReadBytes",
"(",
"'\\n'",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Present prints instructions for manually creating the TXT record | [
"Present",
"prints",
"instructions",
"for",
"manually",
"creating",
"the",
"TXT",
"record"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/dns_challenge_manual.go#L22-L37 | train |
go-acme/lego | challenge/dns01/dns_challenge_manual.go | CleanUp | func (*DNSProviderManual) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := GetRecord(domain, keyAuth)
authZone, err := FindZoneByFqdn(fqdn)
if err != nil {
return err
}
fmt.Printf("lego: You can now remove this TXT record from your %s zone:\n", authZone)
fmt.Printf(dnsTemplate+"\n", fqdn, DefaultTTL, "...")
return nil
} | go | func (*DNSProviderManual) CleanUp(domain, token, keyAuth string) error {
fqdn, _ := GetRecord(domain, keyAuth)
authZone, err := FindZoneByFqdn(fqdn)
if err != nil {
return err
}
fmt.Printf("lego: You can now remove this TXT record from your %s zone:\n", authZone)
fmt.Printf(dnsTemplate+"\n", fqdn, DefaultTTL, "...")
return nil
} | [
"func",
"(",
"*",
"DNSProviderManual",
")",
"CleanUp",
"(",
"domain",
",",
"token",
",",
"keyAuth",
"string",
")",
"error",
"{",
"fqdn",
",",
"_",
":=",
"GetRecord",
"(",
"domain",
",",
"keyAuth",
")",
"\n\n",
"authZone",
",",
"err",
":=",
"FindZoneByFqdn",
"(",
"fqdn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"authZone",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"dnsTemplate",
"+",
"\"",
"\\n",
"\"",
",",
"fqdn",
",",
"DefaultTTL",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CleanUp prints instructions for manually removing the TXT record | [
"CleanUp",
"prints",
"instructions",
"for",
"manually",
"removing",
"the",
"TXT",
"record"
] | 29c63545ce6fffd8289c55c39d81c4fde993533d | https://github.com/go-acme/lego/blob/29c63545ce6fffd8289c55c39d81c4fde993533d/challenge/dns01/dns_challenge_manual.go#L40-L52 | train |
goadesign/goa | uuid/uuid.go | FromString | func FromString(input string) (UUID, error) {
u, err := uuid.FromString(input)
return UUID(u), err
} | go | func FromString(input string) (UUID, error) {
u, err := uuid.FromString(input)
return UUID(u), err
} | [
"func",
"FromString",
"(",
"input",
"string",
")",
"(",
"UUID",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"input",
")",
"\n",
"return",
"UUID",
"(",
"u",
")",
",",
"err",
"\n",
"}"
] | // FromString Wrapper around the real FromString | [
"FromString",
"Wrapper",
"around",
"the",
"real",
"FromString"
] | 90bd33edff1a4f17fab06d1f9e14e659075d1328 | https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/uuid/uuid.go#L16-L19 | train |
goadesign/goa | uuid/uuid.go | MarshalText | func (u UUID) MarshalText() (text []byte, err error) {
return uuid.UUID(u).MarshalText()
} | go | func (u UUID) MarshalText() (text []byte, err error) {
return uuid.UUID(u).MarshalText()
} | [
"func",
"(",
"u",
"UUID",
")",
"MarshalText",
"(",
")",
"(",
"text",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"uuid",
".",
"UUID",
"(",
"u",
")",
".",
"MarshalText",
"(",
")",
"\n",
"}"
] | // MarshalText Wrapper over the real MarshalText method | [
"MarshalText",
"Wrapper",
"over",
"the",
"real",
"MarshalText",
"method"
] | 90bd33edff1a4f17fab06d1f9e14e659075d1328 | https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/uuid/uuid.go#L32-L34 | train |
goadesign/goa | uuid/uuid.go | UnmarshalBinary | func (u *UUID) UnmarshalBinary(data []byte) error {
t := uuid.UUID{}
err := t.UnmarshalBinary(data)
for i, b := range t.Bytes() {
u[i] = b
}
return err
} | go | func (u *UUID) UnmarshalBinary(data []byte) error {
t := uuid.UUID{}
err := t.UnmarshalBinary(data)
for i, b := range t.Bytes() {
u[i] = b
}
return err
} | [
"func",
"(",
"u",
"*",
"UUID",
")",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"t",
":=",
"uuid",
".",
"UUID",
"{",
"}",
"\n",
"err",
":=",
"t",
".",
"UnmarshalBinary",
"(",
"data",
")",
"\n",
"for",
"i",
",",
"b",
":=",
"range",
"t",
".",
"Bytes",
"(",
")",
"{",
"u",
"[",
"i",
"]",
"=",
"b",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // UnmarshalBinary Wrapper over the real UnmarshalBinary method | [
"UnmarshalBinary",
"Wrapper",
"over",
"the",
"real",
"UnmarshalBinary",
"method"
] | 90bd33edff1a4f17fab06d1f9e14e659075d1328 | https://github.com/goadesign/goa/blob/90bd33edff1a4f17fab06d1f9e14e659075d1328/uuid/uuid.go#L42-L49 | train |
Subsets and Splits