New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transifex appears to require credentials for pulling translations #296

Closed
ferventcoder opened this Issue Dec 5, 2018 · 13 comments

Comments

Projects
None yet
3 participants
@ferventcoder

ferventcoder commented Dec 5, 2018

Using ChocolateyGUI without having transifex configured, I didn't always see an error. Then a few months ago I started seeing an error and it appears that maybe the side of transifex that did not require credentials now does. I dug into it at

// Before we do anything with transifex, we must make sure that it have been properly
// Initialized, this is mostly related to running on appveyor or other CI.
// Because we expect the repository to already be configured to use
// transifex, we cannot run tx init, or it would replace the repository configuration file.
BuildParameters.Tasks.TransifexSetupTask = Task("Transifex-Setup")
.WithCriteria(() => BuildParameters.TransifexEnabled)
.WithCriteria(() => !TransifexUserSettingsExists(Context))
.WithCriteria(() => BuildParameters.Transifex.HasCredentials)
.Does(() =>
{
var path = GetTransifexUserSettingsPath();
var encoding = new System.Text.UTF8Encoding(false);
var text = string.Format("[https://www.transifex.com]\r\nhostname = https://www.transifex.com\r\npassword = {0}\r\nusername = api", BuildParameters.Transifex.ApiToken);
System.IO.File.WriteAllText(path, text, encoding);
});
BuildParameters.Tasks.TransifexPushSourceResource = Task("Transifex-Push-SourceFiles")
.WithCriteria(() => BuildParameters.CanPushTranslations)
.IsDependentOn("Transifex-Setup")
.Does(() =>
{
TransifexPush(new TransifexPushSettings {
UploadSourceFiles = true,
Force = string.Equals(BuildParameters.Target, "Transifex-Push-SourceFiles", StringComparison.OrdinalIgnoreCase)
});
});
BuildParameters.Tasks.TransifexPullTranslations = Task("Transifex-Pull-Translations")
.WithCriteria(() => BuildParameters.CanPullTranslations)
.IsDependentOn("Transifex-Push-SourceFiles")
.Does(() =>
{
TransifexPull(new TransifexPullSettings {
All = true,
Mode = BuildParameters.TransifexPullMode,
MinimumPercentage = BuildParameters.TransifexPullPercentage
});
});
. Not having Transifex environment variables set does the following in a diagnostic log:

========================================
Transifex-Setup
========================================
Skipping task: Transifex-Setup

========================================
Transifex-Push-SourceFiles
========================================
Skipping task: Transifex-Push-SourceFiles

========================================
Transifex-Pull-Translations
========================================
Executing task: Transifex-Pull-Translations
Resolving assembly Cake.Transifex.resources, Version=0.7.0.0, Culture=en-US, PublicKeyToken=null
Exception while resolving assembly Cake.Transifex.resources: Could not load file or assembly 'Cake.Transifex.resources' or one of its dependencies. The system cannot find the file specified.
Executing: "C:/ProgramData/Chocolatey/bin/tx.exe" pull --all --minimum-perc=60 --mode=onlytranslated
HttpNotAuthorized: Authorization Required
An error occurred when executing task 'Transifex-Pull-Translations'.
@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Going right to Transifex (the min version 0.12.4):

> & "C:/ProgramData/chocolatey/bin/tx.exe" pull --all --minimum-perc=60 --mode=onlytranslated
HttpNotAuthorized: Authorization Required
@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Upgraded to latest and this is the error I'm seeing now:

 C:\ > & "C:/ProgramData/chocolatey/bin/tx.exe" --version
0.13.2, py 3.6, AMD64
C:\ > & "C:/ProgramData/chocolatey/bin/tx.exe" pull --all --minimum-perc=60 --mode=onlytranslated
tx ERROR: Authorization Required
tx ERROR:
Error: Authentication failed. Please make sure your credentials are valid. You
can update your credentials in the ~/.transifexrc file. For more information,
visit https://docs.transifex.com/client/client-configuration#-transifexrc.
@pascalberger

This comment has been minimized.

Member

pascalberger commented Dec 5, 2018

@AdmiringWorm Do you have an idea what might be the cause of this?

@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

@ferventcoder ferventcoder changed the title from Transifex Appears to require credentials for Pulling Translations now to Transifex appears to require credentials for pulling translations Dec 5, 2018

@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Not sure when it was changed, but the documentation does say to use the client you need to provide authentication.

@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Copying these lines down as criteria for pulling enables the build to work:

.WithCriteria(() => !TransifexUserSettingsExists(Context))
.WithCriteria(() => BuildParameters.Transifex.HasCredentials)

to right after

BuildParameters.Tasks.TransifexPullTranslations = Task("Transifex-Pull-Translations")
.WithCriteria(() => BuildParameters.CanPullTranslations)

@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Also note, at some point I created a ~/.transifexrc file with the following details:

[https://www.transifex.com]
api_hostname = https://api.transifex.com
hostname = https://www.transifex.com
password = no
username = no

(these are the literal values, I did not change them)

@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

If I remove that file, it will ask me to create it again

 & "C:/ProgramData/chocolatey/bin/tx.exe" pull --all --minimum-perc=60 --mode=onlytranslated
tx INFO: No credentials file was found at C:\Users\rob\.transifexrc.
tx INFO: Created C:\Users\rob\.transifexrc
[?] Enter your api token:
Verifying token...
tx ERROR: Authorization credentials are missing. Make sure that you have run `tx init` to setup your credentials.
tx ERROR: 'Api' object has no attribute 'username'
@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

Once I add a valid token to that, everything works. I didn't attempt to run the build between renaming the file and rerunning tx directly. It could be that the mere existence of the file enables transifex pulling, which caused my issue. It might be better to capture the error and explain user next steps for determining the issue - actionable errors are really important for folks who are not wanting to dig into the depths to work on ancillary things can just move on to the areas we need to be focused in and want to dig in. If that makes sense.

& "C:/ProgramData/chocolatey/bin/tx.exe" pull --all --minimum-perc=60 --mode=onlytranslated
[?] Enter your api token: no
Verifying token...
tx INFO:
Error: Invalid token. You can generate a new token at
https://www.transifex.com/user/settings/api/.

[?] Enter your api token: [REDACTED]
Verifying token...
tx INFO: Updating C:\Users\rob\.transifexrc file...
tx INFO: New translations found for the following languages:en_US, ru, nb, de, fr, pt, es, nl, sv, it, ja
tx INFO: Pulling new translations for resource chocolatey-gui.resourcesresx (source: Source\ChocolateyGui\Properties\Resources.resx)
tx WARNING:  -> en_US: Source\ChocolateyGui\Properties\Resources.en-US.resx
tx WARNING:  -> ru: Source\ChocolateyGui\Properties\Resources.ru.resx
tx WARNING:  -> nb: Source\ChocolateyGui\Properties\Resources.nb.resx
tx WARNING:  -> de: Source\ChocolateyGui\Properties\Resources.de.resx
tx WARNING:  -> fr: Source\ChocolateyGui\Properties\Resources.fr.resx
tx WARNING:  -> pt: Source\ChocolateyGui\Properties\Resources.pt.resx
tx WARNING:  -> es: Source\ChocolateyGui\Properties\Resources.es.resx
tx WARNING:  -> nl: Source\ChocolateyGui\Properties\Resources.nl.resx
tx WARNING:  -> sv: Source\ChocolateyGui\Properties\Resources.sv.resx
tx WARNING:  -> it: Source\ChocolateyGui\Properties\Resources.it.resx
tx WARNING:  -> ja: Source\ChocolateyGui\Properties\Resources.ja.resx
tx INFO: Done.
@ferventcoder

This comment has been minimized.

ferventcoder commented Dec 5, 2018

I might also have the file on the system but NOT want it to automatically opt me into transifex pulls

@gep13

This comment has been minimized.

Contributor

gep13 commented Dec 6, 2018

Okay, all is right with the world again...

I have had a look at this, and I am able to explain what is going on, and why I was struggling to understand what is going on. Let me try to explain...

My first thought was that Cake.Recipe is being used on over 100 repos in the Cake-Contrib Organisation, so why is this not causing a problem on those machines. The answer to that question is here:

https://github.com/cake-contrib/Cake.Recipe/blob/develop/Cake.Recipe/Content/build.cake#L571

The Pull-Transifex-Translations task is only added to the DAG when the TransifexEnabled property is true. And this is only set to true if it is forced (via SetParameters) or based on this:

https://github.com/cake-contrib/Cake.Recipe/blob/develop/Cake.Recipe/Content/transifex.cake#L15

i.e. if a ./.tx/config file exists in the repository. None of the Cake-Contrib proiects have either of those things, so that explains why this isn't a problem there. However, ChocolateyGUI does have that file in the repository, and as a result, it has a problem. So, now onto that...

I have just set up a new VM, that has NOTHING on it, other than Windows Server 2016. On to it I installed:

  • Chocolatey
  • Git
  • dotnet 4.7.2

I then cloned the ChocolateyGUI repository, and ran the build (./build.ps1) and this is what I got:

image

So, @ferventcoder seems to be correct that pulling translations seems to need authentication, which I don't think was required before. I can confirm on my machine I have a .transifexrc file:

image

with the correct API token in it, and that is why the pull of the translations is working on my machine.

But, then the obvious question is how/why is this working on AppVeyor...

I have just setup an RDP connection to the AppVeyor Build Agent, and I can confirm that at the start of the build, there was no .transifexrc file in place, however, as soon as the Transifex tasks started, it was created.

Back on my VM, I ran the build again, which results in the following:

image

Which is what @ferventcoder is reporting.

I then went and deleted the generated .transifexrc file, added the environment variable, and ran the build again, and got the following:

image

Which I actually expected to work. Digging further, after looking at what tasks are executed on AppVeyor, brought be to the following:

https://github.com/cake-contrib/Cake.Recipe/blob/develop/Cake.Recipe/Content/transifex.cake#L18-L32

So, long story short, the AppVeyor build, when Transifex is enabled, and has credentials, writes out the necessary .transifexrc file to make everything work correctly.

As suggested, we need additional checks on the Pull-Translations task to match what is done with the others, i.e. should take a dependency on the setup task, and only run if credentials are present.

At some point, on my machine, I must have run the setup task, and had forgotten about it, or entered the apitoken when it was requested, which created the file with valid information. If you input incorrect information when prompted, when running the build a second time, it produces the unauthorized error.

@gep13

This comment has been minimized.

Contributor

gep13 commented Dec 6, 2018

Well, that was an interesting way to start the morning, lots of head scratching and debugging there.

@gep13 gep13 referenced this issue Dec 6, 2018

Open

References need to be updated #289

3 of 9 tasks complete

@gep13 gep13 added the Bug label Dec 6, 2018

@gep13 gep13 added this to the 0.3.0 milestone Dec 6, 2018

@gep13 gep13 closed this Dec 6, 2018

@gep13

This comment has been minimized.

Contributor

gep13 commented Dec 6, 2018

@ferventcoder I have just tested the change that @AdmiringWorm has suggested in his PR, and happy to say that your problem has now been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment